跳转到主要内容

文档索引

获取完整文档索引: https://docs.crewai.com.cn/llms.txt

在深入了解之前,请使用此文件来浏览所有可用页面。

概述

CrewAI 代理可以通过五种不同的能力类型进行扩展,每种类型都有不同的用途。理解何时使用每种能力——以及它们如何协同工作——是构建高效代理的关键。

工具

可调用函数——赋予代理采取行动的能力。例如网络搜索、文件操作、API 调用、代码执行等。

MCP 服务器

远程工具服务器——通过模型上下文协议 (MCP) 将代理连接到外部工具服务器。效果与工具相同,但托管在外部。

应用

平台集成——通过 CrewAI 平台将代理连接到 SaaS 应用(如 Gmail、Slack、Jira、Salesforce)。通过平台集成令牌在本地运行。

技能 (Skills)

领域专业知识——将指令、准则和参考资料注入到代理的提示词 (Prompt) 中。技能告诉代理如何思考

知识

检索事实——通过语义搜索 (RAG) 为代理提供来自文档、文件和 URL 的数据。知识告诉代理需要了解什么

关键区别

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

行动能力 (Tools, MCPs, Apps)

这些赋予了代理做事的能力——调用 API、读取文件、搜索网页、发送电子邮件。在执行时,这三种能力都会解析为相同的内部格式(BaseTool 实例),并出现在代理可以调用的统一工具列表中。
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
)

背景能力 (Skills, Knowledge)

这些会修改代理的提示词——在代理开始推理之前注入专业知识、指令或检索到的数据。它们不会赋予代理新的动作,而是塑造代理的思维方式以及它们可以访问的信息。
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 调用远程 APIMCPsmcps=["https://api.example.com/sse"]
代理通过 Gmail 发送邮件应用apps=["gmail"]
代理遵循特定程序技能 (Skills)skills=["./skills/code-review"]
代理参考公司文档知识knowledge_sources=[pdf_source]
代理搜索网页并遵循审核指南工具 + 技能两者结合使用

组合能力

在实践中,代理通常结合使用多种能力类型。以下是一个实际案例。
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
)

对比表

特性工具MCPs应用技能 (Skills)知识
赋予代理行动能力
修改提示词
需要代码仅配置仅配置仅 Markdown仅配置
本地运行视情况而定是(带环境变量)不适用
需要 API 密钥按工具按服务器集成令牌仅嵌入器 (Embedder)
在 Agent 上设置tools=[]mcps=[]apps=[]skills=[]knowledge_sources=[]
在 Crew 上设置skills=[]knowledge_sources=[]

深入研究

准备好了解更多关于每种能力类型的信息了吗?

工具

创建自定义工具,使用 75+ 个开源工具库,配置缓存和异步执行。

MCP 集成

通过 stdio、SSE 或 HTTP 连接到 MCP 服务器。过滤工具,配置身份验证。

技能 (Skills)

使用 SKILL.md 构建技能包,注入领域专业知识,使用渐进式披露。

知识

从 PDF、CSV、URL 等添加知识。配置嵌入器和检索功能。