Intermediate

Agent Frameworks

Agent frameworks provide the scaffolding for building AI agents without reinventing the wheel. Compare the leading frameworks and learn when to use each one.

Framework Comparison

FrameworkByLanguageBest ForMulti-AgentLearning Curve
LangGraphLangChainPython, JSComplex stateful agentsYesMedium-High
CrewAICrewAIPythonMulti-agent teamsYes (core)Low-Medium
AutoGenMicrosoftPythonConversational multi-agentYes (core)Medium
Semantic KernelMicrosoftC#, Python, JavaEnterprise .NET integrationYesMedium
HaystackdeepsetPythonRAG-heavy agentsLimitedMedium
SmolagentsHugging FacePythonSimple, lightweight agentsLimitedLow

LangGraph

LangGraph is the agent framework from LangChain, designed for building complex, stateful agent applications as graphs. It models agent workflows as nodes (actions) connected by edges (transitions), with full control over flow.

Python - LangGraph Agent
from langgraph.graph import StateGraph, MessagesState
from langgraph.prebuilt import ToolNode, tools_condition
from langchain_anthropic import ChatAnthropic

# Define tools
tools = [search_web, read_file, write_file]

# Create the LLM with tools
llm = ChatAnthropic(model="claude-sonnet-4-20250514")
llm_with_tools = llm.bind_tools(tools)

# Define the agent node
def agent(state: MessagesState):
    response = llm_with_tools.invoke(state["messages"])
    return {"messages": [response]}

# Build the graph
graph = StateGraph(MessagesState)
graph.add_node("agent", agent)
graph.add_node("tools", ToolNode(tools))
graph.set_entry_point("agent")
graph.add_conditional_edges("agent", tools_condition)
graph.add_edge("tools", "agent")

# Compile and run
app = graph.compile()
result = app.invoke({
    "messages": [("user", "Find the latest AI news")]
})
  • Strengths: Fine-grained control, checkpointing, human-in-the-loop, streaming, persistence
  • Weaknesses: Steeper learning curve, can be verbose for simple agents
  • Use when: You need precise control over agent behavior, complex conditional flows, or production-grade reliability

CrewAI

CrewAI is designed specifically for multi-agent collaboration. You define "agents" with roles and "tasks" they perform, organized into a "crew" that works together.

Python - CrewAI Multi-Agent Team
from crewai import Agent, Task, Crew, Process

# Define agents with roles
researcher = Agent(
    role="Senior Research Analyst",
    goal="Find comprehensive information on the topic",
    backstory="Expert at finding and synthesizing information",
    tools=[search_tool, scrape_tool],
    llm="claude-sonnet-4-20250514"
)

writer = Agent(
    role="Content Writer",
    goal="Write clear, engaging content based on research",
    backstory="Skilled technical writer",
    llm="claude-sonnet-4-20250514"
)

# Define tasks
research_task = Task(
    description="Research the latest trends in AI agents",
    agent=researcher,
    expected_output="Detailed research notes"
)

writing_task = Task(
    description="Write a blog post based on the research",
    agent=writer,
    expected_output="A polished blog post"
)

# Create and run the crew
crew = Crew(
    agents=[researcher, writer],
    tasks=[research_task, writing_task],
    process=Process.sequential
)
result = crew.kickoff()
  • Strengths: Intuitive role-based design, easy multi-agent setup, good for content and research workflows
  • Weaknesses: Less control over low-level behavior, can be opinionated about structure
  • Use when: Building teams of agents with distinct roles, content pipelines, research workflows

AutoGen

Microsoft's AutoGen enables multi-agent conversations where agents communicate through messages. Agents can be LLM-powered, tool-based, or human proxies.

  • Strengths: Flexible agent communication, supports human-in-the-loop, good documentation
  • Weaknesses: Can lead to excessive back-and-forth between agents
  • Use when: Conversational multi-agent workflows, scenarios requiring human oversight

Semantic Kernel

Microsoft's SDK for integrating AI into applications. Strong focus on enterprise scenarios and .NET integration, with Python and Java support.

  • Strengths: Enterprise-grade, multi-language, Azure integration, plugin ecosystem
  • Weaknesses: More complex setup, Microsoft-centric
  • Use when: Enterprise .NET applications, Azure ecosystem, structured enterprise workflows

Haystack

deepset's Haystack is primarily a framework for building RAG pipelines but has expanded to support agent-like behavior through its pipeline-based architecture.

  • Strengths: Excellent RAG capabilities, clean pipeline abstraction, good for search-heavy agents
  • Weaknesses: Agent support is secondary to RAG, less flexible for pure agent workflows
  • Use when: Agents that primarily need to search, retrieve, and reason over documents

Smolagents (Hugging Face)

A lightweight, minimalist agent framework from Hugging Face. Designed to be simple and easy to understand.

  • Strengths: Minimal code, easy to learn, works with any LLM, code-based agents
  • Weaknesses: Fewer features, less suitable for complex multi-agent setups
  • Use when: Learning about agents, simple single-agent applications, prototyping

Framework Selection Guide

Quick decision guide:
  • Just learning? Start with Smolagents or build from scratch
  • Single agent with tools? LangGraph or direct API (Anthropic/OpenAI tool use)
  • Multi-agent team? CrewAI (role-based) or AutoGen (conversational)
  • Enterprise .NET? Semantic Kernel
  • RAG-heavy agent? Haystack
  • Maximum control? LangGraph or build your own
💡
Framework vs. from scratch: For production agents, many teams find that starting with a framework and then gradually replacing framework components with custom code gives the best balance of speed and control. Some teams skip frameworks entirely and build directly on the LLM provider's API with tool use.