Praisonai
工具列表
內容詳情
替代品
安裝
複製以下命令到你的Client進行配置
注意:您的密鑰屬於敏感信息,請勿與任何人分享。
🚀 Praison AI
Praison AI 是一個可用於生產環境的多 AI 智能體框架,具備自我反思能力。它旨在創建 AI 智能體,以自動化方式解決從簡單任務到複雜挑戰的各類問題。通過將 PraisonAI 智能體、AG2(前身為 AutoGen)和 CrewAI 集成到低代碼解決方案中,它簡化了多智能體大語言模型系統的構建和管理,強調簡單性、可定製性以及有效的人機協作。
🚀 快速開始
在不到 1 分鐘的時間內開始使用 PraisonAI:
# 安裝
pip install praisonaiagents
# 設置 API 密鑰
export OPENAI_API_KEY=your_key_here
# 創建一個簡單的智能體
python -c "from praisonaiagents import Agent; Agent(instructions='You are a helpful AI assistant').start('Write a haiku about AI')"
✨ 主要特性
🤖 核心智能體
| 特性 | 代碼示例 | 文檔 |
|---|---|---|
| 單智能體 | 示例 | 📖 |
| 多智能體 | 示例 | 📖 |
| 自動智能體 | 示例 | 📖 |
| 自我反思 AI 智能體 | 示例 | 📖 |
| 推理 AI 智能體 | 示例 | 📖 |
| 多模態 AI 智能體 | 示例 | 📖 |
🔄 工作流
| 特性 | 代碼示例 | 文檔 |
|---|---|---|
| 簡單工作流 | 示例 | 📖 |
| 帶智能體的工作流 | 示例 | 📖 |
智能體路由 (route()) |
示例 | 📖 |
並行執行 (parallel()) |
示例 | 📖 |
列表/CSV 循環 (loop()) |
示例 | 📖 |
評估器 - 優化器 (repeat()) |
示例 | 📖 |
| 條件步驟 | 示例 | 📖 |
| 工作流分支 | 示例 | 📖 |
| 工作流提前停止 | 示例 | 📖 |
| 工作流檢查點 | 示例 | 📖 |
💻 代碼與開發
| 特性 | 代碼示例 | 文檔 |
|---|---|---|
| 代碼解釋器智能體 | 示例 | 📖 |
| AI 代碼編輯工具 | 示例 | 📖 |
| 外部智能體 (全部) | 示例 | 📖 |
| Claude 代碼 CLI | 示例 | 📖 |
| Gemini CLI | 示例 | 📖 |
| Codex CLI | 示例 | 📖 |
| Cursor CLI | 示例 | 📖 |
🧠 記憶與知識
| 特性 | 代碼示例 | 文檔 |
|---|---|---|
| 記憶(短期和長期) | 示例 | 📖 |
| 基於文件的記憶 | 示例 | 📖 |
| Claude 記憶工具 | 示例 | 📖 |
| 添加自定義知識 | 示例 | 📖 |
| RAG 智能體 | 示例 | 📖 |
| 與 PDF 聊天智能體 | 示例 | 📖 |
| 數據讀取器(PDF、DOCX 等) | CLI | 📖 |
| 向量存儲選擇 | CLI | 📖 |
| 檢索策略 | CLI | 📖 |
| 重排器 | CLI | 📖 |
| 索引類型(向量/關鍵字/混合) | CLI | 📖 |
| 查詢引擎(子問題等) | CLI | 📖 |
🔬 研究與情報
| 特性 | 代碼示例 | 文檔 |
|---|---|---|
| 深度研究智能體 | 示例 | 📖 |
| 查詢重寫智能體 | 示例 | 📖 |
| 原生網絡搜索 | 示例 | 📖 |
| 內置搜索工具 | 示例 | 📖 |
| 統一網絡搜索 | 示例 | 📖 |
| 網絡抓取(Anthropic) | 示例 | 📖 |
📋 規劃與執行
| 特性 | 代碼示例 | 文檔 |
|---|---|---|
| 規劃模式 | 示例 | 📖 |
| 規劃工具 | 示例 | 📖 |
| 規劃推理 | 示例 | 📖 |
| 提示鏈 | 示例 | 📖 |
| 評估器優化器 | 示例 | 📖 |
| 編排器工作者 | 示例 | 📖 |
👥 專業智能體
| 特性 | 代碼示例 | 文檔 |
|---|---|---|
| 數據分析智能體 | 示例 | 📖 |
| 金融智能體 | 示例 | 📖 |
| 購物智能體 | 示例 | 📖 |
| 推薦智能體 | 示例 | 📖 |
| 維基百科智能體 | 示例 | 📖 |
| 編程智能體 | 示例 | 📖 |
| 數學智能體 | 示例 | 📖 |
| Markdown 智能體 | 示例 | 📖 |
| 提示擴展智能體 | 示例 | 📖 |
🎨 媒體與多模態
| 特性 | 代碼示例 | 文檔 |
|---|---|---|
| 圖像生成智能體 | 示例 | 📖 |
| 圖像轉文本智能體 | 示例 | 📖 |
| 視頻智能體 | 示例 | 📖 |
| 相機集成 | 示例 | 📖 |
🔌 協議與集成
| 特性 | 代碼示例 | 文檔 |
|---|---|---|
| MCP 傳輸 | 示例 | 📖 |
| WebSocket MCP | 示例 | 📖 |
| MCP 安全 | 示例 | 📖 |
| MCP 可恢復性 | 示例 | 📖 |
| MCP 配置管理 | 示例 | 📖 |
| LangChain 集成智能體 | 示例 | 📖 |
🛡️ 安全與控制
| 特性 | 代碼示例 | 文檔 |
|---|---|---|
| 護欄 | 示例 | 📖 |
| 人工批准 | 示例 | 📖 |
| 規則與指令 | 示例 | 📖 |
⚙️ 高級特性
| 特性 | 代碼示例 | 文檔 |
|---|---|---|
| 異步與並行處理 | 示例 | 📖 |
| 並行化 | 示例 | 📖 |
| 重複智能體 | 示例 | 📖 |
| 智能體交接 | 示例 | 📖 |
| 有狀態智能體 | 示例 | 📖 |
| 自主工作流 | 示例 | 📖 |
| 結構化輸出智能體 | 示例 | 📖 |
| 模型路由器 | 示例 | 📖 |
| 提示緩存 | 示例 | 📖 |
| 快速上下文 | 示例 | 📖 |
🛠️ 工具與配置
| 特性 | 代碼示例 | 文檔 |
|---|---|---|
| 100+ 自定義工具 | 示例 | 📖 |
| YAML 配置 | 示例 | 📖 |
| 100+ 大語言模型支持 | 示例 | 📖 |
| 回調智能體 | 示例 | 📖 |
| 鉤子 | 示例 | 📖 |
| 中間件系統 | 示例 | 📖 |
| 可配置模型 | 示例 | 📖 |
| 速率限制器 | 示例 | 📖 |
| 注入工具狀態 | 示例 | 📖 |
| 影子 Git 檢查點 | 示例 | 📖 |
| 後臺任務 | 示例 | 📖 |
| 策略引擎 | 示例 | 📖 |
| 思考預算 | 示例 | 📖 |
| 輸出樣式 | 示例 | 📖 |
| 上下文壓縮 | 示例 | 📖 |
📊 監控與管理
| 特性 | 代碼示例 | 文檔 |
|---|---|---|
| 會話管理 | 示例 | 📖 |
| 自動保存會話 | 示例 | 📖 |
| 上下文中的歷史記錄 | 示例 | 📖 |
| 遙測 | 示例 | 📖 |
| 項目文檔 (.praison/docs/) | 示例 | 📖 |
| AI 提交消息 | 示例 | 📖 |
| 提示中的 @提及 | 示例 | 📖 |
🖥️ CLI 特性
| 特性 | 代碼示例 | 文檔 |
|---|---|---|
| 斜槓命令 | 示例 | 📖 |
| 自主模式 | 示例 | 📖 |
| 成本跟蹤 | 示例 | 📖 |
| 存儲庫映射 | 示例 | 📖 |
| 交互式 TUI | 示例 | 📖 |
| Git 集成 | 示例 | 📖 |
| 沙盒執行 | 示例 | 📖 |
| CLI 比較 | 示例 | 📖 |
| 配置文件/基準測試 | 示例 | 📖 |
| 自動模式 | 示例 | 📖 |
| 初始化 | 示例 | 📖 |
| 文件輸入 | 示例 | 📖 |
| 最終智能體 | 示例 | 📖 |
| 最大令牌數 | 示例 | 📖 |
🧪 評估
| 特性 | 代碼示例 | 文檔 |
|---|---|---|
| 準確性評估 | 示例 | 📖 |
| 性能評估 | 示例 | 📖 |
| 可靠性評估 | 示例 | 📖 |
| 標準評估 | 示例 | 📖 |
🎯 智能體技能
| 特性 | 代碼示例 | 文檔 |
|---|---|---|
| 技能管理 | 示例 | 📖 |
| 自定義技能 | 示例 | 📖 |
⏰ 24/7 調度
| 特性 | 代碼示例 | 文檔 |
|---|---|---|
| 智能體調度器 | 示例 | 📖 |
📦 安裝指南
Python SDK
用於編碼的輕量級包:
pip install praisonaiagents
如需支持 CLI 的完整框架:
pip install praisonai
JavaScript SDK
npm install praisonai
環境變量
| 變量 | 是否必需 | 描述 |
|---|---|---|
OPENAI_API_KEY |
是* | OpenAI API 密鑰 |
ANTHROPIC_API_KEY |
否 | Anthropic Claude API 密鑰 |
GOOGLE_API_KEY |
否 | Google Gemini API 密鑰 |
GROQ_API_KEY |
否 | Groq API 密鑰 |
OPENAI_BASE_URL |
否 | 自定義 API 端點(用於 Ollama、Groq 等) |
*至少需要一個大語言模型提供商的 API 密鑰。
# 設置 API 密鑰
export OPENAI_API_KEY=your_key_here
# 對於 Ollama(本地模型)
export OPENAI_BASE_URL=http://localhost:11434/v1
# 對於 Groq
export OPENAI_API_KEY=your_groq_key
export OPENAI_BASE_URL=https://api.groq.com/openai/v1
💻 使用示例
Python 代碼示例
基礎用法
# 單智能體
from praisonaiagents import Agent
agent = Agent(instructions="Your are a helpful AI assistant")
agent.start("Write a movie script about a robot in Mars")
# 多智能體
from praisonaiagents import Agent, PraisonAIAgents
research_agent = Agent(instructions="Research about AI")
summarise_agent = Agent(instructions="Summarise research agent's findings")
agents = PraisonAIAgents(agents=[research_agent, summarise_agent])
agents.start()
高級用法
# 帶規劃模式的智能體
from praisonaiagents import Agent
def search_web(query: str) -> str:
return f"Search results for: {query}"
agent = Agent(
name="AI Assistant",
instructions="Research and write about topics",
planning=True, # 啟用規劃模式
planning_tools=[search_web], # 規劃研究的工具
planning_reasoning=True # 思維鏈推理
)
result = agent.start("Research AI trends in 2025 and write a summary")
# 深度研究智能體
from praisonaiagents import DeepResearchAgent
# OpenAI 深度研究
agent = DeepResearchAgent(
model="o4-mini-deep-research", # 或 "o3-deep-research"
verbose=True
)
result = agent.research("What are the latest AI trends in 2025?")
print(result.report)
print(f"Citations: {len(result.citations)}")
# Gemini 深度研究
from praisonaiagents import DeepResearchAgent
agent = DeepResearchAgent(
model="deep-research-pro", # 自動檢測為 Gemini
verbose=True
)
result = agent.research("Research quantum computing advances")
print(result.report)
# 查詢重寫智能體
from praisonaiagents import QueryRewriterAgent, RewriteStrategy
agent = QueryRewriterAgent(model="gpt-4o-mini")
# 基礎 - 擴展縮寫,添加上下文
result = agent.rewrite("AI trends")
print(result.primary_query) # "What are the current trends in Artificial Intelligence?"
# HyDE - 生成假設文檔進行語義匹配
result = agent.rewrite("What is quantum computing?", strategy=RewriteStrategy.HYDE)
# 回溯 - 生成更廣泛的上下文問題
result = agent.rewrite("GPT-4 vs Claude 3?", strategy=RewriteStrategy.STEP_BACK)
# 子查詢 - 分解複雜問題
result = agent.rewrite("RAG setup and best embedding models?", strategy=RewriteStrategy.SUB_QUERIES)
# 上下文 - 使用聊天曆史解決引用問題
result = agent.rewrite("What about cost?", chat_history=[...])
# 智能體記憶(零依賴)
from praisonaiagents import Agent
from praisonaiagents.memory import FileMemory
# 啟用記憶
agent = Agent(
name="Personal Assistant",
instructions="You are a helpful assistant that remembers user preferences.",
memory=True, # 啟用基於文件的記憶(無需額外依賴!)
user_id="user123" # 按用戶隔離記憶
)
# 記憶會自動注入對話中
result = agent.start("My name is John and I prefer Python")
# 智能體將在未來的對話中記住這一點
# 自動生成記憶
from praisonaiagents.memory import FileMemory, AutoMemory
memory = FileMemory(user_id="user123")
auto = AutoMemory(memory, enabled=True)
# 自動從對話中提取和存儲記憶
memories = auto.process_interaction(
"My name is John and I prefer Python for backend work"
)
# 提取:name="John", preference="Python for backend"
# 智能體工作流
from praisonaiagents import Agent, Workflow
# 創建智能體
researcher = Agent(
name="Researcher",
role="Research Analyst",
goal="Research topics thoroughly",
instructions="Provide concise, factual information."
)
writer = Agent(
name="Writer",
role="Content Writer",
goal="Write engaging content",
instructions="Write clear, engaging content based on research."
)
# 創建工作流
workflow = Workflow(steps=[researcher, writer])
# 運行工作流 - 智能體按順序處理
result = workflow.start("What are the benefits of AI agents?")
print(result["output"])
# 工作流模式(路由、並行、循環、重複)
from praisonaiagents import Agent, Workflow
from praisonaiagents.workflows import route, parallel, loop, repeat
# 1. 路由 - 分類器智能體將任務路由到專業智能體
classifier = Agent(name="Classifier", instructions="Respond with 'technical' or 'creative'")
tech_agent = Agent(name="TechExpert", role="Technical Expert")
creative_agent = Agent(name="Creative", role="Creative Writer")
workflow = Workflow(steps=[
classifier,
route({
"technical": [tech_agent],
"creative": [creative_agent]
})
])
# 2. 並行 - 多個智能體併發工作
market_agent = Agent(name="Market", role="Market Researcher")
competitor_agent = Agent(name="Competitor", role="Competitor Analyst")
aggregator = Agent(name="Aggregator", role="Synthesizer")
workflow = Workflow(steps=[
parallel([market_agent, competitor_agent]),
aggregator
])
# 3. 循環 - 智能體處理每個項目
processor = Agent(name="Processor", role="Item Processor")
summarizer = Agent(name="Summarizer", role="Summarizer")
workflow = Workflow(
steps=[loop(processor, over="items"), summarizer],
variables={"items": ["AI", "ML", "NLP"]}
)
# 4. 重複 - 評估器 - 優化器模式
generator = Agent(name="Generator", role="Content Generator")
evaluator = Agent(name="Evaluator", instructions="Say 'APPROVED' if good")
workflow = Workflow(steps=[
generator,
repeat(evaluator, until=lambda ctx: "approved" in ctx.previous_result.lower(), max_iterations=3)
])
# 5. 回調
workflow = Workflow(
steps=[researcher, writer],
on_step_complete=lambda name, r: print(f"✅ {name} done")
)
# 6. 帶規劃和推理
workflow = Workflow(
steps=[researcher, writer],
planning=True,
reasoning=True
)
# 7. 異步執行
import asyncio
result = asyncio.run(workflow.astart("input"))
# 8. 狀態跟蹤
workflow.status # "not_started" | "running" | "completed"
workflow.step_statuses # {"step1": "completed", "step2": "skipped"}
# YAML 工作流模板
from praisonaiagents.workflows import YAMLWorkflowParser, WorkflowManager
# 選項 1:解析 YAML 字符串
parser = YAMLWorkflowParser()
workflow = parser.parse_string(yaml_content)
result = workflow.start("Research AI trends")
# 選項 2:使用 WorkflowManager 從文件加載
manager = WorkflowManager()
workflow = manager.load_yaml("research_workflow.yaml")
result = workflow.start("Research AI trends")
# 選項 3:直接執行 YAML
result = manager.execute_yaml(
"research_workflow.yaml",
input_data="Research AI trends",
variables={"topic": "Machine Learning"}
)
# 鉤子
from praisonaiagents.hooks import (
HookRegistry, HookRunner, HookEvent, HookResult,
BeforeToolInput
)
# 創建鉤子註冊表
registry = HookRegistry()
# 記錄所有工具調用
@registry.on(HookEvent.BEFORE_TOOL)
def log_tools(event_data: BeforeToolInput) -> HookResult:
print(f"Tool: {event_data.tool_name}")
return HookResult.allow()
# 阻止危險操作
@registry.on(HookEvent.BEFORE_TOOL)
def security_check(event_data: BeforeToolInput) -> HookResult:
if "delete" in event_data.tool_name.lower():
return HookResult.deny("Delete operations blocked")
return HookResult.allow()
# 執行鉤子
runner = HookRunner(registry)
# 影子 Git 檢查點
from praisonaiagents.checkpoints import CheckpointService
service = CheckpointService(workspace_dir="./my_project")
await service.initialize()
# 保存更改前的檢查點
result = await service.save("Before refactoring")
# 進行更改...
# 需要時恢復
await service.restore(result.checkpoint.id)
# 查看差異
diff = await service.diff()
# 後臺任務
import asyncio
from praisonaiagents.background import BackgroundRunner, BackgroundConfig
async def main():
config = BackgroundConfig(max_concurrent_tasks=3)
runner = BackgroundRunner(config=config)
async def my_task(name: str) -> str:
await asyncio.sleep(2)
return f"Task {name} completed"
task = await runner.submit(my_task, args=("example",), name="my_task")
await task.wait(timeout=10.0)
print(task.result)
asyncio.run(main())
# 策略引擎
from praisonaiagents.policy import (
PolicyEngine, Policy, PolicyRule, PolicyAction
)
engine = PolicyEngine()
policy = Policy(
name="no_delete",
rules=[
PolicyRule(
action=PolicyAction.DENY,
resource="tool:delete_*",
reason="Delete operations blocked"
)
]
)
engine.add_policy(policy)
result = engine.check("tool:delete_file", {})
print(f"Allowed: {result.allowed}")
# 思考預算
from praisonaiagents.thinking import ThinkingBudget, ThinkingTracker
# 使用預定義級別
budget = ThinkingBudget.high() # 16,000 個令牌
# 跟蹤使用情況
tracker = ThinkingTracker()
session = tracker.start_session(budget_tokens=16000)
tracker.end_session(session, tokens_used=12000)
summary = tracker.get_summary()
print(f"Utilization: {summary['average_utilization']:.1%}")
# 輸出樣式
from praisonaiagents.output import OutputStyle, OutputFormatter
# 使用預設樣式
style = OutputStyle.concise()
formatter = OutputFormatter(style)
# 格式化輸出
text = "# Hello\n\nThis is **bold** text."
plain = formatter.format(text)
print(plain)
# 上下文壓縮
from praisonaiagents.compaction import (
ContextCompactor, CompactionStrategy
)
compactor = ContextCompactor(
max_tokens=4000,
strategy=CompactionStrategy.SLIDING,
preserve_recent=3
)
messages = [...] # 你的對話歷史
compacted, result = compactor.compact(messages)
print(f"Compression: {result.compression_ratio:.1%}")
# 字段名稱參考(A-I-G-S)
PraisonAI 同時接受舊的(agents.yaml)和新的(workflow.yaml)字段名稱。對於新項目,建議使用**規範名稱**:
| 規範名稱(推薦) | 別名(也可用) | 用途 |
|-------------------------|-------------------|---------|
| `agents` | `roles` | 定義智能體角色 |
| `instructions` | `backstory` | 智能體行為/角色 |
| `action` | `description` | 步驟的操作 |
| `steps` | `tasks`(嵌套) | 定義工作項 |
| `name` | `topic` | 工作流標識符 |
# A-I-G-S 助記符 - 易於記憶:
- **A**gents - 誰來完成工作
- **I**nstructions - 他們的行為方式
- **G**oal - 他們要實現的目標
- **S**teps - 他們要做的事情
# 快速參考 - 規範格式
name: My Workflow # 工作流名稱(不是 'topic')
agents: # 定義智能體(不是 'roles')
my_agent:
role: Job Title # 智能體的角色
goal: What to achieve # 智能體的目標
instructions: How to act # 智能體的行為(不是 'backstory')
steps: # 定義步驟(不是 'tasks')
- agent: my_agent
action: What to do # 步驟操作(不是 'description')
# 注意:解析器同時接受舊名稱和新名稱。運行 `praisonai workflow validate <file.yaml>` 以查看規範名稱的建議。
# 擴展 agents.yaml 與工作流模式
# 特性對等:現在 `agents.yaml` 和 `workflow.yaml` 支持相同的特性:
# - 所有工作流模式(路由、並行、循環、重複)
# - 所有智能體字段(function_calling_llm、max_rpm、max_execution_time、reflect_llm、模板)
# - 所有步驟字段(expected_output、context、output_json、create_directory、回調)
# - 框架支持(praisonai、crewai、autogen)
# - 流程類型(順序、層次結構、工作流)
# 你可以通過設置 `process: workflow` 直接在 agents.yaml 中使用高級工作流模式:
# agents.yaml 與工作流模式
framework: praisonai
process: workflow # 啟用工作流模式
topic: "Research AI trends"
workflow:
planning: true
reasoning: true
verbose: true
variables:
topic: AI trends
agents: # 規範:使用 'agents' 而不是 'roles'
classifier:
role: Request Classifier
instructions: "Classify requests into categories" # 規範:使用 'instructions' 而不是 'backstory'
goal: Classify requests
researcher:
role: Research Analyst
instructions: "Expert researcher" # 規範:使用 'instructions' 而不是 'backstory'
goal: Research topics
tools:
- tavily_search
steps:
# 順序步驟
- agent: classifier
action: "Classify: {{topic}}"
# 路由模式 - 基於決策的分支
- name: routing
route:
technical: [tech_expert]
default: [researcher]
# 並行模式 - 併發執行
- name: parallel_research
parallel:
- agent: researcher
action: "Research market trends"
- agent: researcher
action: "Research competitors"
# 循環模式 - 遍歷項目
- agent: researcher
action: "Analyze {{item}}"
loop:
over: topics
# 重複模式 - 評估器 - 優化器
- agent: aggregator
action: "Synthesize findings"
repeat:
until: "comprehensive"
max_iterations: 3
# 使用相同的簡單命令運行
praisonai agents.yaml
# MCP(模型上下文協議)
# MCP 客戶端(使用 MCP 服務器)
from praisonaiagents import Agent, MCP
# stdio - 本地 NPX/Python 服務器
agent = Agent(tools=MCP("npx @modelcontextprotocol/server-memory"))
# 可流式傳輸的 HTTP - 生產服務器
agent = Agent(tools=MCP("https://api.example.com/mcp"))
# WebSocket - 即時雙向
agent = Agent(tools=MCP("wss://api.example.com/mcp", auth_token="token"))
# SSE(舊版) - 向後兼容
agent = Agent(tools=MCP("http://localhost:8080/sse"))
# 使用環境變量
agent = Agent(
tools=MCP(
command="npx",
args=["-y", "@modelcontextprotocol/server-brave-search"],
env={"BRAVE_API_KEY": "your-key"}
)
)
# 多個 MCP 服務器 + 常規函數
def my_custom_tool(query: str) -> str:
"""自定義工具函數。"""
return f"Result: {query}"
agent = Agent(
name="MultiToolAgent",
instructions="Agent with multiple MCP servers",
tools=[
MCP("uvx mcp-server-time"), # 時間工具
MCP("npx @modelcontextprotocol/server-memory"), # 內存工具
my_custom_tool # 常規函數
]
)
# MCP 服務器(將工具暴露為 MCP 服務器)
from praisonaiagents.mcp import ToolsMCPServer
def search_web(query: str, max_results: int = 5) -> dict:
"""在網絡上搜索信息。"""
return {"results": [f"Result for {query}"]}
def calculate(expression: str) -> dict:
"""計算數學表達式。"""
return {"result": eval(expression)}
# 創建並運行 MCP 服務器
server = ToolsMCPServer(name="my-tools")
server.register_tools([search_web, calculate])
server.run() # stdio 用於 Claude Desktop
# server.run_sse(host="0.0.0.0", port=8080) # SSE 用於 Web 客戶端
# MCP 特性
| 特性 | 描述 |
|---------|-------------|
| 會話管理 | 自動處理 Mcp-Session-Id |
| 協議版本控制 | Mcp-Protocol-Version 標頭 |
| 可恢復性 | 通過 Last-Event-ID 恢復 SSE 流 |
| 安全性 | 源驗證,防止 DNS 重綁定 |
| WebSocket | 具有指數退避的自動重新連接 |
# A2A(智能體到智能體協議)
# PraisonAI 支持 [A2A 協議](https://a2a-protocol.org) 進行智能體間通信,使你的智能體能夠被發現並與其他 AI 智能體協作。
# A2A 服務器(將智能體暴露為 A2A 服務器)
from praisonaiagents import Agent, A2A
from fastapi import FastAPI
# 創建帶工具的智能體
def search_web(query: str) -> str:
"""在網絡上搜索信息。"""
return f"Results for: {query}"
agent = Agent(
name="Research Assistant",
role="Research Analyst",
goal="Help users research topics",
tools=[search_web]
)
# 暴露為 A2A 服務器
a2a = A2A(agent=agent, url="http://localhost:8000/a2a")
app = FastAPI()
app.include_router(a2a.get_router())
# 運行:uvicorn app:app --reload
# 智能體卡片:GET /.well-known/agent.json
# 狀態:GET /status
# A2A 特性
| 特性 | 描述 |
|---------|-------------|
| 智能體卡片 | 用於智能體發現的 JSON 元數據 |
| 技能提取 | 從工具自動生成技能 |
| 任務管理 | 有狀態的任務生命週期 |
| 流式傳輸 | SSE 流式傳輸以實現即時更新 |
# 文檔:[docs.praison.ai/a2a](https://docs.praison.ai/a2a) | 示例:[examples/python/a2a](https://github.com/MervinPraison/PraisonAI/tree/main/examples/python/a2a)
JavaScript 代碼示例
const { Agent } = require('praisonai');
const agent = new Agent({ instructions: 'You are a helpful AI assistant' });
agent.start('Write a movie script about a robot in Mars');
📚 詳細文檔
🌐 支持的提供商
PraisonAI 通過無縫集成支持 100 多個大語言模型提供商:
| 提供商 | 示例 |
|---|---|
| OpenAI | 示例 |
| Anthropic | 示例 |
| Google Gemini | 示例 |
| Ollama | 示例 |
| Groq | 示例 |
| DeepSeek | 示例 |
| xAI Grok | 示例 |
| Mistral | 示例 |
| Cohere | 示例 |
| Perplexity | 示例 |
| Fireworks | 示例 |
| Together AI | 示例 |
| OpenRouter | 示例 |
| HuggingFace | 示例 |
| Azure OpenAI | 示例 |
| AWS Bedrock | 示例 |
| Google Vertex | 示例 |
| Databricks | 示例 |
| Cloudflare | 示例 |
| AI21 | 示例 |
| Replicate | 示例 |
| SageMaker | 示例 |
| Moonshot | 示例 |
| vLLM | 示例 |
🎯 CLI / 無代碼界面
PraisonAI 提供強大的 CLI 用於無代碼自動化和快速原型開發。
CLI 快速參考
| 類別 | 命令 |
|---|---|
| 執行 | praisonai, --auto, --interactive, --chat |
| 研究 | research, --query-rewrite, --deep-research |
| 規劃 | --planning, --planning-tools, --planning-reasoning |
| 工作流 | workflow run, workflow list, workflow auto |
| 記憶 | memory show, memory add, memory search, memory clear |
| 知識 | knowledge add, knowledge query, knowledge list |
| 會話 | session list, session resume, session delete |
| 工具 | tools list, tools info, tools search |
| MCP | mcp list, mcp create, mcp enable |
| 開發 | commit, docs, checkpoint, hooks |
| 調度 | schedule start, schedule list, schedule stop |
自動模式
pip install praisonai
export OPENAI_API_KEY=xxxxxxxxxxxxxxxxxxxxxx
praisonai --auto create a movie script about Robots in Mars
交互式模式 CLI
# 啟動交互式終端模式(受 Gemini CLI、Codex CLI、Claude Code 啟發)
praisonai --interactive
praisonai -i
# 特性:
# - 流式響應(無框)
# - 內置工具:read_file、write_file、list_files、execute_command、internet_search
# - 斜槓命令:/help、/exit、/tools、/clear
# 聊天模式 - 具有交互式風格的單提示(用於測試/腳本編寫)
# 使用 --chat(或 --chat-mode 以實現向後兼容)
praisonai "list files in current folder" --chat
praisonai "search the web for AI news" --chat
praisonai "read README.md" --chat
聊天 UI(Web 界面)
# 啟動基於 Web 的 Chainlit 聊天界面(需要 praisonai[chat])
pip install "praisonai[chat]"
praisonai chat
# 在瀏覽器中打開 http://localhost:8084
查詢重寫(適用於任何命令)
# 重寫查詢以獲得更好的結果(使用 QueryRewriterAgent)
praisonai "AI trends" --query-rewrite
# 使用搜索工具進行重寫(智能體決定何時搜索)
praisonai "latest developments" --query-rewrite --rewrite-tools "internet_search"
# 適用於任何提示
praisonai "explain quantum computing" --query-rewrite -v
深度研究 CLI
# 默認:OpenAI (o4-mini-deep-research)
praisonai research "What are the latest AI trends in 2025?"
# 使用 Gemini
praisonai research --model deep-research-pro "Your research query"
# 在研究前重寫查詢
praisonai research --query-rewrite "AI trends"
# 使用搜索工具進行重寫
praisonai research --query-rewrite --rewrite-tools "internet_search" "AI trends"
# 使用文件中的自定義工具(在深度研究前收集上下文)
praisonai research --tools tools.py "Your research query"
praisonai research -t my_tools.py "Your research query"
# 使用內置工具名稱(逗號分隔)
praisonai research --tools "internet_search,wiki_search" "Your query"
praisonai research -t "yfinance,calculator_tools" "Stock analysis query"
# 將輸出保存到文件(output/research/{query}.md)
praisonai research --save "Your research query"
praisonai research -s "Your research query"
# 組合選項
praisonai research --query-rewrite --tools tools.py --save "Your research query"
# 詳細模式(顯示調試日誌)
praisonai research -v "Your research query"
規劃模式 CLI
# 啟用規劃模式 - 智能體在執行前創建計劃
praisonai "Research AI trends and write a summary" --planning
# 規劃時使用工具進行研究
praisonai "Analyze market trends" --planning --planning-tools tools.py
# 規劃時使用思維鏈推理
praisonai "Complex analysis task" --planning --planning-reasoning
# 自動批准計劃而無需確認
praisonai "Task" --planning --auto-approve-plan
工具批准 CLI
# 自動批准所有工具執行(謹慎使用!)
praisonai "run ls command" --trust
# 自動批准風險級別以下的工具(對更高風險的工具進行提示)
# 級別:low, medium, high, critical
praisonai "write to file" --approve-level high # 僅對關鍵工具進行提示
praisonai "task" --approve-level medium # 對高風險和關鍵工具進行提示
# 默認行為(無標誌):對所有危險工具進行提示
praisonai "run shell command" # 將提示批准
記憶 CLI
# 為智能體啟用記憶(跨會話持久化)
praisonai "My name is John" --memory
# 按用戶隔離記憶
praisonai "Remember my preferences" --memory --user-id user123
# 記憶管理命令
praisonai memory show # 顯示記憶統計信息
praisonai memory add "User prefers Python" # 添加到長期記憶
praisonai memory search "Python" # 搜索記憶
praisonai memory clear # 清除短期記憶
praisonai memory clear all # 清除所有記憶
praisonai memory save my_session # 保存會話
praisonai memory resume my_session # 恢復會話
praisonai memory sessions # 列出保存的會話
praisonai memory checkpoint # 創建檢查點
praisonai memory restore <checkpoint_id> # 恢復檢查點
praisonai memory checkpoints # 列出檢查點
praisonai memory help # 顯示所有命令
規則 CLI
# 列出所有加載的規則(來自 PRAISON.md、CLAUDE.md 等)
praisonai rules list
# 顯示特定規則的詳細信息
praisonai rules show <rule_name>
# 創建新規則
praisonai rules create my_rule "Always use type hints"
# 刪除規則
praisonai rules delete my_rule
# 顯示規則統計信息
praisonai rules stats
# 在提示中包含手動規則
praisonai "Task" --include-rules security,testing
工作流 CLI
# 列出可用的工作流
praisonai workflow list
# 執行帶有工具的工作流並保存輸出
praisonai workflow run "Research Blog" --tools tavily --save
# 使用變量執行
praisonai workflow run deploy --workflow-var environment=staging --workflow-var branch=main
# 使用規劃模式執行(AI 為每個工作流步驟創建子步驟)
praisonai workflow run "Research Blog" --planning --verbose
# 使用推理模式執行(思維鏈)
praisonai workflow run "Analysis" --reasoning --verbose
# 啟用記憶執行
praisonai workflow run "Research" --memory
# 顯示工作流詳細信息
praisonai workflow show deploy
# 創建新的工作流模板
praisonai workflow create my_workflow
# 內聯工作流(無需模板文件)
praisonai "What is AI?" --workflow "Research,Summarize" --save
# 帶有步驟操作的內聯工作流
praisonai "GPT-5" --workflow "Research:Search for info,Write:Write blog" --tools tavily
# 工作流 CLI 幫助
praisonai workflow help
YAML 工作流文件
# 運行 YAML 工作流文件
praisonai workflow run research.yaml
# 使用變量運行
praisonai workflow run research.yaml --var topic="AI trends"
# 驗證 YAML 工作流
praisonai workflow validate research.yaml
# 從模板創建(簡單、路由、並行、循環、評估器 - 優化器)
praisonai workflow template routing --output my_workflow.yaml
自動生成工作流
# 從主題自動生成順序工作流
praisonai workflow auto "Research AI trends"
# 生成並行工作流(多個智能體併發工作)
praisonai workflow auto "Research AI trends" --pattern parallel
# 生成路由工作流(分類器將任務路由到專家)
praisonai workflow auto "Build a chatbot" --pattern routing
# 生成編排器 - 工作者工作流(中央編排器委派任務)
praisonai workflow auto "Comprehensive market analysis" --pattern orchestrator-workers
# 生成評估器 - 優化器工作流(迭代改進)
praisonai workflow auto "Write and refine article" --pattern evaluator-optimizer
# 指定輸出文件
praisonai workflow auto "Build a chatbot" --pattern routing
# 指定輸出文件
praisonai workflow auto "Research AI" --pattern sequential --output my_workflow.yaml
工作流 CLI 選項
| 標誌 | 描述 |
|---|---|
--workflow-var key=value |
設置工作流變量(可重複) |
--var key=value |
為 YAML 工作流設置變量 |
--pattern <pattern> |
自動生成的模式(順序、並行、路由、循環、編排器 - 工作者、評估器 - 優化器) |
--output <file> |
自動生成的輸出文件 |
--llm <model> |
大語言模型(例如,openai/gpt-4o-mini) |
--tools <tools> |
工具(逗號分隔,例如,tavily) |
--planning |
啟用規劃模式 |
--reasoning |
啟用推理模式 |
--memory |
啟用記憶 |
--verbose |
啟用詳細輸出 |
--save |
將輸出保存到文件 |
鉤子 CLI
# 列出已配置的鉤子
praisonai hooks list
# 顯示鉤子統計信息
praisonai hooks stats
# 創建 hooks.json 模板
praisonai hooks init
Claude 記憶工具 CLI
# 啟用 Claude 記憶工具(僅適用於 Anthropic 模型)
praisonai "Research and remember findings" --claude-memory --llm anthropic/claude-sonnet-4-20250514
護欄 CLI
# 使用大語言模型護欄驗證輸出
praisonai "Write code" --guardrail "Ensure code is secure and follows best practices"
# 與其他標誌組合使用
praisonai "Generate SQL query" --guardrail "No DROP or DELETE statements" --save
指標 CLI
# 顯示令牌使用情況和成本指標
praisonai "Analyze this data" --metrics
# 與其他功能組合使用
praisonai "Complex task" --metrics --planning
調度器 CLI
praisonai schedule start <name> "task" --interval hourly
praisonai schedule list
praisonai schedule logs <name> [--follow]
praisonai schedule stop <name>
praisonai schedule restart <name>
praisonai schedule delete <name>
praisonai schedule describe <name>
praisonai schedule save <name> [file.yaml]
praisonai schedule "task" --interval hourly # 前臺模式
praisonai schedule agents.yaml # 前臺模式
圖像處理 CLI
# 使用基於視覺的任務處理圖像
praisonai "Describe this image" --image path/to/image.png
# 分析圖像內容
praisonai "What objects are in this photo?" --image photo.jpg --llm openai/gpt-4o
遙測 CLI
# 啟用使用情況監控和分析
praisonai "Task" --telemetry
# 與指標結合以實現全面可觀察性
praisonai "Complex analysis" --telemetry --metrics
MCP(模型上下文協議)CLI
# 使用 MCP 服務器工具
praisonai "Search files" --mcp "npx -y @modelcontextprotocol/server-filesystem ."
# 帶有環境變量的 MCP
praisonai "Search web" --mcp "npx -y @modelcontextprotocol/server-brave-search" --mcp-env "BRAVE_API_KEY=your_key"
# 多個 MCP 選項
praisonai "Task" --mcp "npx server" --mcp-env "KEY1=value1,KEY2=value2"
快速上下文 CLI
# 在代碼庫中搜索相關上下文
praisonai "Find authentication code" --fast-context ./src
# 為任何任務添加代碼上下文
praisonai "Explain this function" --fast-context /path/to/project
知識 CLI
# 向知識庫添加文檔
praisonai knowledge add document.pdf
praisonai knowledge add ./docs/
# 搜索知識庫
praisonai knowledge search "API authentication"
# 列出索引文檔
praisonai knowledge list
# 清除知識庫
praisonai knowledge clear
# 顯示知識庫信息
praisonai knowledge info
# 顯示所有命令
praisonai knowledge help
會話 CLI
# 列出所有保存的會話
praisonai session list
# 顯示會話詳細信息
praisonai session show my-project
# 恢復會話(加載到內存中)
praisonai session resume my-project
# 刪除會話
praisonai session delete my-project
# 每次運行後自動保存會話
praisonai "Analyze this code" --auto-save my-project
# 從最後 N 個會話加載歷史記錄到上下文中
praisonai "Continue our discussion" --history 5
會話管理(Python)
from praisonaiagents import Agent
# 每次運行後自動保存會話
agent = Agent(
name="Assistant",
memory=True,
auto_save="my-project"
)
# 從最後 5 個會話加載歷史記錄
agent = Agent(
name="Assistant",
memory=True,
history_in_context=5
)
工作流檢查點
from praisonaiagents.memory.workflows import WorkflowManager
manager = WorkflowManager()
# 每個步驟後保存檢查點
result = manager.execute("deploy", checkpoint="deploy-v1")
# 從檢查點恢復
result = manager.execute("deploy", resume="deploy-v1")
# 列出/刪除檢查點
manager.list_checkpoints()
manager.delete_checkpoint("deploy-v1")
工具 CLI
praisonai tools list
praisonai tools info internet_search
praisonai tools search "web"
praisonai tools doctor
praisonai tools resolve shell_tool
praisonai tools discover
praisonai tools show-sources
praisonai tools show-sources --template ai-video-editor
| 命令 | 示例 | 文檔 |
|---|---|---|
tools list |
示例 | 文檔 |
tools resolve |
示例 | 文檔 |
tools discover |
示例 | 文檔 |
tools show-sources |
示例 | 文檔 |
交接 CLI
# 啟用智能體間任務委派
praisonai "Research and write article" --handoff "researcher,writer,editor"
# 複雜的多智能體工作流
praisonai "Analyze data and create report" --handoff "analyst,visualizer,writer"
自動記憶 CLI
# 啟用自動記憶提取
praisonai "Learn about user preferences" --auto-memory
# 與用戶隔離結合使用
praisonai "Remember my settings" --auto-memory --user-id user123
待辦事項 CLI
# 從任務生成待辦事項列表
praisonai "Plan the project" --todo
# 添加待辦事項
praisonai todo add "Implement feature X"
# 列出所有待辦事項
praisonai todo list
# 完成待辦事項
praisonai todo complete 1
# 刪除待辦事項
praisonai todo delete 1
# 清除所有待辦事項
praisonai todo clear
# 顯示所有命令
praisonai todo help
路由器 CLI
# 根據任務複雜性自動選擇最佳模型
praisonai "Simple question" --router
# 指定首選提供商
praisonai "Complex analysis" --router --router-provider anthropic
# 路由器自動選擇:
# - 簡單任務 → gpt-4o-mini, claude-3-haiku
# - 複雜任務 → gpt-4-turbo, claude-3-opus
# 使用模型路由模板創建工作流
praisonai workflow create --template model-routing --output my_workflow.yaml
自定義模型可以在 agents.yaml 中配置。有關詳細信息,請參閱 模型路由器文檔。
流程顯示 CLI
# 啟用可視化工作流跟蹤
praisonai agents.yaml --flow-display
# 與其他功能結合使用
praisonai "Multi-step task" --planning --flow-display
文檔 CLI
# 列出所有項目文檔
praisonai docs list
# 創建新文檔
praisonai docs create project-overview "This project is a Python web app..."
# 顯示特定文檔
praisonai docs show project-overview
# 刪除文檔
praisonai docs delete old-doc
# 顯示所有命令
praisonai docs help
MCP 配置 CLI
# 列出所有 MCP 配置
praisonai mcp list
# 創建新的 MCP 配置
praisonai mcp create filesystem npx -y @modelcontextprotocol/server-filesystem .
# 顯示特定配置
praisonai mcp show filesystem
# 啟用/禁用配置
praisonai mcp enable filesystem
praisonai mcp disable filesystem
# 刪除配置
praisonai mcp delete filesystem
# 顯示所有命令
praisonai mcp help
AI 提交 CLI
# 全自動模式:暫存所有更改、進行安全檢查、提交併推送
praisonai commit -a
# 交互式模式(需要先執行 git add)
praisonai commit
# 交互式模式並自動推送
praisonai commit --push
# 跳過安全檢查(不推薦)
praisonai commit -a --no-verify
特性:
- 🤖 AI 生成的常規提交消息
- 🔒 內置安全掃描(API 密鑰、密碼、機密、敏感文件)
- 📦 使用 -a 標誌自動暫存
- 🚀 全自動模式下自動推送
- ✏️ 交互式模式下在提交前編輯消息
安全檢測:
- API 密鑰、機密、令牌(AWS、GitHub、GitLab、Slack)
- 密碼和私鑰
- 敏感文件(
.env,id_rsa,.pem,.key等)
服務 CLI(API 服務器)
# 為 YAML 中定義的智能體啟動 API 服務器
praisonai serve agents.yaml
# 使用自定義端口和主機
praisonai serve agents.yaml --port 8005 --host 0.0.0.0
# 替代標誌樣式
praisonai agents.yaml --serve
# 服務器提供:
# POST /agents - 按順序運行所有智能體
# POST /agents/{name} - 運行特定智能體(例如,/agents/researcher)
# GET /agents/list - 列出可用智能體
n8n 集成 CLI
# 將工作流導出到 n8n 並在瀏覽器中打開
praisonai agents.yaml --n8n
# 使用自定義 n8n URL
praisonai agents.yaml --n8n --n8n-url http://localhost:5678
# 設置 N8N_API_KEY 以實現自動導入
execute_agent_task
Executes the agent's primary task with the given prompt.
參數
prompt : str*
描述
The prompt or task description to execute
替代品

Paperbanana
PaperBanana是一個自動化生成學術圖表和統計圖的智能框架,支持從文本描述生成高質量的論文插圖,採用多智能體管道和迭代優化,提供CLI、Python API和MCP服務器等多種使用方式。
Python
10.2K
5分

Finlab Ai
FinLab AI是一個金融量化分析平臺,通過AI技術幫助用戶發現投資策略中的超額收益(alpha)。它提供豐富的數據集、回測框架和策略示例,支持自動化安裝與集成到主流AI編程助手。
10.5K
4分

Assistant Ui
assistant-ui是一個開源TypeScript/React庫,用於快速構建生產級AI聊天界面,提供可組合的UI組件、流式響應、無障礙訪問等功能,支持多種AI後端和模型。
TypeScript
9.5K
5分
A
Apify MCP Server
Apify MCP服務器是一個基於模型上下文協議(MCP)的工具,允許AI助手通過數千個現成的爬蟲、抓取器和自動化工具(Apify Actor)從社交媒體、搜索引擎、電商等網站提取數據。它支持OAuth和Skyfire代理支付,可通過HTTPS端點或本地stdio方式集成到Claude、VS Code等MCP客戶端中。
TypeScript
11.9K
5分
N
Next Devtools MCP
Next.js開發工具MCP服務器,為Claude、Cursor等AI編程助手提供Next.js開發工具和實用程序,包括運行時診斷、開發自動化和文檔訪問功能。
TypeScript
18.9K
5分
P
Praisonai
PraisonAI是一個生產就緒的多AI智能體框架,具有自反思功能,旨在創建AI智能體來自動化解決從簡單任務到複雜挑戰的各種問題。它通過將PraisonAI智能體、AG2和CrewAI集成到一個低代碼解決方案中,簡化了多智能體LLM系統的構建和管理,強調簡單性、定製化和有效的人機協作。
Python
19.2K
5分

