Exploring My OpenAI Agents Examples Repository
As the creator of the openai-agent-examples repository, I wanted to share some practical implementations for using the OpenAI Agents library. In this post, I'll walk you through what's available in my repository and how you can use it to create your own AI agents. How I Structured the Repository I divided the repository into two distinct sets of code: Introductory Examples (1-5): These are identical to the examples in the official documentation, allowing you to test basic functionalities in a controlled environment. I included these to provide a clear starting point and ensure you can see the foundational concepts working before diving into more complex implementations. Practical Projects (6-8): Three more sophisticated projects that explore additional possibilities in scenarios closer to real-world applications. These build on the basic concepts but demonstrate how to create fully functional systems. What is OpenAI Agents? When I started working with OpenAI Agents, I conceptualized it as a system that operates much like a web framework: Triage: Acts as a router that directs requests Handoffs: Represents the available routes Guardrails: Defines the format and validation of requests Agents: Process specific requests based on their specializations My Repository Structure I've organized the repository into several key sections: openai-agent-examples/ ├── 1-5_introduction_examples/ # Basic examples from documentation ├── 6_simple_chat/ # First practical implementation ├── 7_simple_chat_with_apis/ # Advanced implementation with API integration ├── 8_simple_chat_with_gradio/ # UI-focused implementation ├── .env.example ├── .gitignore └── README.md Introductory Examples (1-5) These examples mirror what you'll find in the official documentation, providing a solid foundation: 1. Simple Agent (simple_agent.py) Creating a basic agent with defined instructions: from agents import Agent agent = Agent( name="Math Tutor", instructions="You provide help with math problems. Explain your reasoning at each step and include examples", ) 2. Handoffs Between Specialized Agents A triage system that routes questions to specialized agents: triage_agent = Agent( name="Triage Agent", instructions="You determine which agent to use based on the user's homework question", handoffs=[history_tutor_agent, math_tutor_agent] ) 3. Input Guardrails Safety checks using Pydantic models: from agents import Agent, InputGuardrail, GuardrailFunctionOutput, Runner from pydantic import BaseModel import asyncio class HomeworkOutput(BaseModel): is_homework: bool reasoning: str 4. Python Functions as Tools Transforming Python functions into tools for agents: @function_tool async def fetch_weather(location: Location) -> str: """Fetch the weather for a given location.""" # In real implementations, this would call a weather API return "sunny" 5. Agents as Tools Using agents as tools for orchestration: orchestrator_agent = Agent( name="orchestrator_agent", instructions=( "You are a translation agent. You use the tools given to you to translate." "If asked for multiple translations, you call the relevant tools." ), tools=[ spanish_agent.as_tool( tool_name="translate_to_spanish", tool_description="Translate the user's message to Spanish", ), french_agent.as_tool( tool_name="translate_to_french", tool_description="Translate the user's message to French", ), ], ) Practical Implementations (6-8) After exploring the basic concepts, I created three more practical implementations that go beyond the documentation examples: 6. Simple Chat My first practical implementation is a basic chat system with conversation history support. This bridges the gap between the introductory examples and more complex systems. 7. Chat with APIs This implementation expands to a complete asynchronous chat solution that incorporates: Chat context management Multiple specialized agents: Bitcoin Agent: Fetches real-time prices using CoinGecko's API Jokes Agent: Returns random or topic-related jokes Weather Agent: Provides weather updates for specified cities Time Agent: Returns the current time News Agent: Simulates news headline searches This example demonstrates how to build a system that can interact with external APIs while maintaining conversation context. 8. Chat with Gradio Interface My most advanced implementation includes a modern web interface using Gradio that adds: Dynamic API tool registration during runtime User-friendly UI for easier interaction Flexible context handling across sessions Integration with custom tools that can be added on-the-fly This example shows how to cr

