openai-agents-sdk
26
总安装量
26
周安装量
#14183
全站排名
安装命令
npx skills add https://github.com/laguagu/claude-code-nextjs-skills --skill openai-agents-sdk
Agent 安装分布
opencode
21
claude-code
21
github-copilot
20
codex
20
gemini-cli
19
amp
16
Skill 文档
OpenAI Agents SDK (Python)
Use this skill when developing AI agents using OpenAI Agents SDK (openai-agents package).
Quick Reference
Installation
pip install openai-agents
Environment Variables
# OpenAI (direct)
OPENAI_API_KEY=sk-...
LLM_PROVIDER=openai
# Azure OpenAI (via LiteLLM)
LLM_PROVIDER=azure
AZURE_API_KEY=...
AZURE_API_BASE=https://your-resource.openai.azure.com
AZURE_API_VERSION=2024-12-01-preview
Basic Agent
from agents import Agent, Runner
agent = Agent(
name="Assistant",
instructions="You are a helpful assistant.",
model="gpt-5.2", # or "gpt-5", "gpt-5.2-nano"
)
# Synchronous
result = Runner.run_sync(agent, "Tell me a joke")
print(result.final_output)
# Asynchronous
result = await Runner.run(agent, "Tell me a joke")
Key Patterns
| Pattern | Purpose |
|---|---|
| Basic Agent | Simple Q&A with instructions |
| Azure/LiteLLM | Azure OpenAI integration |
| AgentOutputSchema | Strict JSON validation with Pydantic |
| Function Tools | External actions (@function_tool) |
| Streaming | Real-time UI (Runner.run_streamed) |
| Handoffs | Specialized agents, delegation |
| Agents as Tools | Orchestration (agent.as_tool) |
| LLM as Judge | Iterative improvement loop |
| Guardrails | Input/output validation |
| Sessions | Automatic conversation history |
| Multi-Agent Pipeline | Multi-step workflows |
Reference Documentation
For detailed information, see:
- agents.md – Agent creation, Azure/LiteLLM integration
- tools.md – Function tools, hosted tools, agents as tools
- structured-output.md – Pydantic output, AgentOutputSchema
- streaming.md – Streaming patterns, SSE with FastAPI
- handoffs.md – Agent delegation
- guardrails.md – Input/output validation
- sessions.md – Sessions, conversation history
- patterns.md – Multi-agent workflows, LLM as judge, tracing