code/chapter6/AutoGenDemo/README.md
本目录包含第六章 AutoGen 框架的完整实战案例,展示了如何使用 AutoGen 构建多智能体协作的软件开发团队。
autogen_software_team.py - 主要案例代码(基于 OpenAI 客户端)llm_client.py - HelloAgentsLLM 客户端实现requirements.txt - 依赖包列表output.py - 团队协作生成的比特币价格应用示例README.md - 本说明文档pip install -r requirements.txt
创建 .env 文件并配置以下参数:
# LLM 配置
LLM_API_KEY=your-api-key-here
LLM_BASE_URL=https://api.openai.com/v1
LLM_MODEL_ID=gpt-4
确保可以正常调用 LLM API:
import os
from dotenv import load_dotenv
load_dotenv()
print(f"API Key: {os.getenv('LLM_API_KEY')[:10]}...")
print(f"Base URL: {os.getenv('LLM_BASE_URL')}")
print(f"Model: {os.getenv('LLM_MODEL_ID')}")
python autogen_software_team.py
streamlit run output.py
可以通过修改 system_message 来自定义智能体的行为:
def create_product_manager(model_client):
system_message = """
你是一位经验丰富的产品经理...
# 在这里自定义角色描述
"""
return AssistantAgent(
name="ProductManager",
model_client=model_client,
system_message=system_message,
)
可以修改参与者列表和终止条件:
team_chat = RoundRobinGroupChat(
participants=[
product_manager,
engineer,
code_reviewer,
user_proxy
],
termination_condition=TextMentionTermination("TERMINATE"),
max_turns=20, # 调整最大轮次
)
A: 检查以下几点:
A: 可能原因:
A: 建议:
欢迎提交 Issue 和 Pull Request 来改进这个案例:
本案例是 Hello-Agents 教程的一部分,更多内容请参考项目主页。