Lesson 7 of 20

Agent Frameworks Overview

OpenAI Agents SDK

3 min read

In March 2025, OpenAI released 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 agents 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 agents 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 validation and safety using guardrail functions:

from agents import Agent, InputGuardrail, GuardrailFunctionOutput, Runner

safety_agent = Agent(
    name="Safety Check",
    instructions="Determine if the input is safe. Respond with 'safe' or 'unsafe'."
)

async def content_filter(ctx, agent, input_text):
    """Check content safety before processing"""
    result = await Runner.run(safety_agent, input_text)
    return GuardrailFunctionOutput(
        output_info={"safe": result.final_output == "safe"},
        tripwire_triggered=result.final_output != "safe"
    )

agent = Agent(
    name="Support Agent",
    instructions="You help customers with their orders.",
    input_guardrails=[InputGuardrail(guardrail_function=content_filter)]
)

Running Agents

from agents import Runner

# Process a conversation
result = await Runner.run(
    support_agent,
    input="I want to return my order"
)

print(result.final_output)  # Agent's response
print(result.last_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
FREE WEEKLY NEWSLETTER

Stay on the Nerd Track

One email per week — courses, deep dives, tools, and AI experiments.

No spam. Unsubscribe anytime.