Openai Agents Sdk

laguagu/claude-code-nextjs-skills/skills/openai-agents-sdk

作者 laguaguc51d9c872cf5無授權條款68 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫3 天前更新

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.

AI 產生的概覽

指導使用 openai-agents SDK 開發 Python AI 代理,涵蓋工具、交接、護欄、工作階段、串流與追蹤。

功能
此技能為使用 openai-agents(agents)套件建構 Python AI 代理提供參考指引。內容涵蓋核心 Runner API、函式工具、結構化輸出、交接、護欄、工作階段、串流、協調與追蹤,以及透過 LiteLLM 介接 Azure OpenAI 等提供者整合。它也說明如何在離線情況下使用已安裝的 agents.testing 輔助工具進行驗證,並在缺少文件時閱讀已安裝套件的原始碼。
適用情境
適用於撰寫或審查從 agents 匯入的 Python 程式碼、使用 Runner.run_sync 或 Runner.run_streamed、定義 @function_tool、AgentOutputSchema 或 SQLiteSession,或詢問 openai-agents-python SDK 的情境。它針對 Python SDK,而非 TypeScript 的 @openai/agents 套件。
執行需求
需要安裝 openai-agents 套件的 Python 環境;即時呼叫模型需要提供者憑證與網路存取,離線工作則依賴已安裝套件的原始碼與 agents.testing。此技能不附帶指令碼,只有參考文件。

OpenAI Agents SDK for Python

Use this skill for openai-agents / agents, not the TypeScript SDK. Resolve the installed package and its provider integrations before implementing an API. Current SDK documentation and a matching source tag take precedence over static examples.

Choose a model from the current OpenAI model catalog and model-selection guide. Check the selected model's tools, reasoning settings and provider availability; an SDK fallback or a demo ID is not a permanent recommendation.

The wheel ships no docs. Offline, read the installed source: the version from importlib.metadata.version("openai-agents"), public exports in agents/__init__.py, docstrings and types in the package directory (python -c "import agents; print(agents.__file__)"). The documentation source is docs/ at repository tag v<version>.

Core shape

Runner.run_sync raises inside a running event loop (async handlers and notebooks); use await Runner.run(...). Runner.run_streamed(...) itself is not awaited; consume its stream_events() async iterator to completion.

Checked with openai-agents 0.22.3; confirm names in the installed source for another version:

python
import asynciofrom pydantic import BaseModelfrom agents import Agent, ModelSettings, Runner, SQLiteSession, function_toolfrom openai.types.shared import Reasoning
class OrderAnswer(BaseModel):    order_id: str    status: str    reply: str
@function_tooldef get_order_status(order_id: str) -> str:    """Return an order's shipping status.
    Args:        order_id: Order ID given by the customer.    """    return f"{order_id}: shipped"  # authorize and read the app's data here
support = Agent(    name="Support",    instructions="Answer order questions. Use get_order_status for order data.",    model="gpt-6.1-sol",  # example API ID; use the project's configured model    model_settings=ModelSettings(reasoning=Reasoning(effort="medium")),    tools=[get_order_status],    output_type=OrderAnswer,)# A manager keeps control with tools=[order_tool]; handoffs=[support] transfers it.order_tool = support.as_tool("order_support", "Answer an order question.")
async def main() -> None:    session = SQLiteSession("user-123", "conversations.db")  # ID owned by the signed-in user    result = await Runner.run(support, "Where is order A-17?", session=session)    answer: OrderAnswer = result.final_output  # validated OrderAnswer instance    print(answer.status, answer.reply)
asyncio.run(main())

The example uses Responses (the SDK's default API). GPT-6.1 Sol requires Responses for tool calling and does not support none or minimal reasoning effort. Model availability/live responses were not tested by the offline SDK check.

Integration decisions

  • Keep the project's provider, model and storage unless the task requires a change. Verify model IDs/capabilities in provider configuration or live docs. SDK model/settings defaults may change; configure product-critical choices explicitly.
  • Use native provider/client support when it fits. LiteLLM/Any-LLM are optional integrations with their own compatibility and settings behavior.
  • Choose handoffs when a specialist takes over, or agent.as_tool() when the manager should continue after delegated work. A fixed pipeline does not need extra agents merely to implement ordinary control flow.
  • Authorize side effects in tools. Agent instructions, output schemas and guardrails do not replace authorization or idempotency.
  • Decide history ownership, approval/resume and tracing data policy before exposing a multi-turn agent to untrusted clients.

Read for the feature

  • Agents/providers [blocked]: model defaults, Azure and adapters.
  • Tools [blocked]: local/hosted execution, delegation and approval/resume.
  • Structured output [blocked]: schema and capability constraints.
  • Streaming [blocked]: event types, failures and guardrails.
  • Handoffs [blocked]: control transfer and filtering.
  • Guardrails [blocked]: execution timing and coverage.
  • Sessions [blocked]: history ownership and persistence.
  • Orchestration/tracing [blocked]: run limits and observability.
  • Sandbox [blocked]: beta workspace execution and resume state.

Use the OpenAI Developer Docs MCP (https://developers.openai.com/mcp) if available for current OpenAI API/provider behavior, or its plain-text index https://developers.openai.com/api/docs/llms.txt; use the Python SDK's own reference for SDK signatures. Read selected official examples from a compatible tag, not a copied catalog of demos.

Verification

Verify changed tools, multi-turn history, approval/denial and failure recovery. Use installed agents.testing (verified in 0.22.3) for offline orchestration: ScriptedModel, ModelStep, assistant_message, function_call and model.assert_complete(), with RunConfig(tracing_disabled=True); assigning agent.model = ScriptedModel([...]) runs the core shape offline. Run the project's checks; report missing provider access separately from verified SDK behavior.

來源與署名

來源:laguagu/claude-code-nextjs-skills位於skills/openai-agents-sdk提交c51d9c8

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架