Advanced

Best Practices

Learn real-world patterns, debugging strategies, cost control techniques, production deployment patterns, and common mistakes to avoid with CrewAI.

Real-World Crew Patterns

🔎

Research Crew

Agents: Web Researcher, Data Analyst, Report Writer. Use: Market research, competitive analysis, trend reports.

📝

Content Crew

Agents: SEO Researcher, Writer, Editor. Use: Blog posts, documentation, marketing copy, social media content.

💻

Development Crew

Agents: Architect, Developer, Code Reviewer, Tester. Use: Code generation, bug fixing, code review automation.

👥

Support Crew

Agents: Classifier, Knowledge Agent, Response Writer. Use: Customer support, ticket triage, automated responses.

Debugging Crews

  1. Enable Verbose Mode

    Always set verbose=True on both agents and the crew during development. This shows every reasoning step, tool call, and delegation decision.

  2. Test Agents Individually

    Before combining agents into a crew, test each agent on its own with a simple task. Verify it uses tools correctly and produces the expected output format.

  3. Check Task Dependencies

    If a task produces poor output, check if it received the right context from previous tasks. Print task.output after each task to verify.

  4. Reduce Max Iterations

    If an agent gets stuck in a loop, reduce max_iter to force it to produce output sooner. Default is 25, try 10-15.

Cost Control

Python - Cost-Conscious Configuration
from crewai import Agent, Crew, Process

# Use cheaper models for less critical agents
researcher = Agent(
    role="Researcher",
    goal="Research topic",
    backstory="Expert researcher.",
    llm="gpt-4o-mini",     # Cheaper for research
    max_iter=10,           # Limit iterations
    max_rpm=10,            # Rate limit
)

# Use powerful model for critical tasks
writer = Agent(
    role="Writer",
    goal="Write article",
    backstory="Expert writer.",
    llm="gpt-4o",           # Better model for writing
    max_iter=10,
)

crew = Crew(
    agents=[researcher, writer],
    tasks=[research_task, writing_task],
    process=Process.sequential,  # Cheaper than hierarchical
    verbose=True,
)

Production Deployment

Python - Production Pattern
import os
import logging
from crewai import Crew, Process

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

def run_content_crew(topic: str) -> dict:
    """Run the content creation crew with error handling."""
    try:
        crew = Crew(
            agents=[researcher, writer, editor],
            tasks=[research_task, writing_task, editing_task],
            process=Process.sequential,
            verbose=False,  # Disable in production
            memory=True,
        )

        result = crew.kickoff(inputs={"topic": topic})

        logger.info(f"Crew completed for topic: {topic}")
        return {
            "status": "success",
            "output": str(result),
            "token_usage": result.token_usage,
        }

    except Exception as e:
        logger.error(f"Crew failed: {e}")
        return {"status": "error", "error": str(e)}

Agent Design Guidelines

Do:
  • Give each agent a distinct, non-overlapping role
  • Write detailed backstories (3-5 sentences minimum)
  • Specify expected output format in tasks
  • Use context to pass data between tasks
  • Start with 2-3 agents and add more only if needed
  • Test agents individually before combining into crews
Don't:
  • Create agents with vague roles ("helper", "assistant")
  • Use more agents than necessary (each adds cost and latency)
  • Skip the expected_output field (it guides output quality)
  • Use hierarchical process without a good reason (adds manager overhead)
  • Ignore token usage in production (crews can be expensive)
  • Deploy without error handling and logging

When NOT to Use CrewAI

  • Simple, single-step tasks: If one LLM call solves the problem, do not add multi-agent overhead.
  • Deterministic pipelines: If you know exactly what steps to take and do not need LLM reasoning, use regular code.
  • Real-time applications: Crews take time (30 seconds to several minutes). Not suitable for sub-second response requirements.
  • Cost-sensitive scenarios: Multi-agent systems multiply LLM costs. Evaluate if the quality improvement justifies the expense.

Course Summary

Congratulations on completing the CrewAI course! You have learned how to create agents with specialized roles, define tasks with clear expectations, orchestrate crews with sequential and hierarchical processes, and deploy multi-agent systems to production. You can now build AI teams that collaborate to solve complex problems.