# OpenAI Agents SDK — Build Multi-Agent Systems in Python > Official OpenAI Python SDK for building multi-agent systems with handoffs, guardrails, and tracing. Agents delegate to specialists, enforce safety rules, and produce observable traces. 8,000+ stars. ## Install Save as a script file and run: ## Quick Use ```bash pip install openai-agents ``` ```python from agents import Agent, Runner agent = Agent( name="assistant", instructions="You are a helpful assistant.", model="gpt-4o", ) result = Runner.run_sync(agent, "What is the capital of France?") print(result.final_output) ``` --- ## Intro OpenAI Agents SDK is the official Python framework for building multi-agent systems with handoffs, guardrails, and tracing with 8,000+ GitHub stars. Define agents with instructions and tools, set up handoff rules for delegation between specialists, add guardrails for input/output safety, and get full execution traces for debugging. Unlike generic agent frameworks, this SDK is designed specifically for OpenAI models with first-class support for their function calling and structured output APIs. Best for developers building production agent systems on OpenAI models. Works with: GPT-4o, o3, any OpenAI model. Setup time: under 2 minutes. --- ## Core Concepts ### Agents with Tools ```python from agents import Agent, function_tool @function_tool def get_weather(city: str) -> str: 'Get weather for a city.' return f"Weather in {city}: 22C, sunny" agent = Agent( name="weather-bot", instructions="You help users check the weather.", tools=[get_weather], ) ``` ### Handoffs (Agent Delegation) ```python billing_agent = Agent( name="billing", instructions="Handle billing questions. Access to payment tools.", tools=[get_invoice, process_refund], ) support_agent = Agent( name="support", instructions="Handle general support. Hand off billing questions to billing agent.", handoffs=[billing_agent], ) # When user asks about billing, support_agent hands off to billing_agent ``` ### Guardrails ```python from agents import GuardrailFunctionOutput, input_guardrail @input_guardrail async def block_harmful(ctx, agent, input_text): if "hack" in input_text.lower(): return GuardrailFunctionOutput( output_info={"reason": "Potentially harmful request"}, tripwire_triggered=True, ) agent = Agent( name="safe-agent", input_guardrails=[block_harmful], ) ``` ### Tracing Every agent run produces a detailed trace: ```python result = Runner.run_sync(agent, "Help me with my order") # View trace at: https://platform.openai.com/traces/{trace_id} # Shows: agent decisions, tool calls, handoffs, guardrail checks ``` ### Structured Output ```python from pydantic import BaseModel class OrderSummary(BaseModel): order_id: str status: str total: float agent = Agent( name="order-agent", output_type=OrderSummary, # Enforces structured response ) ``` ### Multi-Agent Architecture ```python researcher = Agent(name="researcher", tools=[search_web]) writer = Agent(name="writer", handoffs=[researcher]) editor = Agent(name="editor", handoffs=[writer]) # editor -> writer -> researcher (chain of delegation) result = Runner.run_sync(editor, "Write an article about AI agents") ``` ### Key Stats - 8,000+ GitHub stars - Official OpenAI product - Handoffs for agent delegation - Input/output guardrails - Built-in tracing and observability ### FAQ **Q: What is OpenAI Agents SDK?** A: The official Python SDK for building multi-agent systems with handoffs between specialists, safety guardrails, and execution tracing. **Q: Is it free?** A: The SDK is open-source under MIT. You need an OpenAI API key. **Q: Does it work with Claude or other models?** A: Designed for OpenAI models. For multi-model support, use LangGraph or CrewAI instead. --- ## Source & Thanks > Created by [OpenAI](https://github.com/openai). Licensed under MIT. > > [openai-agents-python](https://github.com/openai/openai-agents-python) — stars 8,000+ Thanks to OpenAI for standardizing multi-agent patterns. --- ## 快速使用 ```bash pip install openai-agents ``` ```python from agents import Agent, Runner agent = Agent(name="assistant", instructions="你是一个有用的助手。") result = Runner.run_sync(agent, "法国的首都是什么?") ``` --- ## 简介 OpenAI Agents SDK 是 OpenAI 官方 Python 多 Agent 框架,GitHub 8,000+ stars。支持 Agent 间委派(Handoffs)、安全护栏(Guardrails)和执行追踪(Tracing)。适合在 OpenAI 模型上构建生产 Agent 系统。 --- ## 来源与感谢 > Created by [OpenAI](https://github.com/openai). Licensed under MIT. > > [openai-agents-python](https://github.com/openai/openai-agents-python) — stars 8,000+ --- Source: https://tokrepo.com/en/workflows/38035d0b-f942-4bf2-bbad-be9d4f719c00 Author: Agent Toolkit