Agent 能力
CrewAI agents 可以通过 五种不同的能力类型 进行扩展,每一种都承担不同的职责。理解何时使用哪一种,以及它们如何协同工作,是构建高效 agents 的关键。
Tools
可调用函数 - 让 agents 能够采取行动。网页搜索、文件操作、API 调用、代码执行。
MCP Servers
远程工具服务器 - 通过 Model Context Protocol 将 agents 连接到外部工具服务器。效果和 tools 相同,但由外部托管。
Apps
平台集成 - 通过 CrewAI 平台把 agents 连接到 SaaS 应用(Gmail、Slack、Jira、Salesforce)。使用平台集成 token 在本地运行。
Skills
领域知识 - 将指令、规范和参考材料注入 agent prompts。Skills 告诉 agents 应该如何思考。
Knowledge
检索到的事实 - 通过语义搜索(RAG)为 agents 提供来自文档、文件和 URL 的数据。Knowledge 告诉 agents 需要知道什么。
最重要的一点是:这些能力分成两类。
行动型能力(Tools、MCP、Apps)
Section titled “行动型能力(Tools、MCP、Apps)”它们赋予 agents 执行动作的能力 - 调用 API、读取文件、搜索网页、发送邮件。执行时,这三者都会解析成同一种内部格式(BaseTool 实例),并出现在 agent 可以调用的统一工具列表中。
from crewai import Agentfrom crewai_tools import SerperDevTool, FileReadTool
agent = Agent( role="Researcher", goal="Find and compile market data", backstory="Expert market analyst", tools=[SerperDevTool(), FileReadTool()], # 本地工具 mcps=["https://mcp.example.com/sse"], # 远程 MCP 服务器工具 apps=["gmail", "google_sheets"], # 平台集成)上下文型能力(Skills、Knowledge)
Section titled “上下文型能力(Skills、Knowledge)”它们会修改 agent 的 prompt - 在 agent 开始推理前注入专业知识、指令或检索到的数据。它们不会给 agent 新动作;它们决定的是 agent 如何思考,以及它能访问哪些信息。
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"], # 领域指令 knowledge_sources=[pdf_source, url_source], # 检索到的事实)何时使用什么
Section titled “何时使用什么”| 你需要… | 使用 | 示例 |
|---|---|---|
| Agent 搜索网页 | Tools | tools=[SerperDevTool()] |
| Agent 通过 MCP 调用远程 API | MCPs | mcps=["https://api.example.com/sse"] |
| Agent 通过 Gmail 发送邮件 | Apps | apps=["gmail"] |
| Agent 遵循特定流程 | Skills | skills=["./skills/code-review"] |
| Agent 引用公司文档 | Knowledge | knowledge_sources=[pdf_source] |
| Agent 既搜索网页又遵循审核规范 | Tools + Skills | 一起使用两者 |
在实践中,agents 往往会 同时使用多种能力类型。下面是一个真实示例:
from crewai import Agentfrom crewai_tools import SerperDevTool, FileReadTool, CodeInterpreterTool
# 一个功能齐全的研究 agentresearcher = Agent( role="Senior Research Analyst", goal="Produce comprehensive market analysis reports", backstory="Expert analyst with deep industry knowledge",
# ACTION: agent 能做什么 tools=[ SerperDevTool(), # 搜索网页 FileReadTool(), # 读取本地文件 CodeInterpreterTool(), # 运行 Python 代码进行分析 ], mcps=["https://data-api.example.com/sse"], # 访问远程数据 API apps=["google_sheets"], # 写入 Google Sheets
# CONTEXT: agent 知道什么 skills=["./skills/research-methodology"], # 如何做研究 knowledge_sources=[company_docs], # 公司专属数据)| Feature | Tools | MCPs | Apps | Skills | Knowledge |
|---|---|---|---|---|---|
| 给 agent 动作能力 | ✅ | ✅ | ✅ | ❌ | ❌ |
| 修改 prompt | ❌ | ❌ | ❌ | ✅ | ✅ |
| 需要代码 | Yes | 仅配置 | 仅配置 | 仅 Markdown | 仅配置 |
| 本地运行 | Yes | Depends | Yes (with env var) | N/A | Yes |
| 需要 API keys | 每个 tool | 每个 server | Integration token | No | 仅 embedder |
| 设置在 Agent 上 | tools=[] | mcps=[] | apps=[] | skills=[] | knowledge_sources=[] |
| 设置在 Crew 上 | ❌ | ❌ | ❌ | skills=[] | knowledge_sources=[] |
准备进一步了解每种能力类型吗?