PluginBench
Skill
Pass
Audit score 90

openai-agents-sdk

laguagu/claude-code-nextjs-skills

Build AI agents with OpenAI's Python SDK—multi-agent handoffs, function tools, guardrails, streaming, and tracing.

What is openai-agents-sdk?

OpenAI Agents SDK (Python) skill for developing AI agents using the `openai-agents` package. Use when building agents with multi-agent handoffs, function tools, structured output, guardrails, sessions, streaming, or tracing. Python only—not the TypeScript SDK.

  • Create basic agents with instructions and model configuration
  • Build multi-agent systems with handoffs and delegation
  • Define function tools with `@function_tool` decorator
  • Enforce structured JSON output with `AgentOutputSchema` and Pydantic validation
  • Stream agent responses in real-time for UI integration
  • Persist conversation history with `SQLiteSession` or other backends

How to install openai-agents-sdk

npx skills add https://github.com/laguagu/claude-code-nextjs-skills --skill openai-agents-sdk
Prerequisites
  • Python 3.8+
  • Install `openai-agents` package via `uv add openai-agents` or `pip install openai-agents`
  • Set `OPENAI_API_KEY` and `OPENAI_MODEL` environment variables
  • Verified model ID from OpenAI's model catalog
Claude Code
Cursor
Windsurf
Cline

How to use openai-agents-sdk

  1. 1.Install the package: `uv add openai-agents`
  2. 2.Set environment variables: `OPENAI_API_KEY` and `OPENAI_MODEL`
  3. 3.Create an `Agent` with name, instructions, and model
  4. 4.Call `Runner.run_sync()` for synchronous execution or `Runner.run()` for async
  5. 5.Add function tools with `@function_tool` decorator if external actions are needed
  6. 6.Use `AgentOutputSchema` with Pydantic for structured JSON output validation
  7. 7.Enable streaming with `Runner.run_streamed()` for real-time UI updates
  8. 8.Implement handoffs or `agent.as_tool()` for multi-agent delegation

Use cases

Good for
  • Building a Q&A assistant with custom instructions and function tools
  • Creating a multi-agent workflow where specialized agents delegate tasks
  • Streaming agent responses to a web UI in real-time
  • Persisting multi-turn conversations across requests with automatic history
  • Validating agent output against a strict Pydantic schema before returning to users
Who it's for
  • Python developers building AI agents
  • Teams implementing multi-agent orchestration workflows
  • Engineers integrating OpenAI agents into FastAPI or web applications
  • Developers using Azure OpenAI or other LLM providers via LiteLLM

openai-agents-sdk FAQ

What's the difference between this skill and the TypeScript `@openai/agents` SDK?

This skill covers the Python `openai-agents` package only. The TypeScript `@openai/agents` SDK is a separate implementation; use the appropriate skill for your language.

How do I use Azure OpenAI instead of OpenAI?

Configure Azure via LiteLLM by setting provider-specific environment variables. See the agents.md reference for detailed setup—do not hardcode provider env vars in code.

How do I persist conversation history across requests?

Use `SQLiteSession` or other session backends (SQLAlchemy, Redis, OpenAI Conversations) to automatically maintain conversation state. See sessions.md for configuration.

Can I stream agent responses to a web UI?

Yes, use `Runner.run_streamed()` to get real-time events. See streaming.md for event types and FastAPI/SSE integration patterns.

How do I validate agent output as JSON?

Define an `AgentOutputSchema` using Pydantic dataclasses and pass it to the agent. The SDK enforces strict or non-strict validation. See structured-output.md for details.

Full instructions (SKILL.md)

Source of truth, from laguagu/claude-code-nextjs-skills.


name: openai-agents-sdk description: OpenAI Agents SDK (Python) development. Use when building AI agents, multi-agent handoffs, function tools, guardrails, sessions, streaming, or tracing with the openai-agents / agents Python package — including Azure OpenAI via LiteLLM. Triggers on imports from agents, uses of Runner.run_sync/Runner.run_streamed, @function_tool, AgentOutputSchema, SQLiteSession, or questions about the openai-agents-python SDK. Python only — not the TypeScript @openai/agents SDK.

