OpenAI AgentKit Expert by frankxai/claude-skills-library
npx skills add https://github.com/frankxai/claude-skills-library --skill 'OpenAI AgentKit Expert'本技能提供关于使用 OpenAI 的 AgentKit 平台和 Agents SDK 构建生产就绪的多智能体系统的全面指导,遵循 2025 年最佳实践。
用于构建、部署和优化智能体的完整平台,提供企业级工具。
核心组件:
Agents SDK 是实验性 Swarm 框架的生产演进版本。所有生产工作请使用 Agents SDK - Swarm 仅用于教育目的。
迁移说明: 如果遇到遗留的 Swarm 代码,请立即迁移到 Agents SDK。
一个智能体封装了:
设计原则: 智能体应该是轻量级且专业化的,而不是庞大且通用的。
一个例程是智能体可以执行的一系列操作:
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
可以将其视为: 一个智能体拥有并自主执行的微型工作流。
移交使得执行流中智能体之间的转换成为可能。
关键模式: 当智能体遇到其专业领域之外的任务时,它会移交给更合适的智能体。
示例:
# 分诊智能体决定使用哪个专家
if task.type == "refund":
handoff_to(refund_agent)
elif task.type == "sales":
handoff_to(sales_agent)
使用场景: 将请求路由到专门的子智能体
结构:
用户请求 → 分诊智能体 → [确定类别] → 专家智能体
示例实现:
# 具有移交能力的分诊智能体
triage_agent = Agent(
name="Customer Service Triage",
instructions="分析客户请求并路由到适当的专家",
functions=[analyze_request],
handoffs=[refund_agent, sales_agent, support_agent]
)
何时使用:
使用场景: 每个步骤都有专家的多步骤工作流
结构:
步骤 1 智能体 → [完成] → 移交 → 步骤 2 智能体 → ... → 最终智能体
示例:
# 研究 → 分析 → 报告生成流水线
research_agent → analysis_agent → report_agent
何时使用:
使用场景: 将复杂任务分解为并行子任务
结构:
协调器智能体
↓
├─→ 子任务智能体 1
├─→ 子任务智能体 2
└─→ 子任务智能体 3
↓
合成智能体(合并结果)
何时使用:
应该: ✅ 保持智能体专注于单一职责 ✅ 在系统提示中提供清晰、具体的指令 ✅ 定义明确的移交条件 ✅ 使用描述性的智能体名称(有助于调试) ✅ 在集成前单独测试智能体
不应该: ❌ 创建庞大的“无所不能”的智能体 ❌ 允许智能体直接通信(使用移交) ❌ 过度设计,使用过多专门的智能体 ❌ 忽略移交中的错误处理 ❌ 跳过智能体边界测试
有效的例程:
示例:
routine = {
"name": "Process Refund",
"entry": "User requests refund",
"steps": [
"Verify order exists",
"Check refund eligibility",
"Calculate refund amount",
"Process payment reversal",
"Send confirmation"
],
"exit": "Refund confirmed or rejection reason provided",
"error_handling": "Escalate to human agent if verification fails"
}
关键要素:
示例:
def handoff_condition(state):
"""确定是否需要移交"""
if state.requires_specialized_knowledge:
return specialist_agent
if state.exceeds_authority_level:
return supervisor_agent
return None # 继续使用当前智能体
原则: 限制 LLM 参与并依赖预定义或直接执行流的框架运行效率更高。
策略:
原则: 只给智能体提供其专业领域所需的工具。
模式:
# 专门的智能体获得有针对性的工具集
refund_agent.tools = [verify_order, calculate_refund, process_payment]
sales_agent.tools = [check_inventory, create_quote, process_order]
# 不要:两个智能体都获得所有 6 个工具
问题: 简单任务使用过多智能体会产生开销
解决方案: 从简单开始,仅在复杂性需要时才添加智能体
问题: 智能体 A → 智能体 B → 智能体 A 形成循环
解决方案: 设计清晰的层次结构或基于状态的终止条件
问题: 智能体在移交过程中丢失上下文
解决方案: 实现适当的状态管理和上下文传递
问题: 智能体职责重叠导致冲突
解决方案: 定义明确的智能体领域和决策标准
智能体级别:
系统级别:
单元测试:
# 测试单个智能体行为
def test_refund_agent():
result = refund_agent.process(valid_refund_request)
assert result.status == "approved"
assert result.amount > 0
集成测试:
# 测试智能体移交
def test_triage_to_refund():
initial_state = {"request": "I want a refund"}
final_state = orchestrator.run(initial_state)
assert final_state.handling_agent == "refund_agent"
assert final_state.completed == True
端到端测试:
# 测试完整的用户旅程
def test_customer_journey():
scenarios = load_test_scenarios()
for scenario in scenarios:
result = system.execute(scenario)
assert result.meets_requirements()
必要的可观测性:
工具:
智能体安全:
数据保护:
水平扩展:
垂直优化:
from openai import OpenAI
client = OpenAI()
# 定义专门的智能体
support_agent = {
"name": "Technical Support Agent",
"model": "gpt-4o",
"instructions": """You are a technical support specialist.
Help users troubleshoot technical issues.
If issue requires refund, hand off to refund agent.
If issue is sales-related, hand off to sales agent.""",
"tools": [
{"type": "function", "function": troubleshooting_guide},
{"type": "function", "function": escalate_to_human}
]
}
def execute_agent_workflow(initial_request):
current_agent = triage_agent
context = {"request": initial_request, "history": []}
while not is_complete(context):
# 执行当前智能体
response = client.chat.completions.create(
model=current_agent.model,
messages=build_messages(context, current_agent),
tools=current_agent.tools
)
# 检查是否需要移交
next_agent = determine_handoff(response)
if next_agent:
context["history"].append({
"from": current_agent.name,
"to": next_agent.name
})
current_agent = next_agent
else:
context["result"] = response
break
return context
使用 AgentKit 处理基于 OpenAI 的工作流,使用 Claude SDK 处理基于 Anthropic 的工作流,并使用 MCP 将数据源桥接到两者。
LangGraph 提供更细粒度的控制流。对简单工作流使用 AgentKit,对复杂状态机使用 LangGraph。
AgentKit 智能体可以将 MCP 服务器作为工具使用,从而标准化数据源连接。
关键变更:
swarm.run() 替换为 Agents SDK 编排时间线: Swarm 仅处于维护状态。在 2025 年第二季度前迁移所有生产代码。
在以下情况下使用 OpenAI AgentKit:
在以下情况下考虑替代方案:
官方文档:
社区:
本技能确保您使用 OpenAI 在 2025 年的最新平台能力构建稳健、可扩展、生产就绪的多智能体系统。
每周安装次数
–
代码仓库
GitHub 星标数
5
首次出现时间
–
安全审计
This skill provides comprehensive guidance on building production-ready multi-agent systems using OpenAI's AgentKit platform and Agents SDK, following 2025 best practices.
Complete platform for building, deploying, and optimizing agents with enterprise-grade tooling.
Core Components:
The Agents SDK is the production evolution of the experimental Swarm framework. Use Agents SDK for all production work - Swarm is educational only.
Migration Note: If you encounter legacy Swarm code, migrate to Agents SDK immediately.
An Agent encapsulates:
Design Principle: Agents should be lightweight and specialized rather than monolithic and general-purpose.
A routine is a sequence of actions an agent can perform:
Think of it as: A mini-workflow that an agent owns and executes autonomously.
Handoffs enable agent-to-agent transitions in execution flow.
Key Pattern: When an agent encounters a task outside its specialization, it hands off to a more appropriate agent.
Example:
# Triage agent determines which specialist to use
if task.type == "refund":
handoff_to(refund_agent)
elif task.type == "sales":
handoff_to(sales_agent)
Use Case: Routing requests to specialized sub-agents
Structure:
User Request → Triage Agent → [Determines Category] → Specialist Agent
Example Implementation:
# Triage agent with handoff capabilities
triage_agent = Agent(
name="Customer Service Triage",
instructions="Analyze customer requests and route to appropriate specialist",
functions=[analyze_request],
handoffs=[refund_agent, sales_agent, support_agent]
)
When to Use:
Use Case: Multi-step workflows where each step has a specialist
Structure:
Step 1 Agent → [Complete] → Handoff → Step 2 Agent → ... → Final Agent
Example:
# Research → Analysis → Report Generation pipeline
research_agent → analysis_agent → report_agent
When to Use:
Use Case: Breaking complex tasks into parallel subtasks
Structure:
Coordinator Agent
↓
├─→ Subtask Agent 1
├─→ Subtask Agent 2
└─→ Subtask Agent 3
↓
Synthesis Agent (combines results)
When to Use:
DO: ✅ Keep agents focused on single responsibilities ✅ Provide clear, specific instructions in system prompts ✅ Define explicit handoff conditions ✅ Use descriptive agent names (helps with debugging) ✅ Test agents in isolation before integration
DON'T: ❌ Create monolithic "do-everything" agents ❌ Allow agents to communicate directly (use handoffs) ❌ Over-engineer with too many specialized agents ❌ Ignore error handling in handoffs ❌ Skip agent boundary testing
Effective Routines:
Example:
routine = {
"name": "Process Refund",
"entry": "User requests refund",
"steps": [
"Verify order exists",
"Check refund eligibility",
"Calculate refund amount",
"Process payment reversal",
"Send confirmation"
],
"exit": "Refund confirmed or rejection reason provided",
"error_handling": "Escalate to human agent if verification fails"
}
Critical Elements:
Example:
def handoff_condition(state):
"""Determine if handoff needed"""
if state.requires_specialized_knowledge:
return specialist_agent
if state.exceeds_authority_level:
return supervisor_agent
return None # Continue with current agent
Principle: Frameworks that limit LLM involvement and rely on predefined or direct execution flows operate more efficiently.
Strategies:
Principle: Give agents only the tools they need for their specialty.
Pattern:
# Specialized agents get targeted toolsets
refund_agent.tools = [verify_order, calculate_refund, process_payment]
sales_agent.tools = [check_inventory, create_quote, process_order]
# NOT: both agents get all 6 tools
Problem: Too many agents for simple tasks creates overhead
Solution: Start simple, add agents only when complexity demands it
Problem: Agent A → Agent B → Agent A creates loops
Solution: Design clear hierarchy or state-based termination
Problem: Agents lose context across handoffs
Solution: Implement proper state management and context passing
Problem: Overlapping agent responsibilities cause conflicts
Solution: Define explicit agent domains and decision criteria
Agent-Level:
System-Level:
Unit Testing:
# Test individual agent behaviors
def test_refund_agent():
result = refund_agent.process(valid_refund_request)
assert result.status == "approved"
assert result.amount > 0
Integration Testing:
# Test agent handoffs
def test_triage_to_refund():
initial_state = {"request": "I want a refund"}
final_state = orchestrator.run(initial_state)
assert final_state.handling_agent == "refund_agent"
assert final_state.completed == True
End-to-End Testing:
# Test full user journeys
def test_customer_journey():
scenarios = load_test_scenarios()
for scenario in scenarios:
result = system.execute(scenario)
assert result.meets_requirements()
Essential Observability:
Tools:
Agent Security:
Data Protection:
Horizontal Scaling:
Vertical Optimization:
from openai import OpenAI
client = OpenAI()
# Define specialized agent
support_agent = {
"name": "Technical Support Agent",
"model": "gpt-4o",
"instructions": """You are a technical support specialist.
Help users troubleshoot technical issues.
If issue requires refund, hand off to refund agent.
If issue is sales-related, hand off to sales agent.""",
"tools": [
{"type": "function", "function": troubleshooting_guide},
{"type": "function", "function": escalate_to_human}
]
}
def execute_agent_workflow(initial_request):
current_agent = triage_agent
context = {"request": initial_request, "history": []}
while not is_complete(context):
# Execute current agent
response = client.chat.completions.create(
model=current_agent.model,
messages=build_messages(context, current_agent),
tools=current_agent.tools
)
# Check for handoff
next_agent = determine_handoff(response)
if next_agent:
context["history"].append({
"from": current_agent.name,
"to": next_agent.name
})
current_agent = next_agent
else:
context["result"] = response
break
return context
Use AgentKit for OpenAI-based workflows, Claude SDK for Anthropic-based workflows, and MCP to bridge data sources to both.
LangGraph provides more fine-grained control flow. Use AgentKit for simpler workflows, LangGraph for complex state machines.
AgentKit agents can consume MCP servers as tools, standardizing data source connections.
Key Changes:
swarm.run() with Agents SDK orchestrationTimeline: Swarm is maintenance-only. Migrate all production code by Q2 2025.
Use OpenAI AgentKit when:
Consider alternatives when:
Official Documentation:
Community:
This skill ensures you build robust, scalable, production-ready multi-agent systems using OpenAI's latest platform capabilities in 2025.
Weekly Installs
–
Repository
GitHub Stars
5
First Seen
–
Security Audits
AI Elements:基于shadcn/ui的AI原生应用组件库,快速构建对话界面
60,400 周安装