openai-agents
/openai-agents
Pomaga budować agentów w Pythonie z OpenAI Agents SDK: narzędzia funkcyjne, przekazywanie pracy między agentami, guardrails, sesje, strumieniowanie, śledzenie i obsługa MCP.
- Autor
- TerminalSkills ↗
- Repozytorium
- skills ↗
- Licencja
- Apache-2.0
- Ostatnia zmiana repozytorium
- 25.10.2026
Ocena i bezpieczeństwo
- Pliki w paczce
- 2
- Skrypty
- 0
- Komentarze HTML
- 0
- Adresy URL w SKILL.md
- 1
Brak sygnałów. Repozytorium zmienione 25.10.2026, bez odwołań do wycofanych modeli i API.
Apache-2.0, otwarta: można używać i zmieniać, z zachowaniem licencji i informacji o zmianach.
Co robi i kiedy
Pomaga budować agentów w Pythonie z OpenAI Agents SDK: narzędzia funkcyjne, przekazywanie pracy między agentami, guardrails, sesje, strumieniowanie, śledzenie i obsługa MCP.
Oryginalny opis (EN)
The OpenAI Agents SDK is a Python framework (openai-agents) for building agents that call tools, hand work to other agents, run guardrails and stream results, with built-in tracing and MCP support. Use when building a multi-agent workflow with OpenAI models, adding function tools, handoffs, input guardrails or sessions, or when the user mentions openai-agents, Runner.run, or the Agents SDK (the successor to Swarm).
Jak działa
- Overview
- Instructions
- Examples
- Guidelines
Podgląd SKILL.md
---
name: openai-agents
description: >-
The OpenAI Agents SDK is a Python framework (openai-agents) for building agents that call tools,
hand work to other agents, run guardrails and stream results, with built-in tracing and MCP support.
Use when building a multi-agent workflow with OpenAI models, adding function tools, handoffs, input
guardrails or sessions, or when the user mentions openai-agents, Runner.run, or the Agents SDK
(the successor to Swarm).
license: Apache-2.0
compatibility: "Python 3.10+, OPENAI_API_KEY"
metadata:
author: terminal-skills
version: "1.1.0"
category: data-ai
tags: "openai, agents, tools, guardrails, multi-agent"
repository: "https://github.com/openai/openai-agents-python"
---
# OpenAI Agents SDK
## Overview
The OpenAI Agents SDK (`pip install openai-agents`, import name `agents`; version 0.24.0 checked, Python 3.10+) is the production successor to the experimental Swarm project. Its small set of primitives: `Agent` (instructions plus tools), handoffs and agents-as-tools for delegation, guardrails for validating input and output, sessions for memory, and built-in tracing. It uses the Responses API by default for OpenAI models. A JavaScript version exists as `@openai/agents`; this skill covers the Python SDK.
## Instructions
1. Install and set the key: `pip install openai-agents`, `export OPENAI_API_KEY=...`.
2. Create agents with `Agent(name=..., instructions=..., tools=[...], model=...)`. Run with `Runner.run_sync(agent, text)` in scripts, `await Runner.run(agent, text)` in async code; read `result.final_output`.
3. Tools: decorate a function with `@function_tool`. The schema comes from type hints and the docstring (Google-style `Args:` descriptions). Hosted tools such as `WebSearchTool` can go in the same `tools` list.
4. Handoffs: `handoffs=[billing_agent]` takes `Agent` objects (or `handoff(...)` wrappers), not name strings, so define the specialists first. A handoff transfers the conversation; use `agent.as_tool(...)` instead when the main agent should keep control and just call another agent.
5. Typed output: `output_type=SomePydanticModel` makes `final_output` a validated object.
6. Input guardrails: decorate `async def check(ctx, agent, input) -> GuardrailFunctionOutput` with `@input_guardrail` and pass `input_guardrails=[check]`. When `tripwire_triggered=True` the run raises `InputGuardrailTripwireTriggered`; catch it. Output guardrails work the same with `@output_guardrail`.
7. Streaming: `result = Runner.run_streamed(agent, input=...)` (not awaited), then `async for event in result.stream_events()`. Event types are `raw_response_event` (tokens; check `isinstance(event.data, ResponseTextDeltaEvent)` from `openai.types.responses`), `run_item_stream_event` (`event.name` such as `tool_called`, `tool_output`, `message_output_created`) and `agent_updated_stream_event` (after a handoff).
8. MCP: `MCPServerStdio(params={"command": "npx", "args": [...]})` as an async context manager, then `Agent(mcp_servers=[server])`. Also available: `MCPServerStreamableHttp(params={"url": ..., "headers": ...})` and `HostedMCPTool` (the Responses API connects to the server itself). `cache_tools_list=True` is safe only if the tool list rarely changes.
9. Tracing is on by default and uploads to the OpenAI dashboard; disable with `OPENAI_AGENTS_DISABLE_TRACING=1` or `set_tracing_disabled(True)` when data must not leave your environment.
## Examples
### Example 1: Triage agent with a billing specialist
**User request:** "Route refund questions to a billing agent that can look up orders."
```python
import asyncio
from agents import Agent, Runner, function_tool
@function_tool
def lookup_order(order_id: str) -> str:
"""Look up an order.
Args:
order_id: The order identifier, for example ORD-12345
"""
return "ORD-12345: delivered 2026-10-02, total $48.00, status damaged-on-arrival"
billing = Agent(
name="Billing Specialist",
instructions="Handle refunds. Always look up the order first.",
tools=[lookup_order],
)
triage = Agent(
name="Triage",
instructions="Send billing and refund questions to the Billing Specialist.",
handoffs=[billing],
)
async def main():
result = await Runner.run(triage, "Refund order ORD-12345, it arrived damaged")
print(result.final_output)
asyncio.run(main())
```
**Result:** the trace shows Triage handing off to Billing Specialist, one `lookup_order` call, then a reply about the refund.
### Example 2: Block off-topic input with a guardrail
**User request:** "Reject messages that are not support requests before the main agent runs."
```python
# The `await`/`async for` lines in Examples 2 and 3 must run inside an `async def` (as in Example 1) or a notebook.
from pydantic import BaseModel
from agents import (Agent, Runner, GuardrailFunctionOutput, RunContextWrapper,
input_guardrail, InputGuardrailTripwireTriggered)
class Check(BaseModel):
is_support_request: bool
checker = Agent(name="Checker", instructions="Is this a customer support request?", output_type=Check)
@input_guardrail
async def only_support(ctx: RunContextWrapper[None], agent: Agent, user_input) -> GuardrailFunctionOutput:
res = await Runner.run(checker, user_input, context=ctx.context)
return GuardrailFunctionOutput(output_info=res.final_output,
tripwire_triggered=not res.final_output.is_support_request)
support = Agent(name="Support", instructions="Help with orders.", input_guardrails=[only_support])
try:
await Runner.run(support, "Write me a poem about cats")
except InputGuardrailTripwireTriggered:
print("Sorry, I can only help with orders.")
```
**Result:** the poem request raises the tripwire exception before the Support agent produces output.
### Example 3: Stream tokens and handoffs
```python
from agents import Runner # triage is the agent from Example 1
from openai.types.responses import ResponseTextDeltaEvent
result = Runner.run_streamed(triage, input="Where is order ORD-12345?")
async for event in result.stream_events():
if event.type == "raw_response_event" and isinstance(event.data, ResponseTextDeltaEvent):
print(event.data.delta, end="", flush=True)
elif event.type == "agent_updated_stream_event":
print(f"\n[now: {event.new_agent.name}]")
```
## Guidelines
- `handoffs` must hold agent objects; strings fail. Avoid circular definitions by creating the specialist first or by appending to `agent.handoffs` afterwards.
- Keep consuming `stream_events()` to the end; the run only finishes then.
- Input guardrails run only on the first agent in a chain, output guardrails only on the last; put checks that must always apply on the tool itself.
- Tracing sends prompts and tool data to OpenAI by default; turn it off for sensitive workloads.
- Give MCP servers only to agents that need them, connect only to trusted servers, and keep tokens in headers read from environment variables.
- Cap runaway loops with `max_turns` on `Runner.run`.
Pliki w paczce (2)
- SKILL.md 7 KB
- _scores.json 2 KB
Wersje
| Repozytorium | Wynik | Licencja |
|---|---|---|
| Ta strona · TerminalSkills/skills | 100 | Apache-2.0 |
| coco-research/coco | 100 | MIT |
| MARUCIE/openclaw-foundry | 100 | MIT |
| kid-sid/codex-spellbook | 100 | MIT |
Migawka bazy z 28.10.2026 · wersja paczki 79e24f451849 (skrót SHA-256 całej paczki)
Pobrania w ostatnich 30 dniach: 0 · ranking
Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.
Podobne skille
- 100openai-agents-sdk
Wspiera tworzenie agentów w Pythonie z pakietem openai-agents: przekazania między agentami, narzędzia funkcyjne, guardrails, sesje, streaming i tracing, także przez Azure OpenAI lub LiteLLM. - 100openai-agents-sdk
Pomaga budować agentów w Pythonie z OpenAI Agents SDK: runnery, narzędzia, przekazania, guardrails, tracing, pamięć, topologie wieloagentowe i deterministyczną orkiestrację. - 95scaffolding-openai-agents
Buduje agentów AI na OpenAI Agents SDK: handoffy, narzędzia, guardrails, orkiestrację i strumieniowanie odpowiedzi. - 100migrating-openai-agents-sdk-to-pydantic-ai
Przenosi aplikacje w Pythonie z OpenAI Agents SDK na Pydantic AI, w tym agentów, narzędzia, handoffy, guardrails, sesje, zatwierdzanie przez człowieka i streaming. - 100microsoft-agent-framework
Pomaga budować agentów AI i przepływy wieloagentowe w Microsoft Agent Framework w Pythonie i .NET oraz migrować z agentów Semantic Kernel. - 100agentmail-toolkit
Dodaje narzędzia AgentMail do frameworków agentów przez AgentMail Toolkit w TypeScript lub Pythonie: Vercel AI SDK, LangChain, OpenAI Agents SDK, LiveKit Agents i adaptery MCP.