Esta página se muestra en inglés. Una traducción al español está en curso.
CLI ToolsApr 7, 2026·2 min de lectura

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.

Introducción

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

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)

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

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:

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

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

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.


🙏

Fuente y agradecimientos

Created by OpenAI. Licensed under MIT.

openai-agents-python — stars 8,000+

Thanks to OpenAI for standardizing multi-agent patterns.

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.