🤖 AI/ML

CrewAI

A framework in which multiple AI agents collaborate

📖 Detailed Explanation

CrewAI is a multi-agent orchestration framework in which multiple AI agents collaborate like a team to perform complex tasks. It assigns each agent a Role, a Goal, and a Backstory, and executes tasks sequentially or in parallel to implement complex workflows that are difficult to achieve with a single LLM.

CrewAI, released as open source by Joao Moura in late 2023, was born under the influence of autonomous agent projects such as AutoGPT and BabyAGI. It is integrated with LangChain, and with its differentiated approach of role-based agent design, it grew rapidly, reaching more than 20,000 GitHub stars.

CrewAI's core components are Agent, Task, Crew, and Tool. An Agent is an AI persona with a specific role, and a Task is a unit of work for an agent to perform. A Crew manages a team of agents, and a Tool provides external capabilities such as web search and file reading. The order of task execution is controlled by a Sequential or Hierarchical process.

In practice, it is used for research automation, content generation pipelines, code review systems, and more. For example, a research Crew can be configured as a three-stage workflow in which a researcher agent collects information, an analyst agent reviews it, and a writer agent writes the report.

💻 Code Example

from crewai import Agent, Task, Crew, Process
from crewai_tools import SerperDevTool

# 도구 설정
search_tool = SerperDevTool()

# 에이전트 정의
researcher = Agent(
    role="시장 조사 전문가",
    goal="AI 시장 동향에 대한 심층 분석 제공",
    backstory="10년 경력의 기술 시장 분석가로, 트렌드 예측에 강점이 있습니다.",
    tools=[search_tool],
    verbose=True,
    llm="gpt-4o"
)

writer = Agent(
    role="기술 콘텐츠 작가",
    goal="복잡한 기술 정보를 이해하기 쉬운 콘텐츠로 변환",
    backstory="기술 매거진 편집장 출신으로, 전문 용어를 쉽게 풀어쓰는 능력이 뛰어납니다.",
    verbose=True,
    llm="gpt-4o"
)

# 태스크 정의
research_task = Task(
    description="2024년 생성형 AI 시장 규모와 주요 플레이어를 조사하세요.",
    expected_output="시장 규모, 성장률, Top 5 기업 정보가 포함된 분석 보고서",
    agent=researcher
)

writing_task = Task(
    description="조사 결과를 바탕으로 경영진 브리핑 문서를 작성하세요.",
    expected_output="A4 1페이지 분량의 요약 보고서",
    agent=writer,
    context=[research_task]  # research_task 결과를 컨텍스트로 사용
)

# Crew 구성 및 실행
crew = Crew(
    agents=[researcher, writer],
    tasks=[research_task, writing_task],
    process=Process.sequential,  # 순차 실행
    verbose=True
)

# 실행
result = crew.kickoff()
print(result)

🗣️ Say It Like This in Practice

At an AI automation project kickoff

"We want to automate the weekly competitor analysis report. With CrewAI, we can set up three agents: a research agent, an analysis agent, and a report-writing agent. Since each agent works sequentially and passes context along, the results are much more systematic than with a single prompt."

In a tech stack selection meeting

"Comparing LangGraph and CrewAI, LangGraph is based on a state machine, so it allows precise control, while CrewAI is role-based, so it is more intuitive. Our team has no experience with agents, so it would be best to start with CrewAI and migrate to LangGraph when the complexity increases."

In a code review

"The agent's backstory is too short. In CrewAI, the backstory is not just a description but the context that makes the LLM immerse itself in the role. If you write it specifically, like 'a senior analyst with 10 years of experience who has worked at both startups and large corporations,' the output quality changes dramatically."

⚠️ Common Mistakes & Cautions

1.
Token cost explosion

In a multi-agent system, token usage increases exponentially because context is passed between agents. A five-stage workflow with three agents can cost more than 10 times as much as a single call. Limit it with the max_iter and max_rpm settings.

2.
Infinite loop risk

If an agent fails to complete a task and keeps retrying, it can fall into an infinite loop. Be sure to set timeout and max_retries on the Task, and implement fallback logic for failures.

3.
Difficult debugging

When multiple agents interact, it is hard to identify the cause when a problem occurs. Enable logging with verbose=True, and implement a callback that saves each agent's intermediate results to a file.

🔗 Related Terms

📚 Learn More