演示了高级编排模式,其中专业化的智能体被编排智能体用作函数工具。
安装OpenAI智能体SDK:
pip install openai-agents
设置环境:
cp ../env.example .env # Edit .env and add your OpenAI API key
运行智能体:
import asyncio from agent import main # Test agent orchestration patterns asyncio.run(main())
@function_tool with Runner.run()@function_tool async def research_tool(topic: str) -> str: result = await Runner.run( research_agent, input=f"Research this topic thoroughly: {topic}", max_turns=3 ) return str(result.final_output)
@function_tool async def writing_tool(content: str, style: str = "professional") -> str: prompt = f"Write engaging {style} content based on this research: {content}" result = await Runner.run(writing_agent, input=prompt, max_turns=2) return str(result.final_output)
@function_tool async def editing_tool(content: str) -> str: result = await Runner.run( editing_agent, input=f"Edit and improve this content: {content}" ) return str(result.final_output)
免责声明:
本文档采用基于机器的 AI 翻译服务进行翻译。尽管我们力求准确,但请注意,自动翻译可能存在错误或不准确之处。应以原文语言版本的文档作为权威依据。如需获取关键信息,建议使用专业的人工翻译。对于因使用本翻译而产生的任何误解或误读,我们概不负责。