Crewai multi agent

From findscripter/everything-skills · View interactive version

Crewai multi agent is an AI agent skill from the GitHub repository findscripter/everything-skills. 当需要用 Python 搭建角色分工、可协作的多智能体团队时使用;用 CrewAI 设计 Agent 人设(role/goal/backstory)、定义 Task、编排 Crew(顺序/层级流程)并产出可运行的多智能体管线;不适用于显式状态机图编排(用 LangGraph)、单 Agent 简单脚本或非 Python 场景;触发词:crewai、多智能体团队、角色化 Agent、crew、collaborative agents

How to use this skill

Skill file

何时使用

适用:

不该用(负边界):

前置:Python 3.10+、安装 crewai、具备 LLM API(OpenAI/Anthropic/Ollama)、理解「委派」概念。

步骤

  1. 设计 Agent 人设:每个 Agent 写清 role(身份)、goal(目标,可含 {topic} 占位)、backstory(背景,强化专长)。
  2. 定义 Task:写 description(含步骤要求)、expected_output(明确产物格式)、绑定 agent,依赖前序结果用 context 引用。
  3. 选流程:任务线性依赖用 Process.sequential;需要动态调度、合并结果用 Process.hierarchical 并指定 manager_llm。
  4. 编排 Crew:传入 agents、tasks、process,按需开 memory、planning、tools。
  5. 运行:crew.kickoff(inputs={...}),多阶段分支用 Flow。
  6. 配置建议:优先用 YAML(agents.yaml / tasks.yaml)配置 + @CrewBase 类,便于维护。

指令

示例

YAML + CrewBase 最小可运行骨架(顺序流程,写作 Crew):

# config/agents.yaml
researcher:
  role: "Senior Research Analyst"
  goal: "Find comprehensive, accurate information on {topic}"
  backstory: "You are an expert researcher known for thorough, accurate research."
  tools: [SerperDevTool, WebsiteSearchTool]
  verbose: true
writer:
  role: "Content Writer"
  goal: "Create engaging, well-structured content"
  backstory: "You transform research into compelling narratives."
  verbose: true
# config/tasks.yaml
research_task:
  description: "Research the topic: {topic}. Focus on key facts, recent developments, expert and contrarian views. Cite sources."
  agent: researcher
  expected_output: "A report with executive summary, bulleted findings, sources cited."
writing_task:
  description: "Using the research, write an 800-1000 word article about {topic} with clear headers and an actionable conclusion."
  agent: writer
  expected_output: "A polished article ready for publication"
  context: [research_task]   # 复用研究任务输出
# crew.py
from crewai import Agent, Task, Crew, Process
from crewai.project import CrewBase, agent, task, crew

@CrewBase
class ContentCrew:
    agents_config = 'config/agents.yaml'
    tasks_config = 'config/tasks.yaml'

    @agent
    def researcher(self) -> Agent: return Agent(config=self.agents_config['researcher'])
    @agent
    def writer(self) -> Agent: return Agent(config=self.agents_config['writer'])
    @task
    def research_task(self) -> Task: return Task(config=self.tasks_config['research_task'])
    @task
    def writing_task(self) -> Task: return Task(config=self.tasks_config['writing_task'])
    @crew
    def crew(self) -> Crew:
        return Crew(agents=self.agents, tasks=self.tasks,
                    process=Process.sequential, verbose=True)

# main.py
result = ContentCrew().crew().kickoff(inputs={"topic": "AI Agents in 2025"})

层级流程(经理 Agent 动态调度):

crew = Crew(
    agents=[researcher, analyst, writer],
    tasks=[research_task, analysis_task, writing_task],
    process=Process.hierarchical,
    manager_llm=ChatOpenAI(model="gpt-4o"),  # 经理由谁来分配/委派/合并
    verbose=True,
)
result = crew.kickoff()

Flow 事件驱动 + 路由(多阶段含质检分支):

from crewai.flow.flow import Flow, listen, start, router

class ContentFlow(Flow):
    @start()
    def gather(self):
        self.topic = self.inputs.get("topic", "AI"); return {"topic": self.topic}
    @listen(gather)
    def research(self, req):
        self.research = ResearchCrew().crew().kickoff(inputs=req).raw
    @router(research)
    def quality_check(self, _):
        return "revise" if self.needs_revision(self.research) else "publish"
    @listen("publish")
    def publish(self): return {"status": "published"}

flow = ContentFlow(); flow.kickoff(inputs={"topic": "AI Agents"})

注意事项

互见


采编自 sickn33/antigravity-awesome-skills(MIT),上游原条目源自 vibeship-spawner-skills(Apache 2.0)。

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.