核心概念

安装Conda环境
Anaconda官网下载,Anaconda的完整版或者MiniConda均可
bash
# 创建Conda环境
conda create -n openagents python=3.12
# 激活conda环境
conda activate openagents
# 安装UV管理
pip install uvicorn
# 安装openagents
uv pip install -U openagents
获取项目
bash
git clone https://github.com/openagents-org/openagents.git
cd openagents
# openagents studio -s前, 需要先构建studio项目
cd studio
npm install
npm run build
创建网络
bash
# 创建网络
openagents network init ./my_first_network
# 启动网络
openagents network start ./my_first_network
# 启动网络可视化
openagents studio -s
Agent连接到网络
前置设置及问题
1、密钥设置及问题,Windows/Mac/Linux
bash
# Windows
# Must: set deepseek_api_key
$env:DEEPSEEK_API_KEY="your-key-here"
# Mac/Linux设置命令
# Optional: Set the OpenAI base URL
export OPENAI_BASE_URL="your-base-url-here"
# Must: Set the OpenAI API key
export OPENAI_API_KEY="your-key-here"
2、Windows关于编码问题,运行会报错:
bash
openagents\Lib\logging\__init__.py", line 1163, in emit
stream.write(msg + self.terminator)
UnicodeEncodeError: 'gbk' codec can't encode character '\U0001f527' in position 0: illegal multibyte sequence
解决方案:将系统编码改为UTF-8,再重启电脑。重新尝试。
- 按下【Win】键,输入"设置"并打开。
- 在设置窗口中,点击"时间和语言"。
- 在"时间和语言"设置中,点击"语言"菜单项。
- 在"语言"设置中,点击"管理语言设置"。
- 在"区域"窗口中,选择"管理"选项卡。
- 点击"更改系统区域设置"按钮。
- 在"区域设置"对话框中,勾选"Beta 版:使用Unicode UTF-8提供全球语言支持(U)"复选框。
- 点击"确定"按钮保存更改。
基于YAML的Agents
bash
# 激活conda环境
conda activate openagents
# 启动Agent
openagents agent start ./my_first_network/agents/charlie.yaml
基于Python的Agents
bash
# 激活conda环境
conda activate openagents
# llm的Agent
python ./my_first_network/agents/llm_agent.py
# 无llm的Agents
python ./my_first_network/agents/simple_agent.py
OpenAgents Demo
00_hello_world: 一个客服回复消息
bash
# 激活conda环境
conda activate openagents
# 启动网络, HTTP: 8700 , gRPC: 8600
openagents network start demos/00_hello_world/
# 启动代理
openagents agent start demos/00_hello_world/agents/charlie.yaml
# 连接Studio, 导航到http://localhost:8050 并连接到 localhost:8700
openagents studio -s
01_startup_pitch_room: 与创始人、工程师和投资者的多代理角色扮演
- founder: 远见企业家角色
- engineer: 技术联合创始人角色
- investor: 投资者角色
bash
# 激活conda环境
conda activate openagents
# 启动网络
openagents network start demos/01_startup_pitch_room
# 启动创始人角色
openagents agent start demos/01_startup_pitch_room/agents/founder.yaml
# 启动工程师代理
openagents agent start demos/01_startup_pitch_room/agents/engineer.yaml
# 启动投资者代理
openagents agent start demos/01_startup_pitch_room/agents/investor.yaml
# 启动Studio
openagents studio -s
02_tech_news_stream: HackNews与Python WorkAgent集成
- news-hunter: 新闻猎人角色
- commentator: 解说员
bash
# 激活conda环境
conda activate openagents
# 启动网络
openagents network start demos/02_tech_news_stream/
# 启动新闻猎人代理
python demos/02_tech_news_stream/agents/news_hunter.py
python demos/02_tech_news_stream/agents/news_hunter.py --interval 120 --host localhost --port 8700
# 启动解说员代理
openagents agent start demos/02_tech_news_stream/agents/commentator.yaml
03_research_team: 基于路由器的任务委派,使用项目模组
- router: 协调员角色,接受请求、委派任务、汇总结果
- web-searcher: 信息收集者角色,网络搜索,黑客新闻查询
- analyst: 合成器,分析与结论
bash
# 激活conda环境
conda activate openagents
# Windows
# Must: set deepseek_api_key
$env:OPENAI_API_KEY="your-key-here"
$env:OPENAI_BASE_URL="your-base-url-here"
$env:BRAVE_API_KEY="your-key-here"
# Mac/Linux设置命令
# LLM API KEY
export OPENAI_API_KEY="your-key-here"
export OPENAI_BASE_URL="your-base-url-here"
# BRAVE API KEY
export BRAVE_API_KEY="your-key-here"
# 启动网络
openagents network start demos/03_research_team/
# 启动路由器
openagents agent start demos/03_research_team/agents/router.yaml
# 启动网络搜索器
openagents agent start demos/03_research_team/agents/web_searcher.yaml
# 启动分析师
openagents agent start demos/03_research_team/agents/analyst.yaml
# 启动studio
openagents studio -s
04_grammar_check_forum: 带有自动语法检查功能的论坛
- 语法错误
- 拼写错误
- 标点符号
- 句子结构
- 用词
- 风格建议
bash
# 激活conda环境
conda activate openagents
# Windows
# Must: set deepseek_api_key
$env:OPENAI_API_KEY="your-key-here"
$env:OPENAI_BASE_URL="your-base-url-here"
# Mac/Linux设置命令
# Optional: Set the OpenAI base URL
export OPENAI_BASE_URL="your-base-url-here"
# Must: Set the OpenAI API key
export OPENAI_API_KEY="your-key-here"
# 启动网络
openagents network start demos/04_grammar_check_forum/
# 启动语法检查器
openagents agent start demos/04_grammar_check_forum/agents/grammar_checker.yaml
参考
1️⃣ 教程:5 个 Demo 入门OpenAgents
文档:https://mp.weixin.qq.com/s/RX-JF4rLoLTN_P-R2TWYuA
GitHub:https://github.com/openagents-org/openagents
新手入门教程:https://openagents.org/docs/tutorials/tutorials
OpenAgents 官网:https://openagents.org