Maverick MCP
MaverickMCP是一個基於FastMCP 2.0的個人股票分析服務器,為Claude Desktop等MCP客戶端提供專業級的金融數據分析、技術指標計算和投資組合優化工具。它預置了520只標普500股票數據,支持多種技術分析策略和並行處理,無需複雜認證即可本地運行。
Python
13.4K
4分
B
Blueprint MCP
Blueprint MCP是一個基於Arcade生態的圖表生成工具,利用Nano Banana Pro等技術,通過分析代碼庫和系統架構自動生成架構圖、流程圖等可視化圖表,幫助開發者理解複雜系統。
Python
12.0K
4分

Markdownify MCP
Markdownify是一個多功能文件轉換服務,支持將PDF、圖片、音頻等多種格式及網頁內容轉換為Markdown格式。
TypeScript
36.9K
5分

Baidu Map
已認證
百度地圖MCP Server是國內首個兼容MCP協議的地圖服務,提供地理編碼、路線規劃等10個標準化API接口,支持Python和Typescript快速接入,賦能智能體實現地圖相關功能。
Python
44.8K
4.5分

Firecrawl MCP Server
Firecrawl MCP Server是一個集成Firecrawl網頁抓取能力的模型上下文協議服務器,提供豐富的網頁抓取、搜索和內容提取功能。
TypeScript
147.6K
5分

Sequential Thinking MCP Server
一個基於MCP協議的結構化思維服務器,通過定義思考階段幫助分解複雜問題並生成總結
Python
36.1K
4.5分

Edgeone Pages MCP Server
EdgeOne Pages MCP是一個通過MCP協議快速部署HTML內容到EdgeOne Pages並獲取公開URL的服務
TypeScript
27.6K
4.8分

Magic MCP
Magic Component Platform (MCP) 是一個AI驅動的UI組件生成工具,通過自然語言描述幫助開發者快速創建現代化UI組件,支持多種IDE集成。
JavaScript
23.0K
5分

Notion Api MCP
已認證
一個基於Python的MCP服務器,通過Notion API提供高級待辦事項管理和內容組織功能,實現AI模型與Notion的無縫集成。
Python
21.5K
4.5分

Context7
Context7 MCP是一個為AI編程助手提供即時、版本特定文檔和代碼示例的服務,通過Model Context Protocol直接集成到提示中,解決LLM使用過時信息的問題。
TypeScript
93.9K
4.7分