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
- Install dependencies:
pip install openai openai-agents - Set your OpenAI API key:
export OPENAI_API_KEY="your_api_key_here" - Run the examples:
python 01_basic/hello_world.py
Contents
Examples
Basic
01_basic/: Simple "Hello World" examples showing basic agent setup and interaction02_models/: Working with external model providers and configurations03_tools/: Building and integrating different types of tools for agents04_context/: Managing context and history in agent interactions05_handoffs/: Demonstrates agent-to-agent task delegation06_guardrails/: Adding input/output validation and safety guardrails07_run_stream/: Working with streaming responses from agents08_lifecycle/: Understanding and managing agent lifecycles and hooks09_outputs/: Handling different types of agent outputs10_tracing/: Implementing tracing and logging for agent actions
Advanced
11_mcp/: Using the Model Context Protocol12_prompting/: Advanced prompting techniques (e.g. dynamic prompting)13_voice_agents/: Building voice-enabled agents