Lesson 7 of 20

Agent Frameworks Overview

OpenAI Agents SDK

3 min read

At DevDay 2025, OpenAI introduced the Agents SDK—a lightweight, production-ready framework built around three core primitives: Agents, Handoffs, and Guardrails.

The Three Primitives

1. Agents

The core building block—an LLM with instructions and tools:

from openai import Agent

support_agent = Agent(
    name="Customer Support",
    instructions="""You help customers with their orders.
    Be friendly and efficient. If you can't help,
    hand off to a specialist.""",
    tools=[order_lookup, refund_tool]
)

sales_agent = Agent(
    name="Sales Specialist",
    instructions="You help customers find the right products.",
    tools=[product_search, inventory_check]
)

2. Handoffs

Seamless transitions between agents:

from openai import handoff

# Define when to hand off
support_agent = Agent(
    name="Support",
    instructions="Help with support. Hand off sales questions.",
    handoffs=[
        handoff(
            to=sales_agent,
            condition="Customer asks about purchasing products"
        ),
        handoff(
            to=billing_agent,
            condition="Customer has billing issues"
        )
    ]
)

3. Guardrails

Input/output validation and safety:

from openai import guardrail

# Input guardrail
@guardrail(type="input")
def check_pii(message):
    """Block messages containing PII"""
    if contains_pii(message):
        return "Please don't share personal information."
    return None  # Allow the message

# Output guardrail
@guardrail(type="output")
def check_response(response):
    """Ensure responses are appropriate"""
    if is_harmful(response):
        return "I can't help with that request."
    return None  # Allow the response

agent = Agent(
    name="Safe Agent",
    guardrails=[check_pii, check_response]
)

Running Agents

from openai import Runner

# Create a runner
runner = Runner(agents=[support_agent, sales_agent, billing_agent])

# Process a conversation
result = runner.run(
    initial_agent=support_agent,
    messages=[
        {"role": "user", "content": "I want to return my order"}
    ]
)

print(result.messages)  # Full conversation
print(result.final_agent)  # Which agent ended the conversation

Key Advantages

Feature Benefit
Simple API Easy to learn, quick to implement
Native integration Works seamlessly with OpenAI models
Built-in safety Guardrails are first-class citizens
Tracing included Debug with OpenAI's dashboard
Production ready Designed for scale from day one

Comparison with Other Frameworks

OpenAI Agents SDK    LangChain           CrewAI
─────────────────    ─────────           ──────
Lightweight          Feature-rich        Role-focused
3 primitives         Many abstractions   Team metaphor
OpenAI-native        Model-agnostic      Model-agnostic
Built-in guardrails  Add-on safety       Basic safety

When to Choose OpenAI Agents SDK

Best for:

  • OpenAI-first applications
  • Simple, clean architectures
  • Projects needing built-in safety
  • Teams wanting minimal dependencies

⚠️ Consider alternatives when:

  • You need multi-model support
  • Want extensive community tools
  • Building complex multi-agent systems

Next, we'll learn how to choose the right framework for your project. :::

Quiz

Module 2: Agent Frameworks Overview

Take Quiz