A comprehensive repository showcasing production-grade orchestration patterns using the OpenAI Agent SDK. This project serves as a technical blueprint for building, scaling, and securing multi-agent systems, tailored for Applied AI Engineers and LLM practitioners.
This repository is structured into specialized modules, each demonstrating a critical facet of modern AI Agent architecture:
- Dynamic Delegation: Implements the
handoffpattern to transfer control between specialized agents (e.g., General Assistant to Math Specialist). - Stateful Transitions: Demonstrates
on_handoffhooks to fetch/validate data from external databases before agent activation. - Handoff Filters: Utilizing
handoff_filtersto prune toolsets during transitions, ensuring agents only have access to contextually relevant tools.
- Input/Output Validation: Implementation of
InputGuardrailTripwireTriggeredandOutputGuardrailTripwireTriggeredto intercept unsafe prompts or hallucinations. - Deterministic Control: Using specialized Guardrail agents to monitor and validate the conversation flow.
- Execution Interception: Deep dive into
Runnerhooks to monitor agent performance, tool calls, and state transitions in real-time. - Tracing: Integrated tracing configurations for debugging complex multi-turn interactions.
- SQLite Integration: Utilizing
SQLiteSessionfor long-term conversation persistence. - Async State Handling: Robust patterns for managing concurrent user sessions and history retrieval.
- Type-Safe Tools: Leveraging
@function_toolwith strict Python type hints for reliable LLM tool-calling. - Functional Composition: Building modular toolsets for arithmetic, API interactions, and data processing.
- Runtime Metadata: Patterns for injecting user-specific metadata (IDs, names, permissions) into the agent's execution context without bloating the prompt.
- Human-in-the-loop: Bridging the SDK with Chainlit to create production-ready chat interfaces with streaming capabilities.
- Framework: OpenAI Agent SDK
- Language: Python 3.13+
- Database: SQLite (Session Persistence)
- UI: Chainlit
- Environment Management:
uv(Recommended) - Configuration:
python-decouple
Ensure you have uv installed for optimal dependency management.
-
Clone the repository:
git clone -b main https://github.com/S-Farhan05/Open_Ai_Agents-Sdk.git cd Open_Ai_Agents-Sdk -
Set up Environment Variables: Create a
.envfile in the root or specific subdirectories:OPENAI_API_KEY=your_api_key_here GEMINI_API_KEY=your_gemini_key_here (if using Google models)
-
Install Dependencies:
uv sync
-
Run an Example:
cd Custom_handoff python main.py
This repo is designed to be studied sequentially:
- Start with
Agents_startfor basic SDK familiarity. - Master Tools in
Tool_behaviorandAgents_asTools. - Understand State through
ContextandSession_management. - Learn Orchestration in
Custom_handoffandRunner_methods. - Secure the System using patterns in
GuardRails. - Observe & Debug using
Agent_hooks.
This repository is designed as an open-source technical resource for the AI Engineering community. Feel free to fork, experiment, and contribute to these implementation patterns. For professional inquiries or collaboration, please reach out via GitHub.
Master the Orchestration. Build the Future.