主题
智能体能力
了解扩展 CrewAI 智能体的五种方式:工具、MCP、应用、技能和知识。
概述
CrewAI 智能体可以通过 五种不同的能力类型 进行扩展,每种类型服务于不同目的。理解何时使用每种类型——以及它们如何协同工作——是构建高效智能体的关键。
Tools
可调用函数——让智能体具备采取行动的能力。网页搜索、文件操作、API 调用、代码执行。
MCP Servers
远程工具服务器——通过 Model Context Protocol 将智能体连接到外部工具服务器。效果与工具相同,但托管在外部。
Apps
平台集成——通过 CrewAI 平台将智能体连接到 SaaS 应用(Gmail、Slack、Jira、Salesforce)。使用平台集成 token 在本地运行。
Skills
领域专业知识——将指令、指南和参考资料注入智能体提示词。技能告诉智能体 如何思考。
Knowledge
检索到的事实——通过语义搜索(RAG)为智能体提供来自文档、文件和 URL 的数据。知识告诉智能体 需要知道什么。
关键区别
最重要的一点是:这些能力分为两类。
行动能力(工具、MCP、应用)
这些能力让智能体能够 做事——调用 API、读取文件、搜索网页、发送电子邮件。在执行时,三者都会解析为相同的内部格式(BaseTool 实例),并出现在智能体可调用的统一工具列表中。
python
from crewai import Agent
from crewai_tools import SerperDevTool, FileReadTool
agent = Agent(
role="Researcher",
goal="Find and compile market data",
backstory="Expert market analyst",
tools=[SerperDevTool(), FileReadTool()], # Local tools
mcps=["https://mcp.example.com/sse"], # Remote MCP server tools
apps=["gmail", "google_sheets"], # Platform integrations
)上下文能力(技能、知识)
这些能力会修改智能体的 提示词——在智能体开始推理之前注入专业知识、指令或检索到的数据。它们不会赋予智能体新的行动;它们塑造智能体的思考方式以及可访问的信息。
python
from crewai import Agent
agent = Agent(
role="Security Auditor",
goal="Audit cloud infrastructure for vulnerabilities",
backstory="Expert in cloud security with 10 years of experience",
skills=["./skills/security-audit"], # Domain instructions
knowledge_sources=[pdf_source, url_source], # Retrieved facts
)何时使用何种能力
| 你需要…… | 使用 | 示例 |
|---|---|---|
| 让智能体搜索网页 | 工具 | tools=[SerperDevTool()] |
| 让智能体通过 MCP 调用远程 API | MCP | mcps=["https://api.example.com/sse"] |
| 让智能体通过 Gmail 发送电子邮件 | 应用 | apps=["gmail"] |
| 让智能体遵循特定流程 | 技能 | skills=["./skills/code-review"] |
| 让智能体引用公司文档 | 知识 | knowledge_sources=[pdf_source] |
| 让智能体搜索网页并遵循评审指南 | 工具 + 技能 | 同时使用两者 |
组合能力
在实践中,智能体经常 同时使用多种能力类型。下面是一个贴近实际的示例:
python
from crewai import Agent
from crewai_tools import SerperDevTool, FileReadTool, CodeInterpreterTool
# A fully-equipped research agent
researcher = Agent(
role="Senior Research Analyst",
goal="Produce comprehensive market analysis reports",
backstory="Expert analyst with deep industry knowledge",
# ACTION: What the agent can DO
tools=[
SerperDevTool(), # Search the web
FileReadTool(), # Read local files
CodeInterpreterTool(), # Run Python code for analysis
],
mcps=["https://data-api.example.com/sse"], # Access remote data API
apps=["google_sheets"], # Write to Google Sheets
# CONTEXT: What the agent KNOWS
skills=["./skills/research-methodology"], # How to conduct research
knowledge_sources=[company_docs], # Company-specific data
)对比表
| 功能 | 工具 | MCP | 应用 | 技能 | 知识 |
|---|---|---|---|---|---|
| 赋予智能体行动 | ✅ | ✅ | ✅ | ❌ | ❌ |
| 修改提示词 | ❌ | ❌ | ❌ | ✅ | ✅ |
| 需要代码 | 是 | 仅配置 | 仅配置 | 仅 Markdown | 仅配置 |
| 本地运行 | 是 | 视情况而定 | 是(使用环境变量) | 不适用 | 是 |
| 需要 API 密钥 | 每个工具 | 每个服务器 | 集成 token | 否 | 仅嵌入器 |
| 在智能体上设置 | tools=[] | mcps=[] | apps=[] | skills=[] | knowledge_sources=[] |
| 在团队上设置 | ❌ | ❌ | ❌ | skills=[] | knowledge_sources=[] |
深入探讨
准备好进一步了解每种能力类型了吗?