PraisonAI:AutoGen 继任者·100+ LLM 支持·MCP 原生
posts posts 2026-04-12T02:31:39+08:00PraisonAI 是 AutoGen 的继任者,支持 100+ LLM 和 MCP 原生,提供多智能体框架功能。技术笔记AI, Agent, LLM, MCP, PythonPraisonAI:AutoGen 继任者,100+ LLM、MCP 原生多智能体框架
PraisonAI 要解决的问题很具体:把模型调用、工具编排、记忆、安全护栏和工作流调度塞进同一套 Python SDK 里,让多 Agent 协作从原型验证跑到生产部署时不换技术栈。
本文从它内部几条并行的主线拆起:四款产品各自负责什么、Agent 核心能力层、MCP 协议层、记忆与知识层、工作流调度层,然后给一个完整的研究任务流案例,最后说清楚什么团队该先用、什么场景可以等等。
一、系统总览:四款产品 + 五层能力
PraisonAI 不是一个单体库,而是四款产品组合。先看清边界,后面才不容易混:
| 产品 | 形态 | 适合谁 |
|---|---|---|
Core SDK (praisonaiagents) | Python 库 | 想把 Agent 嵌入现有项目的开发者 |
CLI (praisonai) | 命令行 | 终端里快速跑任务的用户 |
| Claw Dashboard | Web 面板 | 需要接 Telegram / Slack / Discord 的团队 |
| Flow Visual Builder | 拖拽界面 | 不想写代码、用可视化搭工作流的人 |
| PraisonAI UI | 轻量聊天界面 | 快速交互测试 |
安装方式一一对应:
pip install praisonaiagents # Core SDK
pip install praisonai # CLI
pip install "praisonai[claw]" # Dashboard
pip install "praisonai[flow]" # Flow Builder
pip install "praisonai[ui]" # 聊天 UI在这四款产品之下,PraisonAI 的能力栈分五层:
- Agent 核心 — Single / Multi / Auto / Self-Reflection / Reasoning / Multi-Modal,决定 Agent 怎么思考、怎么分工。
- MCP 协议层 — stdio、HTTP、WebSocket、SSE 四种传输,决定 Agent 怎么接外部工具和数据源。
- 记忆与知识层 — 内置 Memory(零依赖)+ Knowledge(RAG)+ 20+ 数据库持久化,决定 Agent 记住什么、查什么。
- 工作流调度层 — Sequential / Parallel / Loop / Repeat / Route + Planning Mode(plan → execute → reason 循环),决定多个 Agent 怎么排顺序。
- 安全与可观测层 — Guardrails 输入输出验证 + Langfuse 追踪,决定怎么防出错、怎么排查。
后面逐层展开。
二、核心数据
| 指标 | 数值 |
|---|---|
| Stars | 6.9k ⭐ |
| Forks | 1.1k |
| 最新版本 | v4.5.149 (2026-04-11) |
| 提交数 | 3,388 commits |
| 许可证 | MIT |
| 语言 | Python 85.9%, TypeScript 9.7%, Rust 4.1% |
项目被 Elon Musk 在 X 上推荐过。它自称 AutoGen 的继任者——继承了 AutoGen 的多 Agent 对话架构,但在模型适配(100+ LLM)、协议标准化(MCP 原生)和产品化(Dashboard / Flow Builder)上往前走了一大步。
三、一次研究任务如何流过系统
在进入各层细节之前,先看一个具体例子——用户要求“分析 2026 年 AI 领域三大趋势,输出 Markdown 表格”。这条任务在 PraisonAI 里会怎么走:
- 接收与规划:Agent 收到指令,Planning Mode 打开,先拆成三个子任务——搜索、交叉验证、格式化输出。
- 工具调用:Agent 通过 MCP(stdio 模式,连本地 Brave Search 服务器)发起搜索。MCP 层把工具调用的输入输出标准化,不依赖特定 API 格式。
- 多 Agent 协作:research agent 收集原始材料 → summarise agent 提取关键信息 → writer agent 格式化为 Markdown 表格。Agents 容器负责把前一个 Agent 的上下文传递给下一个。
- 自我反思:Self Reflection 打开时,Agent 会检查输出是否与搜索来源一致、有没有遗漏趋势维度,发现问题时自动补搜一轮。
- 记忆落盘:Memory 启用时,这次研究的结果和中间步骤写进记忆库,下次问“上次那三个趋势再展开说说”可以直接召回,不用重新搜索。
- 安全校验:Guardrails 的输出 validator 扫一遍最终文本,如果触发了敏感词规则,替换为
[FILTERED],然后才返回用户。
这条链路串起了 Planning、MCP、多 Agent 协作、Self Reflection、Memory 和 Guardrails 六个模块。下面分别展开每个模块的用法。
四、快速开始
# 核心 SDK
pip install praisonaiagents
# 或者完整安装
pip install praisonai
# 设置 API Key
export OPENAI_API_KEY="your-api-key"4.1 单 Agent 模式
from praisonaiagents import Agent
agent = Agent(instructions="You are a senior data analyst.")
agent.start("Analyze the top 3 tech trends of 2026 and format as a markdown table.")4.2 多 Agent 模式
from praisonaiagents import Agent, Agents
research_agent = Agent(instructions="Research about AI")
summarise_agent = Agent(instructions="Summarise research agent's findings")
agents = Agents(agents=[research_agent, summarise_agent])
agents.start()五、Agent 核心能力
5.1 Agent 类型
| 类型 | 用途 |
|---|---|
| Single Agent | 单 Agent 处理简单查询 |
| Multi Agents | 多 Agent 协作,前一个输出是后一个输入 |
| Auto Agents | 框架自动选择最优 Agent |
| Self Reflection | 输出后自我检查并修正 |
| Reasoning | 显式推理链路 |
| Multi-Modal | 图像等多模态输入 |
5.2 代码示例
单 Agent:
from praisonaiagents import Agent
agent = Agent(instructions="You are a helpful AI assistant")
agent.start("Write a movie script about a robot in Mars")多 Agent 协作:
from praisonaiagents import Agent, Agents
research_agent = Agent(instructions="Research about AI trends")
writer_agent = Agent(instructions="Write engaging content based on research")
research_team = Agents(agents=[research_agent, writer_agent])
research_team.start()Deep Research(启用后 Agent 自主进行多轮搜索和交叉验证):
from praisonaiagents import Agent
agent = Agent(
instructions="You are a research analyst",
deep_research=True
)
agent.start("Research the impact of AI on healthcare in 2026")5.3 Planning Mode(计划模式)
Agent 进入 plan → execute → reason 循环,适合多步骤任务:
from praisonaiagents import Agent
agent = Agent(
instructions="You are a planning assistant",
planning=True
)
agent.start("Plan a product launch for our new AI product")CLI 中也可以启用:
praisonai --planning
praisonai --planning-tools
praisonai --planning-reasoningPlanning Mode 的价值在于:它把“大任务拆小步骤”这一步从 prompt 里拎出来做成显式循环,每一步执行完再决定下一步,而不是让模型一口气生成全量计划然后硬执行。
六、MCP 协议支持
PraisonAI 对 MCP(Model Context Protocol)的支持不是挂个插件,而是四种传输方式全部原生支持:
| 传输方式 | 适用场景 | 示例 |
|---|---|---|
| stdio | 本地 NPX / Python MCP 服务器 | 开发测试 |
| HTTP | 生产服务器 | Streamable HTTP |
| WebSocket | 需要实时双向通信 | 实时应用 |
| SSE | 服务端推送 | 轻量级实时 |
from praisonaiagents import Agent, MCP
# stdio - 本地 NPX 服务器
agent = Agent(tools=MCP("npx @modelcontextprotocol/server-memory"))
# Streamable HTTP - 生产服务器
agent = Agent(tools=MCP("https://api.example.com/mcp"))
# WebSocket - 实时双向
agent = Agent(tools=MCP("wss://api.example.com/mcp", auth_token="token"))
# 带环境变量
agent = Agent(
tools=MCP(
command="npx",
args=["-y", "@modelcontextprotocol/server-brave-search"],
env={"BRAVE_API_KEY": "your-key"}
)
)四种传输方式的并存意味着同一套 Agent 代码可以在本地开发时用 stdio 连本地 MCP 服务器,上线时切到 HTTP,不需要改 Agent 逻辑。
七、工具系统
7.1 自定义工具
用 @tool 装饰器注册函数为 Agent 可调用工具:
from praisonaiagents import Agent, tool
@tool
def search(query: str) -> str:
"""Search the web for information."""
return f"Results for: {query}"
@tool
def calculate(expression: str) -> float:
"""Evaluate a math expression."""
return eval(expression)
agent = Agent(
instructions="You are a helpful assistant",
tools=[search, calculate]
)
agent.start("Search for AI news and calculate 15*4")7.2 内置工具
框架自带 100+ 工具,覆盖 Web Search、文件读写、HTTP 请求、数据库连接等常见场景,不需要从零写。
八、记忆与知识系统
8.1 Memory(记忆)
memory=True 打开后,Agent 自动保存对话上下文,下次对话可直接召回:
from praisonaiagents import Agent
agent = Agent(
name="Assistant",
memory=True
)
agent.chat("Hello!") # 自动保存
agent.chat("What did I say earlier?") # 回忆8.2 Knowledge(知识库)
CLI 管理知识库,适合把项目文档、API 手册等静态资料喂给 Agent:
praisonai knowledge add ./docs
praisonai knowledge query "How to use the API"
praisonai knowledge list8.3 数据库持久化
Memory 默认存本地,也可以接到外部数据库,消息、运行记录、追踪数据自动落库:
from praisonaiagents import Agent, db
agent = Agent(
name="Assistant",
db=db(database_url="postgresql://localhost/mydb"),
session_id="my-session"
)
agent.chat("Hello!")支持 PostgreSQL、MySQL、SQLite、MongoDB、Redis 等 20+ 数据库。
九、工作流模式
9.1 五种模式
| 模式 | 行为 |
|---|---|
| Sequential | 按顺序一个接一个 |
| Parallel | 同时跑多个 Agent |
| Loop | 满足条件前一直循环 |
| Repeat | 固定次数重复 |
| Route | 按条件分流到不同 Agent |
9.2 YAML 工作流
不想写代码时用 YAML 声明:
framework: praisonai
topic: "Write a blog post about AI"
agents:
researcher:
role: Research Analyst
goal: Research AI trends and gather information
instructions: "Find accurate information about AI trends"
writer:
role: Content Writer
goal: Write engaging blog posts
instructions: "Write clear, engaging content based on research"praisonai agents.yaml十、安全护栏(Guardrails)
输入输出各挂一个 validator,在 Agent 收到指令前和返回结果前各拦截一次:
from praisonaiagents import Agent, Guardrails
guardrails = Guardrails(
input_validator=lambda x: x if len(x) < 1000 else x[:1000],
output_validator=lambda x: x if "safe" in x.lower() else "[FILTERED]"
)
agent = Agent(
instructions="You are a helpful assistant",
guardrails=guardrails
)输入 validator 截断超长输入防止 prompt 注入撑爆上下文;输出 validator 检查敏感词。两个 validator 都是纯函数,可以换成自己的规则。
十一、支持的模型
24+ 提供商,通过 model 参数切换,不需要改 Agent 逻辑:
| 提供商 | 示例模型 |
|---|---|
| OpenAI | gpt-4 |
| Anthropic | claude-3-5-sonnet-20241022 |
| Google Gemini | gemini-pro |
| DeepSeek | DeepSeek V3 |
| Azure | Azure OpenAI |
| Ollama | ollama/llama3(本地) |
| Groq | 高速推理 |
| Mistral | Mistral Large |
| Cerebras | 超快速推理 |
| Cohere | Command R+ |
| OpenRouter | 统一 API |
| Perplexity | Sonar |
| Fireworks | 高性能 |
| AWS Bedrock | Claude on AWS |
| xAI Grok | Grok 系列 |
| Vertex AI | Google Cloud |
| HuggingFace | 开源模型 |
| Together AI | 聚合平台 |
| Databricks | 端到端平台 |
| Replicate | 开源模型托管 |
| Cloudflare | Workers AI |
from praisonaiagents import Agent
agent = Agent(model="gpt-4", instructions="...")
agent = Agent(model="claude-3-5-sonnet-20241022", instructions="...")
agent = Agent(model="gemini-pro", instructions="...")
agent = Agent(model="ollama/llama3", instructions="...")十二、CLI 常用命令
运行模式
| 命令 | 说明 |
|---|---|
praisonai | 默认运行 |
praisonai --auto | 自动选择 Agent |
praisonai --interactive | 交互模式 |
praisonai --chat | 聊天模式 |
研究与记忆
| 命令 | 说明 |
|---|---|
praisonai research | 研究模式 |
praisonai --deep-research | 深度研究 |
praisonai memory show | 显示记忆 |
praisonai memory add | 添加记忆 |
praisonai memory search | 搜索记忆 |
praisonai memory clear | 清除记忆 |
MCP 与工具
| 命令 | 说明 |
|---|---|
praisonai mcp list | 列出 MCP 服务器 |
praisonai mcp create | 创建 MCP 服务器 |
praisonai tools list | 列出工具 |
praisonai tools search | 搜索工具 |
praisonai schedule start | 启动定时调度 |
praisonai workflow run | 运行工作流 |
十三、应用场景
| 场景 | 典型用法 |
|---|---|
| 研究与分析 | deep_research=True,多轮搜索 + 交叉验证 |
| 代码生成 | 配 file_read / file_write / code_execute 工具 |
| 内容创作 | 多 Agent:research → write → review |
| 数据管道 | 结合自定义工具做 ETL |
| 客服 | memory=True + 知识库,24/7 |
| 工作流自动化 | YAML 声明 + Cron 定时 |
研究助手示例:
from praisonaiagents import Agent
researcher = Agent(
instructions="You are a research analyst. Research the top 3 AI trends of 2026.",
deep_research=True
)
researcher.start()客服示例:
from praisonaiagents import Agent
support = Agent(
instructions="You are a helpful customer support agent.",
memory=True,
tools=["web_search", "knowledge_base"]
)
support.start()代码生成:
from praisonaiagents import Agent
coder = Agent(
instructions="You are an expert Python developer.",
tools=["file_read", "file_write", "code_execute"]
)
coder.start("Write a web scraper for news articles")十四、性能基准
官方给出的数据是:
| 指标 | 数值 |
|---|---|
| 平均实例化时间 | 3.77 μs |
| 吞吐量 | 高并发支持 |
| 内存占用 | 极低 |
这组数字说明什么、不说明什么:
- 实例化时间 3.77 μs 测的是
Agent()对象的创建开销,反映 SDK 本身的轻量程度。它不包含模型 API 调用延迟——实际端到端响应时间取决于你选的模型和网络。 - 吞吐量 官方写“高并发支持”但没给出具体 QPS 或并发数,说明这组 benchmark 主要定位是 SDK 开销参考,不是生产压测报告。
- 内存占用“极低” 同样缺少量化——如果你挂了 20+ 数据库连接和 Langfuse 追踪,内存消耗会明显上升。
实际使用中,性能瓶颈大概率在模型 API 响应时间和你接的 MCP 服务器的处理速度上,PraisonAI SDK 本身不是瓶颈。
启用 Langfuse 追踪可以看到端到端链路:
pip install "praisonai[langfuse]"
praisonai langfuse十五、部署选项
Python SDK
pip install praisonaiagents
export OPENAI_API_KEY="your-key"
export ANTHROPIC_API_KEY="your-key"Docker
docker build -t praisonai .
docker run -p 8082:8082 praisonaiKubernetes
apiVersion: apps/v1
kind: Deployment
metadata:
name: praisonai
spec:
replicas: 3
template:
spec:
containers:
- name: praisonai
image: praisonai:latest
ports:
- containerPort: 8082十六、开发指南
git clone https://github.com/MervinPraison/PraisonAI.git
cd PraisonAI
pip install -e ".[dev]"
pytest
ruff format .
ruff check .贡献流程:
git checkout -b feature/new-feature
git commit -m "feat: add new feature"
git push origin feature/new-feature
# 创建 PR十七、实践建议
Agent 设计
- 指令写清楚角色和目标,不要让 Agent 猜自己该干什么。
- 工具只给必要的——太多工具会分散模型注意力,太少则完不成任务。
- Memory 按需开:对话型任务打开,一次性脚本关掉更干净。
- Guardrails 的 validator 用纯函数,尽量不依赖外部调用,避免引入新的失败点。
性能
- 模型越强越慢也越贵——简单任务用
ollama/llama3或 Groq,复杂推理再上 GPT-4。 - 独立子任务用 Parallel 模式并行跑,不要串行排队。
- 重复查询开 Memory 避免反复调用模型。
- 需要流式反馈时用 SSE 传输,比轮询省资源。
十八、FAQ
Q: ModuleNotFoundError: No module named ‘praisonaiagents’
pip install praisonaiagentsQ: API key not found / Authentication error
export OPENAI_API_KEY="your-api-key"Q: 如何使用本地模型 (Ollama)?
agent = Agent(model="ollama/llama3", instructions="...")Q: 如何持久化对话?
agent = Agent(db=db(database_url="postgresql://localhost/mydb"))获取帮助
| 资源 | 链接 |
|---|---|
| 文档 | https://docs.praison.ai |
| Issues | https://github.com/MervinPraison/PraisonAI/issues |
| Discussions | https://github.com/MervinPraison/PraisonAI/discussions |
十九、什么时候用 PraisonAI
PraisonAI 最合适的场景是:你需要多 Agent 协作、接外部工具(MCP)、并且希望一套 SDK 从原型跑到部署。具体来说:
优先考虑的场景:
- 研究类任务,需要搜索 → 交叉验证 → 格式化输出的多步流水线。
- 已经有 MCP 服务器或打算用 MCP 标准化工具接入。
- 团队需要 Dashboard 把 Agent 接到 Telegram / Slack / Discord,而不是自己写 Bot 框架。
- 想用 YAML 声明工作流 + 可视化拖拽,降低非开发同事的参与门槛。
可以等等的场景:
- 只跑单 Agent 简单问答——用 OpenAI SDK 或 LangChain 更轻量,PraisonAI 的 Planning / Multi-Agent / MCP 层在这里是额外复杂度。
- 对模型推理延迟极度敏感的场景——PraisonAI 的 Planning 循环会增加往返次数,如果每个毫秒都关键,直接调模型 API 更可控。
- 团队已经深度绑定了另一个 Agent 框架(如 CrewAI 或 LangGraph),迁移成本需要单独评估。
从哪里开始:
pip install praisonaiagents,用单 Agent 模式跑通第一个任务。- 打开
memory=True和planning=True,感受多步推理和记忆召回的效果。 - 接一个 MCP 服务器(比如 Brave Search),让 Agent 真正调用外部工具。
- 上多 Agent 协作,用
Agents容器串联两个 Agent。 - 需要对外暴露时,上 Claw Dashboard 或部署到 K8s。
相关资源:
| 资源 | 链接 |
|---|---|
| GitHub | https://github.com/MervinPraison/PraisonAI |
| 文档 | https://docs.praison.ai |
| Dashboard | http://localhost:8082 |
| YouTube | 22 个视频教程 |
| Elon Musk 推荐 | https://x.com/elonmusk/status/1893870468249141688 |
本文基于 PraisonAI v4.5.149(6.9k Stars)撰写