跳转到内容

Agent 能力

CrewAI agents 可以通过 五种不同的能力类型 进行扩展,每一种都承担不同的职责。理解何时使用哪一种,以及它们如何协同工作,是构建高效 agents 的关键。


最重要的一点是:这些能力分成两类

它们赋予 agents 执行动作的能力 - 调用 API、读取文件、搜索网页、发送邮件。执行时,这三者都会解析成同一种内部格式(BaseTool 实例),并出现在 agent 可以调用的统一工具列表中。

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()], # 本地工具
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], # 检索到的事实
)

你需要…使用示例
Agent 搜索网页Toolstools=[SerperDevTool()]
Agent 通过 MCP 调用远程 APIMCPsmcps=["https://api.example.com/sse"]
Agent 通过 Gmail 发送邮件Appsapps=["gmail"]
Agent 遵循特定流程Skillsskills=["./skills/code-review"]
Agent 引用公司文档Knowledgeknowledge_sources=[pdf_source]
Agent 既搜索网页又遵循审核规范Tools + Skills一起使用两者

在实践中,agents 往往会 同时使用多种能力类型。下面是一个真实示例:

from crewai import Agent
from crewai_tools import SerperDevTool, FileReadTool, CodeInterpreterTool
# 一个功能齐全的研究 agent
researcher = 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], # 公司专属数据
)

FeatureToolsMCPsAppsSkillsKnowledge
给 agent 动作能力
修改 prompt
需要代码Yes仅配置仅配置仅 Markdown仅配置
本地运行YesDependsYes (with env var)N/AYes
需要 API keys每个 tool每个 serverIntegration tokenNo仅 embedder
设置在 Agent 上tools=[]mcps=[]apps=[]skills=[]knowledge_sources=[]
设置在 Crew 上skills=[]knowledge_sources=[]

准备进一步了解每种能力类型吗?