OpenAI Agents SDK (Python)

Use this skill when developing AI agents using OpenAI Agents SDK (openai-agents package).

Quick Reference

Installation

uv add openai-agents        # or `pip install openai-agents` outside a uv project

Environment Variables

Set both in the process environment before running the example; replace the placeholders:

export OPENAI_API_KEY="sk-..."
export OPENAI_MODEL="your-verified-model-id"  # this example's own variable; the SDK itself reads OPENAI_DEFAULT_MODEL

Using Azure or another provider instead? See agents.md — don't hardcode provider env vars here, they vary and go stale.

Basic Agent

import os
from agents import Agent, Runner

agent = Agent(
    name="Assistant",
    instructions="You are a helpful assistant.",
    model=os.environ["OPENAI_MODEL"],  # configure a verified model ID
)

# Synchronous
result = Runner.run_sync(agent, "Tell me a joke")
print(result.final_output)

# Asynchronous
result = await Runner.run(agent, "Tell me a joke")

Omitting model= uses the installed SDK's default. Configure it explicitly in production and verify available IDs against the provider's model catalog.

Key Patterns

PatternPurpose
Basic AgentSimple Q&A with instructions
Azure/LiteLLMAzure OpenAI integration
AgentOutputSchemaStrict JSON validation with Pydantic
Function ToolsExternal actions (@function_tool)
StreamingReal-time UI (Runner.run_streamed)
HandoffsSpecialized agents, delegation
Agents as ToolsOrchestration (agent.as_tool)
LLM as JudgeIterative improvement loop
GuardrailsInput/output validation
SessionsAutomatic conversation history
Multi-Agent PipelineMulti-step workflows
SandboxingSandboxAgent — filesystem, shell and skills inside a local/Docker sandbox (beta)
TracingBuilt-in spans for runs, tools, handoffs and guardrails; pluggable processors

The SDK has no separate Subagent class: express delegation with handoffs or agent.as_tool(). For model-written tool orchestration, use ProgrammaticToolCallingTool and verify its Responses-only constraints.

Preferred: Live Docs via MCP

Model names and API details change frequently. When available, consult the OpenAI Developer Docs MCP server (openaiDeveloperDocs) before relying on the static references below.

Setup (Codex CLI):

codex mcp add openaiDeveloperDocs --url https://developers.openai.com/mcp

Setup (Claude Code):

claude mcp add --transport http openaiDeveloperDocs https://developers.openai.com/mcp

Or in Codex ~/.codex/config.toml (VS Code and Cursor use different JSON schemas):

[mcp_servers.openaiDeveloperDocs]
url = "https://developers.openai.com/mcp"

Key tools: mcp__openaiDeveloperDocs__search_openai_docs, fetch_openai_doc, list_api_endpoints, get_openapi_spec.

Rules: Cite fetched docs. Never speculate on field names, defaults, or current model IDs — fetch first. Keep quotes under 125 chars.

Fallback when MCP is unavailable: https://developers.openai.com/api/docs/llms.txt (plain-text index of all API docs; each entry has a .md twin at /api/docs/<slug>.md).

Reference Documentation

Offline/quick-lookup snippets. Verify model names and API signatures against the MCP or docs when accuracy matters.

  • agents.md - read when choosing or wiring a model: default-model caveat, LiteLLM, native Azure client
  • tools.md - read when adding function tools, hosted tools, or agents-as-tools
  • structured-output.md - read when the output must be a Pydantic/dataclass shape (AgentOutputSchema, strict vs non-strict)
  • streaming.md - read when streaming to a UI (event types, SSE with FastAPI)
  • handoffs.md - read when one agent delegates to another (handoff vs as_tool, input filters)
  • guardrails.md - read when validating input/output or gating tool calls
  • sessions.md - read when conversation history must persist across requests (SQLite, SQLAlchemy, Redis, OpenAI Conversations)
  • patterns.md - read for multi-agent pipelines, LLM-as-judge loops, tracing controls, max_turns, parallelization
  • sandbox.md - read when the agent must edit files or run commands in an isolated workspace (SandboxAgent, beta)

Official Documentation