CrewAI enables role-based agent teams. Each agent has a role, goal, and backstory — forming a crew that works together on tasks.
pip install crewai crewai-tools
from crewai import Agent, Task, Crew
researcher = Agent(
role="Senior Researcher",
goal="Find accurate information",
backstory="Expert researcher with 20 years experience",
tools=[],
verbose=True
)
writer = Agent(
role="Content Writer",
goal="Write compelling content based on research",
backstory="Award-winning technology writer",
)
research_task = Task(
description="Research the latest AI agent frameworks",
agent=researcher,
expected_output="A detailed report on AI agent frameworks"
)
write_task = Task(
description="Write a blog post from the research",
agent=writer,
expected_output="A 500-word blog post"
)
crew = Crew(
agents=[researcher, writer],
tasks=[research_task, write_task],
verbose=True
)
result = crew.kickoff()
Build multi-agent financial research teams that gather data, analyze trends, and generate reports.
from crewai_tools import tool
from pydantic import BaseModel
class StockAnalysis(BaseModel):
ticker: str
current_price: float
recommendation: str
@tool("Stock Price Tool")
def get_stock_price(ticker: str) -> float:
"""Get the current stock price for a ticker."""
import yfinance as yf
stock = yf.Ticker(ticker)
return stock.info.get("currentPrice", 0)
CrewAI supports short-term, long-term, and entity memory. Use SQL or vector storage for persistent memory across runs.
Combine multiple agents (data collector, analyst, risk assessor, trader) into a collaborative trading framework.