跳转到内容

Agent 仓库

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

Agent Repositories

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

Agent Repositories

你可以在代码中使用 from_repository 参数从仓库加载 agents,并在本地运行:

from crewai import Agent
# Create an agent by loading it from a repository
# The agent is loaded with all its predefined configurations
researcher = Agent(
from_repository="market-research-agent"
)

你可以通过在配置中提供值来覆盖仓库里的特定设置:

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
)
from crewai import Crew, Agent, Task
# Load agents from repositories
researcher = Agent(
from_repository="market-research-agent"
)
writer = Agent(
from_repository="content-writer-agent"
)
# Create tasks
research_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 crew
crew = Crew(
agents=[researcher, writer],
tasks=[research_task, writing_task],
verbose=True
)
# Run the crew
result = crew.kickoff()

示例:在 kickoff() 中使用仓库 agents

Section titled “示例:在 kickoff() 中使用仓库 agents”

你也可以直接把仓库 agents 与 kickoff() 方法一起使用,以获得更简单的交互:

from crewai import Agent
from pydantic import BaseModel
from typing import List
# Define a structured output format
class MarketAnalysis(BaseModel):
key_trends: List[str]
opportunities: List[str]
recommendation: str
# Load an agent from repository
analyst = Agent(
from_repository="market-analyst-agent",
verbose=True
)
# Get a free-form response
result = analyst.kickoff("Analyze the AI market in 2025")
print(result.raw) # Access the raw response
# Get structured output
structured_result = analyst.kickoff(
"Provide a structured analysis of the AI market in 2025",
response_format=MarketAnalysis
)
# Access structured data
print(f"Key Trends: {structured_result.pydantic.key_trends}")
print(f"Recommendation: {structured_result.pydantic.recommendation}")
  1. 命名规范:为你的仓库 agents 使用清晰、描述性强的名称
  2. 文档:为每个 agent 提供完整说明
  3. 工具管理:确保仓库 agent 引用的工具在你的环境中可用
  4. 访问控制:管理权限,确保只有授权团队成员可以修改仓库 agents

要在不同组织之间切换或查看当前组织,请使用 CrewAI CLI:

Terminal window
# View current organization
crewai org current
# Switch to a different organization
crewai org switch <org_id>
# List all available organizations
crewai org list