Skip to content
>_devvkit
$devvkit learn --librarie autogen-&-crewai-guide

AutoGen & CrewAI Guide

[ai][agents][multi-agent][automation]
AI / LLM Tools
Install
# AutoGen:
pip install pyautogen
# or: uv add pyautogen

# CrewAI:
pip install crewai
# or: uv add crewai
# Both need: OPENAI_API_KEY or other LLM config

AutoGen (Microsoft) enables multi-agent conversations where agents talk to each other — a user proxy agent asks questions, an assistant agent responds, a code executor runs the code. Agents can use tools (web search, file system, APIs) and have dynamic group chats with speaker selection.

CrewAI is the simpler, task-oriented alternative. You define `Agent`s (role, goal, backstory, tools) and `Task`s (description, expected output, assigned agent), then kick off a `Crew`. CrewAI handles delegation and task sequencing automatically. Great for research, content writing, and data analysis workflows.

Both support local models via Ollama, custom tools, and human-in-the-loop approval. AutoGen is more flexible and programmable; CrewAI is more opinionated and easier to get started. GUI: AutoGen Studio (no-code agent builder), CrewAI Enterprise (web UI for monitoring crews).

AutoGen Setup

AutoGen — two-agentSimple assistant + user.
import autogen

config_list = [{'model': 'gpt-4o', 'api_key': '...'}]

assistant = autogen.AssistantAgent(
    name='Assistant',
    llm_config={'config_list': config_list}
)

user_proxy = autogen.UserProxyAgent(
    name='User',
    human_input_mode='NEVER',
    code_execution_config={'work_dir': 'coding'}
)

user_proxy.initiate_chat(
    assistant,
    message='Write a Python script to fetch and plot stock prices'
)
AutoGen — tool useAgent uses external tools.
from typing import Annotated
import autogen

# Define a tool function
@autogen.register_for_llm
def search_web(query: Annotated[str, 'Search query']) -> str:
    import requests
    return requests.get(f'https://api.duckduckgo.com/?q={query}&format=json').text

@autogen.register_for_execution
def search_web(query: str) -> str: ...

assistant = autogen.AssistantAgent(
    name='Assistant',
    llm_config=llm_config,
    tools=[search_web]  # Agent can use this tool
)
Local modelsRun agents with Ollama.
# AutoGen with Ollama:
config_list = [{
    'model': 'llama3.2',
    'base_url': 'http://localhost:11434/v1',
    'api_key': 'ollama'
}]

# CrewAI with Ollama:
from langchain_ollama import ChatOllama
llm = ChatOllama(model='llama3.2', base_url='http://localhost:11434')

agent = Agent(
    role='Assistant',
    llm=llm
)

AutoGen Multi-Agent

AutoGen — group chatMultiple agents collaborate.
import autogen

planner = autogen.AssistantAgent(name='Planner', llm_config=llm_config)
coder = autogen.AssistantAgent(name='Coder', llm_config=llm_config)
critic = autogen.AssistantAgent(name='Critic', llm_config=llm_config)

manager = autogen.GroupChatManager(
    groupchat=autogen.GroupChat(
        agents=[planner, coder, critic],
        messages=[],
        max_round=10
    )
)

user = autogen.UserProxyAgent(
    name='User',
    code_execution_config={'work_dir': 'coding'}
)

user.initiate_chat(manager, message='Build a REST API with FastAPI')

CrewAI Setup

CrewAI — basic crewDefine agents and tasks.
from crewai import Agent, Task, Crew

# Define agents
researcher = Agent(
    role='Senior Researcher',
    goal='Find latest AI breakthroughs',
    backstory='You're a tech analyst at a top research firm',
    llm='gpt-4o'
)

writer = Agent(
    role='Technical Writer',
    goal='Write clear summaries of AI research',
    backstory='You translate complex research into plain English',
)

# Define tasks
research_task = Task(
    description='Research the latest LLM papers from arXiv',
    agent=researcher
)

write_task = Task(
    description='Write a 500-word blog summary of findings',
    agent=writer
)

# Create crew
crew = Crew(
    agents=[researcher, writer],
    tasks=[research_task, write_task],
    verbose=True
)

result = crew.kickoff()
print(result)

CrewAI Tasks

CrewAI — with toolsAgents with tool access.
from crewai_tools import (
    FileReadTool,
    FileWriteTool,
    WebsiteSearchTool
)

researcher = Agent(
    role='Researcher',
    tools=[WebsiteSearchTool(), FileReadTool()],
    llm='gpt-4o'
)

writer = Agent(
    role='Writer',
    tools=[FileWriteTool()]
)

# Sequential task execution
research = Task(
    description='Research web development trends 2026',
    expected_output='A list of top 10 trends with sources',
    agent=researcher
)

# Output from research_task is input to write_task
draft = Task(
    description='Write a blog post based on research',
    expected_output='A 1000-word markdown blog post',
    agent=writer
)
CrewAI — sequential vs hierarchicalTask orchestration modes.
# Sequential (default): tasks run in order
crew = Crew(agents=[a1, a2], tasks=[t1, t2], process='sequential')

# Hierarchical: manager delegates to agents
crew = Crew(
    agents=[researcher, writer, reviewer],
    tasks=[main_task],
    process='hierarchical',
    manager_llm='gpt-4o'
)

# The manager decides which agent does what