К основному содержанию
скилл CX Codex

openai-agents-sdk — скилл для Claude Code: что делает и установка

Скилл помогает писать агентов на Python-библиотеке openai-agents: настраивать передачу контекста между агентами, инструменты через @function_tool, стриминг и сессии в SQLite.

Установить в Claude Code · Через Skills CLI (Vercel) Все способы и платформы ↓
npx skills add laguagu/claude-code-nextjs-skills --skill openai-agents-sdk -a claude-code
Открыть на GitHub

Что делает openai-agents-sdk

Пакет предназначен только для Python-библиотеки openai-agents и не подходит для TypeScript SDK. Скилл даёт правила для правильной оркестрации: разделяет передачу управления через handoffs и вызов агента как инструмента через agent.as_tool(). Внутри есть подсказки по работе с циклом событий, где Runner.run_sync падает в асинхронном окружении и требует await Runner.run(...).

Для сохранения состояния диалога предлагается использовать SQLiteSession. Скилл подчёркивает, что guardrails и системные инструкции не заменяют авторизацию внутри самих инструментов. Для тестов без вызовов к реальным API используется модуль agents.testing с заглушкой ScriptedModel.

Подключение к Azure OpenAI поддерживается напрямую или через LiteLLM. Если вы работаете в Jupyter-ноутбуке, синхронный Runner.run_sync сразу вызовет ошибку цикла событий, поэтому переход на await Runner.run здесь обязателен.

Какие задачи решает

  • настроить цепочки передачи управления через handoffs
  • обернуть Python-функции в инструменты с декоратором @function_tool
  • привязать историю диалогов к локальной базе через SQLiteSession
  • протестировать логику агента офлайн через agents.testing и ScriptedModel
  • организовать потоковый ответ через асинхронный итератор stream_events()

Примеры запросов агенту

  • Напиши агента поддержки на openai-agents с сохранением истории в SQLiteSession и структурированным выводом OrderAnswer
  • Как сделать handoff между агентом-диспетчером и агентом возврата заказов в openai-agents?
  • Покажи, как протестировать вызовы функций агента офлайн с помощью agents.testing.ScriptedModel

Как установить openai-agents-sdk

1Через Skills CLI (Vercel)

npx skills add laguagu/claude-code-nextjs-skills --skill openai-agents-sdk -a claude-code

2Вручную: положить файлы

~/.claude/skills/openai-agents-sdk/SKILL.md

Папка скилла целиком; для одного проекта — .claude/skills/openai-agents-sdk/

По шагам, с командами для каждой платформы: Как установить скилл в Claude Code: пять способов

Из того же набора3

Похожие

extension-openai caffeinelabs Задаёт правила интеграции OpenAI в канистры Motoko через пакет openai-client. Защищает API-ключ от утечки при реплицированных вызовах. CX Codex +1 28 100установок podcast-generation microsoft Генерирует озвучку текстов в формате подкаста через модель Azure OpenAI GPT Realtime Mini по WebSocket. Помогает настроить стриминг аудио от FastAPI до React. 29установок arize-ai-provider-integration официальный arize Скилл управляет интеграциями Arize AI с провайдерами языковых моделей: помогает добавлять учётные данные, просматривать настройки и удалять подключения. Пригодится для настройки моделей, используемых оценщиками Arize. 1 100установок copilot-sdk microsoft Помогает создавать приложения на базе GitHub Copilot SDK для Node.js, Python, Go и .NET. Пригодится для программной интеграции Copilot в бэкенд или CLI-инструменты. 76установок openai-whisper-api openclaw Скилл гоняет аудио через OpenAI Audio Transcriptions API и отдаёт текст или JSON. Пригодится, когда нужно расшифровать созвон или голосовую заметку прямо из агента. CX Codex +1 5 400установок openai-docs официальный openai Скилл ищет актуальные материалы OpenAI и помогает отвечать по API, Codex, моделям и обновлению промптов с опорой на официальную документацию. CX Codex +1 6 100установок

Рядом в теме «Настройка агента: память, контекст, субагенты»

Все скиллы по теме «Настройка агента: память, контекст, субагенты» →

Вопросы о openai-agents-sdk

Как установить openai-agents-sdk в Claude Code?

Выполните в терминале команду npx skills add laguagu/claude-code-nextjs-skills --skill openai-agents-sdk -a claude-code.

Для каких версий SDK и языков подходит этот скилл?

Скилл написан строго для Python-пакетов openai-agents и agents, примеры проверены на версии 0.22.3. Для TypeScript-пакета @openai/agents он не подходит.

В чём разница между handoffs и вызовом agent.as_tool()?

Метод agent.as_tool() оставляет управление у вызывающего агента-менеджера после выполнения подзадачи. Механизм handoffs полностью передаёт диалог специализированному агенту.

Исходный текст

SKILL.md · MIT
---
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 through its native client or 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 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](https://openai.github.io/openai-agents-python/)
and a matching source tag take precedence over static examples.

Choose a model from the current [OpenAI model catalog](https://developers.openai.com/api/docs/models)
and [model-selection guide](https://developers.openai.com/api/docs/guides/model-selection).
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 asyncio
from pydantic import BaseModel
from agents import Agent, ModelSettings, Runner, SQLiteSession, function_tool
from openai.types.shared import Reasoning

class OrderAnswer(BaseModel):
    order_id: str
    status: str
    reply: str

@function_tool
def 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](https://developers.openai.com/api/docs/models/gpt-6.1-sol)
requires Responses for tool calling and does not support `none` or `minimal`
reasoning effort.

## 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](references/agents.md): model defaults, Azure and adapters.
- [Tools](references/tools.md): local/hosted execution, delegation and approval/resume.
- [Structured output](references/structured-output.md): schema and capability constraints.
- [Streaming](references/streaming.md): event types, failures and guardrails.
- [Handoffs](references/handoffs.md): control transfer and filtering.
- [Guardrails](references/guardrails.md): execution timing and coverage.
- [Sessions](references/sessions.md): history ownership and persistence.
- [Orchestration/tracing](references/patterns.md): run limits and observability.
- [Sandbox](references/sandbox.md): 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](https://github.com/openai/openai-agents-python/tree/main/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 · MIT · laguagu/claude-code-nextjs-skills

Смотрите также

Спонсоры проекта

Компании, которые помогают держать аналитику открытой