Build multi-agent workflows using CrewAI patterns
Build multi-agent workflows using CrewAI patterns
Build production-ready multi-agent workflows using CrewAI best practices.
Create specialized agents with clear roles:
from crewai import Agent
researcher = Agent(
role='Research Analyst',
goal='Find accurate information on topics',
backstory='Expert researcher with attention to detail',
verbose=True,
memory=True,
max_iter=3
)
writer = Agent(
role='Content Writer',
goal='Create engaging content from research',
backstory='Skilled writer who transforms data into stories',
verbose=True
)
Create tasks with clear expected outputs:
from crewai import Task
research_task = Task(
description='Research the topic: {topic}',
agent=researcher,
expected_output='Comprehensive research report with key findings'
)
writing_task = Task(
description='Write an article based on research',
agent=writer,
expected_output='Engaging article in markdown format',
context=[research_task] # Depends on research
)
Assemble agents and tasks into a crew:
from crewai import Crew, Process
crew = Crew(
agents=[researcher, writer],
tasks=[research_task, writing_task],
process=Process.sequential,
verbose=True,
memory=True
)
result = crew.kickoff(inputs={"topic": "AI Agents"})
print(result.raw)
For complex state management:
from crewai.flow.flow import Flow, listen, start
class MyFlow(Flow):
@start()
def begin(self):
return crew.kickoff(inputs={"topic": "AI"})
@listen(begin)
def process_result(self, result):
return result.raw
flow = MyFlow()
final_result = flow.kickoff()
| File | Purpose |
|||
| agents/ | Agent definitions with roles |
| tasks/ | Task definitions with dependencies |
| crews/ | Crew configurations |
| flows/ | Flow orchestrations (optional) |
| Type | Use Case |
||-|
| Process.sequential | Tasks run one after another |
| Process.hierarchical | Manager delegates to workers |
context parametermemory=True for better contextcrew = Crew(
agents=[researcher, writer, reviewer],
tasks=[research_task, write_task, review_task],
process=Process.sequential
)
crew = Crew(
agents=[manager, worker1, worker2],
tasks=[complex_task],
process=Process.hierarchical,
manager_llm=ChatOpenAI(model='gpt-4')
)
| Issue | Solution |
|-|-|
| Agent loops infinitely | Set max_iter=3 |
| Wrong task order | Use context parameter |
| Tool failures | Add error handling in tools |
| LLM errors | Use max_retry_limit |
CrewAI Flows provide structured event-driven orchestration:
from crewai.flow.flow import Flow, listen, start, router
class ResearchFlow(Flow):
@start()
def gather_requirements(self):
# First step - always runs
return {"topic": self.state.topic}
@listen(gather_requirements)
def research(self, requirements):
# Triggered after gather_requirements
crew = Crew(agents=[researcher], tasks=[research_task])
return crew.kickoff(inputs=requirements)
@router(research)
def evaluate_quality(self, result):
if result.quality_score > 0.8:
return "publish"
return "revise"
@listen("publish")
def publish_results(self, result):
return result
@listen("revise")
def revise_research(self, result):
return self.research(result)
flow = ResearchFlow()
flow.kickoff(inputs={"topic": "AI trends"})
from crewai import Agent
from crewai_tools import MCPServerAdapter
# Connect to MCP servers for tool access
mcp_tools = MCPServerAdapter(
server_params={"url": "http://localhost:3000/mcp"}
).tools
agent = Agent(
role="Data Analyst",
tools=mcp_tools,
llm="gpt-4"
)
crew = Crew(
agents=[...],
tasks=[...],
memory=True, # Enable short-term + long-term memory
embedder={
"provider": "openai",
"config": {"model": "text-embedding-3-small"}
},
max_rpm=10, # Rate limiting guardrail
max_tokens=4096 # Token limit guardrail
)
{directories.knowledge}/crewai-patterns.json{directories.templates}/ai/crewai/{directories.docs}/examples/04-multi-agent-research-system/This skill should be used when strict adherence to the defined process is required.
npx skills add gitwalter/orchestrating-crewai-workflows下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer