Skip to content

협업 (Collaboration)

에이전트 하나로 해결하기 어려운 일이 많아요. 조사가 필요한 부분, 글쓰기가 필요한 부분, 검토가 필요한 부분이 섞여 있죠. CrewAI는 여러 에이전트가 서로 업무를 위임(delegate) 하고 질문(ask question) 을 주고받으며 한 팀처럼 일할 수 있게 해줘요. 이 글에서는 협업을 켜는 방법부터 실제 코드, 그리고 운영할 때 챙겨야 할 관점까지 하나씩 짚어볼게요.

개요

CrewAI에서 협업은 에이전트들이 서로의 전문성을 활용하도록 업무를 위임하고 질문을 던지는 것으로 이뤄져요. 에이전트에 allow_delegation=True를 주면 이 협업 도구들이 자동으로 켜져요. 이 설정 하나가 "각자 자기 일만 하는 개인"을 "서로 돕는 팀"으로 바꾸는 핵심이에요.

Quick Start: 협업 켜기

협업은 아주 단순하게 시작해요. Agent를 만들 때 allow_delegation=True만 넣으면 돼요.

from crewai import Agent, Crew, Task

# Enable collaboration for agents
researcher = Agent(
    role="Research Specialist",
    goal="Conduct thorough research on any topic",
    backstory="Expert researcher with access to various sources",
    allow_delegation=True,  # 🔑 Key setting for collaboration
    verbose=True
)

writer = Agent(
    role="Content Writer",
    goal="Create engaging content based on research",
    backstory="Skilled writer who transforms research into compelling content",
    allow_delegation=True,  # 🔑 Enables asking questions to other agents
    verbose=True
)

# Agents can now collaborate automatically
crew = Crew(
    agents=[researcher, writer],
    tasks=[...],
    verbose=True
)

verbose=True가 붙어 있으면 에이전트들이 실제로 어떻게 협업하는지 실행 로그로 확인할 수 있어요. 처음에 동작을 눈으로 볼 때 특히 유용하죠.

에이전트 협업은 어떻게 동작하나요

allow_delegation=True를 주면 CrewAI가 에이전트에게 두 가지 도구를 자동으로 부여해요. 에이전트가 이 도구를 골라서 호출하는 방식으로 협업이 일어나요.

1. Delegate Work Tool (업무 위임 도구)

동료에게 특정 전문성이 필요한 작업을 넘길 때 써요. 에이전트는 자동으로 이 도구를 갖게 돼요.

# Agent automatically gets this tool:
# Delegate work to coworker(task: str, context: str, coworker: str)
  • task: 동료에게 맡길 작업 내용
  • context: 작업을 이해하는 데 필요한 맥락
  • coworker: 일을 넘길 대상 에이전트

2. Ask Question Tool (질문 도구)

동료에게 구체적인 질문을 던져 정보를 얻을 때 써요. 위임보다 가볍게, 필요한 정보만 물어보는 도구예요.

# Agent automatically gets this tool:
# Ask question to coworker(question: str, context: str, coworker: str)

둘 다 같은 형태의 인자를 받는다는 점을 기억해두면 좋아요. 차이는 "일을 넘기느냐" vs "정보를 물어보느냐" 예요.

협업이 실제로 일어나는 예시

조사 → 글쓰기 → 검토로 이어지는 콘텐츠 제작 흐름을 예로 들어볼게요. 각 에이전트가 서로 다른 역할을 맡고, allow_delegation=True로 협업을 켠 상태예요.

from crewai import Agent, Crew, Task, Process

# Create collaborative agents
researcher = Agent(
    role="Research Specialist",
    goal="Find accurate, up-to-date information on any topic",
    backstory="You're a meticulous researcher with expertise in finding ...",
    allow_delegation=True,
    verbose=True
)

# ... writer, editor 에이전트 정의 (모두 allow_delegation=True)

editor = Agent(
    role="Editor",
    goal="Ensure content quality and consistency",
    backstory="You're an experienced editor with an eye for detail, "
              "ensuring content meets high standards for clarity and accuracy.",
    allow_delegation=True,
    verbose=True
)

# Create a task that encourages collaboration
article_task = Task(
    description="Write an article on AI trends...",
    expected_output="A well-researched, well-written article",
    agent=writer  # Writer leads, but can delegate research to researcher
)

# Create collaborative crew
crew = Crew(
    agents=[researcher, writer, editor],
    tasks=[article_task],
    process=Process.sequential,
    verbose=True
)

result = crew.kickoff()

핵심은 article_taskagent=writer예요. 글쓰기를 주도하지만, 조사가 필요하면 researcher에게 위임하고 모호한 부분은 질문으로 채울 수 있어요. Process.sequential이라 에이전트들은 순서대로 흐르는데, 그 안에서도 협업 도구를 통해 동료를 부르는 구조예요.

협업 패턴

패턴: 단일 작업에서의 협업

Task 안에서 여러 역할을 명시해 협업을 유도할 수도 있어요. 작업 설명에 "누가 무엇을 맡을지"를 적어두면 각 에이전트가 자기 영역을 맡아요.

collaborative_task = Task(
    description="""Create a marketing strategy for a new AI product.

    Writer: Focus on messaging and content strategy
    Researcher: Provide market analysis and competitor insights
    ...
    """,
    expected_output="A complete marketing strategy",
    agent=some_agent
)

작업 설명만으로 역할 분담을 지시하니, 명시적으로 allow_delegation에 기대지 않아도 구조가 잡히는 방식이에요.

