Agent 仓库
Agent Repositories 允许企业用户在团队和项目之间存储、共享并复用 agent 定义。该功能帮助组织维护一个集中化的标准化 agents 库,从而提升一致性并减少重复劳动。

Agent 仓库的优势
Section titled “Agent 仓库的优势”- 标准化:在整个组织中保持一致的 agent 定义
- 可复用性:创建一次 agent,即可在多个 crews 和项目中使用
- 治理:为 agent 配置实施组织级策略
- 协作:让团队能够共享并在彼此工作的基础上继续构建
创建和使用 Agent 仓库
Section titled “创建和使用 Agent 仓库”- 你必须拥有 CrewAI 账户,可以先试用 free plan。
- 为你的工作流创建具有特定角色和目标的 agents。
- 为每个专用 assistant 配置 tools 和能力。
- 通过可视化界面或 API 集成,将 agents 部署到各个项目中。

从仓库加载 agents
Section titled “从仓库加载 agents”你可以在代码中使用 from_repository 参数从仓库加载 agents,并在本地运行:
from crewai import Agent
# Create an agent by loading it from a repository# The agent is loaded with all its predefined configurationsresearcher = Agent( from_repository="market-research-agent")覆盖仓库设置
Section titled “覆盖仓库设置”你可以通过在配置中提供值来覆盖仓库里的特定设置:
researcher = Agent( from_repository="market-research-agent", goal="Research the latest trends in AI development", # Override the repository goal verbose=True # Add a setting not in the repository)示例:使用仓库 agents 创建 Crew
Section titled “示例:使用仓库 agents 创建 Crew”from crewai import Crew, Agent, Task
# Load agents from repositoriesresearcher = Agent( from_repository="market-research-agent")
writer = Agent( from_repository="content-writer-agent")
# Create tasksresearch_task = Task( description="Research the latest trends in AI", agent=researcher)
writing_task = Task( description="Write a comprehensive report based on the research", agent=writer)
# Create the crewcrew = Crew( agents=[researcher, writer], tasks=[research_task, writing_task], verbose=True)
# Run the crewresult = crew.kickoff()示例:在 kickoff() 中使用仓库 agents
Section titled “示例:在 kickoff() 中使用仓库 agents”你也可以直接把仓库 agents 与 kickoff() 方法一起使用,以获得更简单的交互:
from crewai import Agentfrom pydantic import BaseModelfrom typing import List
# Define a structured output formatclass MarketAnalysis(BaseModel): key_trends: List[str] opportunities: List[str] recommendation: str
# Load an agent from repositoryanalyst = Agent( from_repository="market-analyst-agent", verbose=True)
# Get a free-form responseresult = analyst.kickoff("Analyze the AI market in 2025")print(result.raw) # Access the raw response
# Get structured outputstructured_result = analyst.kickoff( "Provide a structured analysis of the AI market in 2025", response_format=MarketAnalysis)
# Access structured dataprint(f"Key Trends: {structured_result.pydantic.key_trends}")print(f"Recommendation: {structured_result.pydantic.recommendation}")- 命名规范:为你的仓库 agents 使用清晰、描述性强的名称
- 文档:为每个 agent 提供完整说明
- 工具管理:确保仓库 agent 引用的工具在你的环境中可用
- 访问控制:管理权限,确保只有授权团队成员可以修改仓库 agents
要在不同组织之间切换或查看当前组织,请使用 CrewAI CLI:
# View current organizationcrewai org current
# Switch to a different organizationcrewai org switch <org_id>
# List all available organizationscrewai org list