openai-agents
БесплатноБез исполняемых скриптовНе проверенGuide to the OpenAI Agents SDK for JavaScript and TypeScript (@openai/agents, @openai/agents- realtime), covering text agents and realtime voice agents…
Об этом скилле
OpenAI Agents SDK Skill
Complete skill for building AI applications with OpenAI Agents SDK (JavaScript/TypeScript), covering text agents, realtime voice agents, multi-agent workflows, and production deployment patterns.
Installation & Setup
Install required packages:
npm install @openai/agents zod@3
npm install @openai/agents-realtime # For voice agents
Set environment variable:
export OPENAI_API_KEY="your-api-key"
Supported runtimes:
- Node.js 22+
- Deno
- Bun
- Cloudflare Workers (experimental)
Core Concepts
1. Agents
LLMs equipped with instructions and tools:
import { Agent } from '@openai/agents';
const agent = new Agent({
name: 'Assistant',
instructions: 'You are helpful.',
tools: [myTool],
model: 'gpt-4o-mini',
});
2. Tools
Functions agents can call, with automatic schema generation:
import { tool } from '@openai/agents';
import { z } from 'zod';
const weatherTool = tool({
name: 'get_weather',
description: 'Get weather for a city',
parameters: z.object({
city: z.string(),
}),
execute: async ({ city }) => {
return `Weather in ${city}: sunny`;
},
});
3. Handoffs
Multi-agent delegation:
const specialist = new Agent({ /* ... */ });
const triageAgent = Agent.create({
name: 'Triage',
instructions: 'Route to specialists',
handoffs: [specialist],
});
4. Guardrails
Input/output validation for safety:
const agent = new Agent({
inputGuardrails: [homeworkDetector],
outputGuardrails: [piiFilter],
});
5. Structured Outputs
Type-safe responses with Zod:
const agent = new Agent({
outputType: z.object({
sentiment: z.enum(['positive', 'negative', 'neutral']),
confidence: z.number(),
}),
});
Text Agents
Basic Usage
import { run } from '@openai/agents';
const result = await run(agent, 'What is 2+2?');
console.log(result.finalOutput);
console.log(result.usage.totalTokens);
Streaming
const stream = await run(agent, 'Tell me a story', {
stream: true,
});
for await (const event of stream) {
if (event.type === 'raw_model_stream_event') {
const chunk = event.data?.choices?.[0]?.delta?.content || '';
process.stdout.write(chunk);
}
}
Templates:
templates/text-agents/agent-basic.tstemplates/text-agents/agent-streaming.ts
Multi-Agent Handoffs
Create specialized agents and route between them:
const billingAgent = new Agent({
name: 'Billing',
handoffDescription: 'For billing and payment questions',
tools: [processRefundTool],
});
const techAgent = new Agent({
name: 'Technical',
handoffDescription: 'For technical issues',
tools: [createTicketTool],
});
const triageAgent = Agent.create({
name: 'Triage',
instructions: 'Route customers to the right specialist',
handoffs: [billingAgent, techAgent],
});
Templates:
templates/text-agents/agent-handoffs.ts
References:
references/agent-patterns.md- LLM vs code orchestration
Guardrails
Input Guardrails
Validate input before processing:
const homeworkGuardrail: InputGuardrail = {
name: 'Homework Detection',
execute: async ({ input, context }) => {
const result = await run(guardrailAgent, input);
return {
tripwireTriggered: result.finalOutput.isHomework,
outputInfo: result.finalOutput,
};
},
};
const agent = new Agent({
inputGuardrails: [homeworkGuardrail],
});
Output Guardrails
Filter responses:
const piiGuardrail: OutputGuardrail = {
name: 'PII Detection',
execute: async ({ agentOutput }) => {
const phoneRegex = /\b\d{3}[-. ]?\d{3}[-. ]?\d{4}\b/;
return {
tripwireTriggered: phoneRegex.test(agentOutput as string),
outputInfo: { detected: 'phone_number' },
};
},
};
Templates:
templates/text-agents/agent-guardrails-input.tstemplates/text-agents/agent-guardrails-output.ts
Human-in-the-Loop
Require approval for specific actions:
const refundTool = tool({
name: 'process_refund',
requiresApproval: true, // ← Requires human approval
execute: async ({ amount }) => {
return `Refunded $${amount}`;
},
});
// Handle approval requests
let result = await runner.run(input);
while (result.interruption) {
if (result.interruption.type === 'tool_approval') {
const approved = await promptUser(result.interruption);
result = approved
? await result.state.approve(result.interruption)
: await result.state.reject(result.interruption);
}
}
Templates:
templates/text-agents/agent-human-approval.ts
Realtime Voice Agents
Creating Voice Agents
import { RealtimeAgent, tool } from '@openai/agents-realtime';
const voiceAgent = new RealtimeAgent({
name: 'Voice Assistant',
instructions: 'Keep responses concise for v
Установить openai-agents в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл openai-agents?
Guide to the OpenAI Agents SDK for JavaScript and TypeScript (@openai/agents, @openai/agents- realtime), covering text agents and realtime voice agents. Covers agents, tools defined with Zod schemas, multi-agent workflows and handoffs, input and output guardrails, structured outputs, streaming, human-in-the-loop patterns, and integrations for Cloudflare Workers, Next.js, React, Hono and Node.js, with templates for each agent type plus error handling and debugging strategies. Prevents 9+ documented errors including Zod schema type errors, MCP tracing failures, agent infinite loops, tool call failures, and schema mismatches. Use when building or debugging agent workflows with this SDK, adding tools or handoffs, implementing realtime voice agents, or hitting those errors.
Как установить скилл openai-agents?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл openai-agents запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic