Become an Agentic Architect

Agents Collaboration in CrewAI

In CrewAI, collaboration lets agents work together like a real team: they can delegate work and ask each other questions instead of solving everything alone. You turn collaboration on by giving agents permission to delegate and by designing clear roles, tasks, and workflows.


1. Turning Collaboration On: allow_delegation

Collaboration is opt‑in at the agent level.

# python
from crewai import Agent, Crew, Task

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

writer = Agent(
    role="Content Writer",
    goal="Create engaging content based on research",
    backstory="Transforms research into compelling content",
    allow_delegation=True,   # 🔑 can ask and delegate to others
    verbose=True,
)

crew = Crew(
    agents=[researcher, writer],
    tasks=[...],
    verbose=True,
)
  • When allow_delegation=True, CrewAI automatically equips that agent with collaboration tools.
  • Those tools let the agent delegate tasks and ask questions to other agents in the same crew.

2. The Two Built‑In Collaboration Tools

When delegation is enabled, the agent silently gains two tools behind the scenes.

2.1 Delegate Work Tool

Used when an agent wants a coworker to handle a subtask.

Delegate work to coworker(task: str, context: str, coworker: str)
  • task: What you want them to do.
  • context: Everything they need to know (they don’t share your memory).
  • coworker: Name/role of the target agent.

CrewAI routes this to the selected coworker agent and returns that agent’s result.

2.2 Ask Question Tool

Used when an agent only needs information or an opinion.

Ask question to coworker(question: str, context: str, coworker: str)
  • question: The exact question you’re asking.
  • context: Background needed to answer correctly.
  • coworker: Target agent.

This is perfect for clarification, fact checks, and specialist input.


3. Collaboration in Action: Content Team Example

Below is a full example of three collaborative agents working on a single article.

from crewai import Agent, Crew, Task, Process

researcher = Agent(
    role="Research Specialist",
    goal="Find accurate, up-to-date information on any topic",
    backstory=(
        "Meticulous researcher who finds reliable sources and fact-checks "
        "information across domains."
    ),
    allow_delegation=True,
    verbose=True,
)

writer = Agent(
    role="Content Writer",
    goal="Create engaging, well-structured content",
    backstory=(
        "Skilled writer who turns research into compelling, readable content "
        "for different audiences."
    ),
    allow_delegation=True,
    verbose=True,
)

editor = Agent(
    role="Content Editor",
    goal="Ensure content quality and consistency",
    backstory=(
        "Experienced editor with an eye for detail, ensuring clarity and accuracy."
    ),
    allow_delegation=True,
    verbose=True,
)

article_task = Task(
    description="""
    Write a comprehensive 1000-word article about 'The Future of AI in Healthcare'.
    The article should include:
    - Current AI applications in healthcare
    - Emerging trends and technologies
    - Potential challenges and ethical considerations
    - Expert predictions for the next 5 years

    Collaborate with your teammates to ensure accuracy and quality.
    """,
    expected_output=(
        "A well-researched, engaging 1000-word article with proper structure and citations"
    ),
    agent=writer,  # writer leads but can delegate to researcher/editor
)

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

result = crew.kickoff()

What happens conceptually:

  • The writer leads the main task.
  • The writer can delegate research work to the researcher.
  • The writer or researcher can ask the editor to review and refine.

You don’t script those steps manually; the LLM uses the collaboration tools based on the prompt, roles, and instructions.


4. Common Collaboration Patterns

4.1 Pattern 1 – Research → Write → Edit (multi‑task pipeline)

Use separate tasks with context to pass outputs along.

research_task = Task(
    description="Research the latest developments in quantum computing.",
    expected_output="Comprehensive research summary with key findings and sources.",
    agent=researcher,
)

writing_task = Task(
    description="Write an article based on the research findings.",
    expected_output="Engaging 800-word article about quantum computing.",
    agent=writer,
    context=[research_task],  # gets research summary as context
)

editing_task = Task(
    description="Edit and polish the article for publication.",
    expected_output="Publication-ready article with improved clarity and flow.",
    agent=editor,
    context=[writing_task],   # gets article draft as context
)

Here collaboration comes from task structure and clear hand‑offs, even without delegation.

4.2 Pattern 2 – Collaborative Single Task

One task, but multiple agents collaborate via delegation.

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.

    Work together to create a comprehensive strategy.
    """,
    expected_output="Complete marketing strategy with research backing.",
    agent=writer,  # lead agent, can delegate to researcher
)

This is useful when you want the conversation to stay within one task but still leverage multiple roles.


5. Hierarchical Collaboration: Manager + Specialists

For complex projects, you can mix collaboration with a hierarchical process.

from crewai import Agent, Crew, Task, Process

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

researcher = Agent(
    role="Researcher",
    goal="Provide accurate research and analysis",
    backstory="Expert researcher with deep analytical skills.",
    allow_delegation=False,  # focus on execution
    verbose=True,
)

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

project_task = Task(
    description="Create a comprehensive market analysis report with recommendations.",
    expected_output="Executive summary, detailed analysis, and strategic recommendations.",
    agent=manager,  # manager delegates work to specialists
)

crew = Crew(
    agents=[manager, researcher, writer],
    tasks=[project_task],
    process=Process.hierarchical,
    manager_llm="gpt-4o",  # required for hierarchical
    verbose=True,
)
  • The manager agent plans the work, delegates parts to researcher/writer, and validates outputs.
  • Specialists focus on their domain; you usually leave allow_delegation=False so they don’t re‑delegate randomly.

6. Best Practices for Effective Collaboration

6.1 Design clear, complementary roles

# ✅ Good
researcher = Agent(role="Market Research Analyst", ...)
writer    = Agent(role="Technical Content Writer", ...)
editor    = Agent(role="Copy Editor", ...)

# ❌ Vague
agent1 = Agent(role="Assistant", ...)
agent2 = Agent(role="Helper", ...)
  • Each agent should have a sharp specialization, so the LLM knows who to delegate to.

6.2 Enable delegation strategically

lead_agent = Agent(
    role="Content Lead",
    allow_delegation=True,   # coordinator
    ...
)

specialist_agent = Agent(
    role="Data Analyst",
    allow_delegation=False,  # focus only on analysis
    ...
)
  • Allow delegation for coordinators / leads, and optionally disable for narrow specialists to avoid delegation loops.

6.3 Use context to share information

writing_task = Task(
    description="Write article based on research.",
    expected_output="Polished article.",
    agent=writer,
    context=[research_task],  # shares research output
)
  • Good context reduces back‑and‑forth questions and makes collaboration more efficient.

6.4 Write collaboration‑friendly task descriptions

Task(
    description="""
    Research competitors in the AI chatbot space.
    Focus on: pricing models, key features, and target markets.
    Provide data in a structured format.

    Collaborate with the writer if you need help turning data into narrative.
    """,
    ...
)
  • Be explicit about who should do what, when to ask for help, and what format to return.

7. Troubleshooting Collaboration

7.1 Agents don’t seem to collaborate

Symptom: No delegation or questions, everyone works alone.

  • Check that allow_delegation=True for the agents who should coordinate.[web:83][web:86]
  • Ensure roles are distinct so the LLM sees a reason to delegate.
  • Add collaboration hints in the task description (“collaborate with your teammates…”).

7.2 Too much back‑and‑forth

Symptom: Agents keep asking each other questions, progress is slow.

  • Improve task descriptions and context so they need fewer clarifications.
  • Narrow roles (e.g., writer decides structure; researcher only provides facts).
  • Use a manager agent to centralize decisions in complex crews.

7.3 Delegation loops

Symptom: Agents keep delegating work back and forth.

  • Give one agent the “final say” (e.g., manager or lead).
  • Disable delegation for some specialists (allow_delegation=False).

8. Monitoring and Evolving Collaboration

8.1 Monitor collaboration with callbacks

def track_collaboration(output):
    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,
    verbose=True,
)
  • Use callbacks or logs to see how much delegation and Q&A actually happen.

8.2 Use memory to improve over time

agent = Agent(
    role="Content Lead",
    memory=True,           # remembers past collaborations
    allow_delegation=True,
    verbose=True,
)
  • With memory=True, agents can remember what worked before and refine delegation decisions in future runs

9. How to think about planning collaboration

Here is a useful way to frame collaboration:

  • Level 1: Single agent per task – no collaboration.
  • Level 2: Sequential tasks + context – hand‑offs without delegation.
  • Level 3: allow_delegation=True – agents can call each other as tools.
  • Level 4: Hierarchical + collaboration – manager orchestrates specialists in complex projects.

The key mindset: you are not just writing prompts; you are designing a team with clear roles, communication channels, and collaboration rules.