As the creator of the openai-agent-examples
repository, I wanted to share some practical implementations for using the OpenAI Agents library. In this post, I'll walk you through what's available in my repository and how you can use it to create your own AI agents.
How I Structured the Repository
I divided the repository into two distinct sets of code:
Introductory Examples (1-5): These are identical to the examples in the official documentation, allowing you to test basic functionalities in a controlled environment. I included these to provide a clear starting point and ensure you can see the foundational concepts working before diving into more complex implementations.
Practical Projects (6-8): Three more sophisticated projects that explore additional possibilities in scenarios closer to real-world applications. These build on the basic concepts but demonstrate how to create fully functional systems.
What is OpenAI Agents?
When I started working with OpenAI Agents, I conceptualized it as a system that operates much like a web framework:
- Triage: Acts as a router that directs requests
- Handoffs: Represents the available routes
- Guardrails: Defines the format and validation of requests
- Agents: Process specific requests based on their specializations
My Repository Structure
I've organized the repository into several key sections:
openai-agent-examples/
├── 1-5_introduction_examples/ # Basic examples from documentation
├── 6_simple_chat/ # First practical implementation
├── 7_simple_chat_with_apis/ # Advanced implementation with API integration
├── 8_simple_chat_with_gradio/ # UI-focused implementation
├── .env.example
├── .gitignore
└── README.md
Introductory Examples (1-5)
These examples mirror what you'll find in the official documentation, providing a solid foundation:
1. Simple Agent (simple_agent.py
)
Creating a basic agent with defined instructions:
from agents import Agent
agent = Agent(
name="Math Tutor",
instructions="You provide help with math problems. Explain your reasoning at each step and include examples",
)
2. Handoffs Between Specialized Agents
A triage system that routes questions to specialized agents:
triage_agent = Agent(
name="Triage Agent",
instructions="You determine which agent to use based on the user's homework question",
handoffs=[history_tutor_agent, math_tutor_agent]
)
3. Input Guardrails
Safety checks using Pydantic models:
from agents import Agent, InputGuardrail, GuardrailFunctionOutput, Runner
from pydantic import BaseModel
import asyncio
class HomeworkOutput(BaseModel):
is_homework: bool
reasoning: str
4. Python Functions as Tools
Transforming Python functions into tools for agents:
@function_tool
async def fetch_weather(location: Location) -> str:
"""Fetch the weather for a given location."""
# In real implementations, this would call a weather API
return "sunny"
5. Agents as Tools
Using agents as tools for orchestration:
orchestrator_agent = Agent(
name="orchestrator_agent",
instructions=(
"You are a translation agent. You use the tools given to you to translate."
"If asked for multiple translations, you call the relevant tools."
),
tools=[
spanish_agent.as_tool(
tool_name="translate_to_spanish",
tool_description="Translate the user's message to Spanish",
),
french_agent.as_tool(
tool_name="translate_to_french",
tool_description="Translate the user's message to French",
),
],
)
Practical Implementations (6-8)
After exploring the basic concepts, I created three more practical implementations that go beyond the documentation examples:
6. Simple Chat
My first practical implementation is a basic chat system with conversation history support. This bridges the gap between the introductory examples and more complex systems.
7. Chat with APIs
This implementation expands to a complete asynchronous chat solution that incorporates:
- Chat context management
- Multiple specialized agents:
- Bitcoin Agent: Fetches real-time prices using CoinGecko's API
- Jokes Agent: Returns random or topic-related jokes
- Weather Agent: Provides weather updates for specified cities
- Time Agent: Returns the current time
- News Agent: Simulates news headline searches
This example demonstrates how to build a system that can interact with external APIs while maintaining conversation context.
8. Chat with Gradio Interface
My most advanced implementation includes a modern web interface using Gradio that adds:
- Dynamic API tool registration during runtime
- User-friendly UI for easier interaction
- Flexible context handling across sessions
- Integration with custom tools that can be added on-the-fly
This example shows how to create a deployment-ready system that end users can interact with through a web interface.
Why I Built This Repository
When I started working with OpenAI Agents, I realized there weren't many comprehensive examples showing how to build a complete system. I wanted to create a resource that would:
- Demonstrate the full potential of the library beyond basic usage
- Show how to integrate multiple agents in a cohesive system
- Provide practical examples that address real-world challenges
- Help developers understand how to maintain context in multi-turn conversations
- Showcase different deployment options from command line to web interfaces
The introductory examples help you understand the basics, while the practical implementations show you how to create fully functional systems that could serve as starting points for your own projects.
Looking Forward
I'm continuing to expand this repository with more examples and use cases. If you have suggestions or would like to contribute, please feel free to open an issue or submit a pull request on GitHub.
By sharing these examples, I hope to help other developers explore the potential of the OpenAI Agents library and build their own innovative AI applications.
Happy coding!