계층형 협업 (Hierarchical Collaboration)

에이전트들의 협업을 매니저가 조율하게 하는 방식도 있어요. 매니저가 업무를 배분하고, 일반 에이전트는 자기 전문 분야에 집중하도록 allow_delegation=False를 주는 게 일반적이에요.

from crewai import Agent, Crew, Task, Process

# Manager agent coordinates the team
manager = Agent(
    role="Project Manager",
    goal="Coordinate team efforts and ensure project success",
    backstory="Experienced project manager skilled at delegation and quality control",
    allow_delegation=True
)

researcher = Agent(
    role="Researcher",
    goal="Gather market data",
    backstory="...",
    allow_delegation=False,  # Specialists focus on their expertise
    verbose=True
)

writer = Agent(
    role="Writer",
    goal="Create compelling content",
    backstory="Skilled writer who creates engaging content",
    allow_delegation=False,
    verbose=True
)

# Manager-led task
project_task = Task(
    description="Create a comprehensive market analysis report with recommendations",
    expected_output="Executive summary, detailed analysis, and strategic recommendations",
    agent=manager  # Manager will delegate to specialists
)

# Hierarchical crew
crew = Crew(
    agents=[manager, researcher, writer],
    tasks=[project_task],
    process=Process.hierarchical,  # Manager coordinates everything
    manager_llm="gpt-4o",  # Specify LLM for manager
    verbose=True
)

Process.hierarchical로 바꾸면 매니저가 모든 걸 조율해요. manager_llm="gpt-4o"처럼 매니저가 쓸 LLM을 따로 지정할 수 있다는 점도 기억해두세요. 매니저는 판단과 배분이 핵심이라 더 강한 모델을 주는 경우가 많아요.

협업 모범 사례

명확한 역할 정의

협업 품질은 역할이 얼마나 선명한지에 크게 좌우돼요. 역할이 겹치거나 모호하면 누가 무엇을 맡아야 할지 에이전트도 헷갈려요.

# ✅ Good: Specific, complementary roles
researcher = Agent(role="Market Research Analyst", ...)
writer = Agent(role="Technical Content Writer", ...)

# ❌ Avoid: Overlapping or vague roles
agent1 = Agent(role="General Assistant", ...)
agent2 = Agent(role="Helper", ...)

"General Assistant" 같은 모호한 역할 두 개보다, "Market Research Analyst"와 "Technical Content Writer"처럼 서로 보완되는 구체적 역할이 협업에서 훨씬 잘 동작해요.

고급 협업 기능

커스텀 협업 규칙

에이전트의 backstory에 협업 지침을 적어두면, 그 에이전트가 어떻게 협업할지 방향을 잡아줄 수 있어요.

agent = Agent(
    role="Senior Developer",
    backstory="""You lead development projects and coordinate with team members.

    Collaboration guidelines:
    - Delegate research tasks to the Research Analyst
    ...
    """,
    ...
)

역할(role)이 "무엇을 하는지"를 정한다면, backstory의 협업 가이드라인은 "누구한테 무엇을 넘기고 어떻게 협력하는지"를 정해요. 규모가 커질수록 이 몇 줄이 협업 방향을 안정적으로 잡아줘요.

협업 모니터링

step_callback으로 각 단계의 출력을 받아 실제로 위임·질문이 일어났는지 추적할 수 있어요.

def track_collaboration(output):
    """Track collaboration patterns"""
    if "Delegate work to coworker" in output.raw:
        print("🤝 Delegation occurred")
    if "Ask question to coworker" in output.raw:
        print("❓ Question asked")

crew = Crew(
    agents=[...],
    tasks=[...],
    step_callback=track_collaboration,  # Monitor collaboration
    verbose=True
)

출력에 "Delegate work to coworker""Ask question to coworker" 문자열이 있는지 검사하는 방식이에요. 협업이 의도대로 일어나는지, 혹은 에이전트가 무한정 동료를 부르고 있진 않은지 운영 관점에서 확인하는 데 유용해요.

메모리와 학습

memory=True를 주면 에이전트가 과거 협업을 기억하고, 시간이 지나면서 위임 결정을 개선해요.

agent = Agent(
    role="Content Lead",
    memory=True,  # Remembers past interactions
    allow_delegation=True,
    verbose=True
)

메모리를 켜면 "지난번엔 누구한테 뭘 맡겼고 결과가 어땠는지"를 바탕으로 더 나은 협업 선택을 하게 돼요. 반복되는 워크플로우라면 이 설정이 협업 품질을 점점 끌어올려줘요.

더 알아보기

협업을 직접 시작해보려면 이 순서를 따라가 보세요.

  • 예제부터: 기본 협업 예제로 동작을 먼저 확인해요
  • 역할 조합 실험: 서로 다른 역할 조합을 바꿔가며 어떤 조합이 잘 맞는지 시도해봐요
  • 상호작용 관찰: verbose=True로 협업이 실제로 어떻게 일어나는지 눈으로 보세요
  • 작업 설명 최적화: 명확한 작업 설명일수록 협업도 잘 일어나요

협업은 개별 AI 에이전트들을 복잡하고 다면적인 문제를 함께 풀 수 있는 강력한 팀으로 바꿔줘요. 팀원을 몇 명 만들지, 누가 매니저를 맡을지, 역할을 어떻게 나눌지 — 여기서 시작해서 점점 확장해나가면 돼요.