OpenAI Agents Examples

June 17, 2025 ยท View on GitHub

This directory contains examples and templates for building AI agents using the OpenAI Agents SDK.

Overview

This folder provides starter code and examples to help you build AI agents with the OpenAI Agents SDK. It includes basic and advanced examples covering various aspects of agent development.

Prerequisites

  • Python 3.8 or higher
  • OpenAI API key (set as an environment variable or in a .env file)

Usage

  1. Install dependencies:
    pip install openai openai-agents
    
  2. Set your OpenAI API key:
    export OPENAI_API_KEY="your_api_key_here"
    
  3. Run the examples:
    python 01_basic/hello_world.py
    

Contents

Examples

Basic

  • 01_basic/: Simple "Hello World" examples showing basic agent setup and interaction
  • 02_models/: Working with external model providers and configurations
  • 03_tools/: Building and integrating different types of tools for agents
  • 04_context/: Managing context and history in agent interactions
  • 05_handoffs/: Demonstrates agent-to-agent task delegation
  • 06_guardrails/: Adding input/output validation and safety guardrails
  • 07_run_stream/: Working with streaming responses from agents
  • 08_lifecycle/: Understanding and managing agent lifecycles and hooks
  • 09_outputs/: Handling different types of agent outputs
  • 10_tracing/: Implementing tracing and logging for agent actions

Advanced