OpenAI Agents SDK(Python 版) の公式実装。LLM にツール・指示・ガードレール・他エージェントへの引き継ぎ(Handoff)を与え、「マルチエージェントワークフロー」を組むための軽量フレームワーク。
openai-agents として公開。src/agents/ 配下):
Agent … instructions / tools / handoffs / guardrails を持つ LLM 定義Runner … エージェント実行ループ(同期・非同期・ストリーミング)tool / function_tool … Python 関数・MCP・ホスト済みツールを統一 I/F でツール化handoffs … 別エージェントへの委譲guardrail … 入出力の検証・遮断memory / sessions … 会話履歴の自動管理(Redis・SQLAlchemy オプション)tracing … 実行トレースの可視化(OpenAI Traces UI 連携)sandbox … v0.14 で追加された「Sandbox Agent」(ファイル操作やコマンド実行を安全な環境で行う長時間タスク向け)realtime / voice … gpt-realtime による音声エージェントexamples/(basic, agent_patterns, handoffs, mcp, research_bot, customer_service, realtime, voice, sandbox…)と MkDocs による公式ドキュメント、tests/ 完備。| 比較対象 | Agents SDK の優位点 |
|---|---|
| OpenAI API を直接叩く(Responses / Chat Completions) | tool calling ループ・JSON スキーマ生成・履歴管理・リトライ・ストリーミングの「定型コード」を肩代わり。Python 関数に @function_tool を付けるだけで型・description・引数スキーマを自動生成。 |
| LangChain / LangGraph | 抽象が最小(Agent・Tool・Handoff・Guardrail の 4 概念中心)で学習コストが低い。グラフ DSL を強制せず、素の Python + async で書ける。OpenAI Responses API とネイティブ連携し、Tracing UI と直結。 |
| AutoGen / CrewAI 等のマルチエージェント FW | 「Agents as tools」「Handoffs」という2方式でマルチエージェントを素直に表現。Guardrail、Human-in-the-loop、Session 永続化、Sandbox 実行が公式サポートでバージョン整合が取れる。 |
| 自作の ReAct ループ | トレーシング/ガードレール/セッション中断・再開(RunState スキーマ管理)/MCP/リアルタイム音声まで揃っているため、PoC から本番まで同じ抽象で延ばせる。 |
要するに 「OpenAI 公式が面倒を見る、最小抽象でベンダーロックインの薄いマルチエージェント実装」 が価値。
pip install openai-agents # or: uv add openai-agents
export OPENAI_API_KEY=...
音声なら [voice]、Redis セッションなら [redis] extras。
@function_tool
def get_weather(city: str) -> Weather: ...
Pydantic 型から入出力スキーマが自動生成される。MCP サーバや hosted tool も同じ tools=[...] に混ぜられる。
agent = Agent(
name="Assistant",
instructions="You are a helpful agent.",
tools=[get_weather],
handoffs=[other_agent], # 必要なら他エージェントへ委譲
input_guardrails=[...], # 必要なら入力検証
)
result = await Runner.run(agent, "What's the weather in Tokyo?")
print(result.final_output)
Runner.run_sync / Runner.run_streamed も選択可能。内部で tool 呼び出し・handoff・ガードレールのループを自動実行。
examples/agent_patterns/ に routing / parallelization / llm-as-judge / deterministic 等のレシピあり)。Session で履歴永続化、RunState 保存で中断・再開、Human-in-the-loop で承認フローを実装。make sync → 実装 → make format / make lint / make typecheck / make tests(CLAUDE.md の $code-change-verification を遵守)→ PR テンプレートで提出。