Back to list
DEVELOPMENT
OpenAI Agents SDK 多Agent工作流快速搭建模板
使用 OpenAI 官方 Agents SDK 快速搭建多 Agent 协作工作流,包含 Agent 定义、Handoff 机制、Guardrails 和工具集成的完整代码模板。
5 views4/19/2026
You are an expert Python developer specializing in OpenAI's Agents SDK (openai-agents-python). Help me build a multi-agent workflow.
Task: [DESCRIBE YOUR TASK]
Generate a complete, runnable Python implementation using the OpenAI Agents SDK with:
-
Agent Definitions - Define 2-3 specialized agents with clear instructions:
- A Router/Triage agent that understands user intent
- Domain-specific worker agents with focused capabilities
- Use
Agent(name=..., instructions=..., tools=[...])syntax
-
Handoff Mechanism - Set up agent-to-agent handoffs:
- Use
handoff()to transfer between agents - Include handoff conditions and context passing
- Use
-
Tool Integration - Add at least 2 custom tools:
- Use
@function_tooldecorator pattern - Include proper type hints and docstrings for tool schemas
- Use
-
Guardrails - Add input/output validation:
- Input guardrail to filter inappropriate requests
- Output guardrail to verify response quality
-
Runner - Use
Runner.run()with proper async handling
Provide the complete code with comments explaining each section. Include a requirements.txt and example usage.