Agent Frameworks: Building with LangChain, CrewAI & Beyond
LangGraph, CrewAI, AutoGen, OpenAI Agents SDK, Anthropic's Agent SDK — the framework landscape changes every six months and the wrong choice costs you a quarter of rewrites. The rule that survives the churn: build the loop yourself once with raw SDK calls, then adopt a framework that abstracts what you actually need. This lesson is a decision matrix, not a fan club.
Learning Objectives
After this lesson, you will be able to:
Compare the four major agent frameworks -- LangChain/LangGraph, CrewAI, AutoGen, and Anthropic Agent SDK -- and know what each one is best at
Understand how LangChain's building blocks (chains, agents, tools, memory) snap together like LEGO pieces to build agent applications
Describe CrewAI's approach: define agent roles ('Senior Researcher', 'Technical Writer') and let them collaborate like a real team
Identify when AutoGen's conversation-driven multi-agent patterns are the right fit (debate, brainstorming, research)
Use a decision matrix to choose the right framework for your specific task instead of defaulting to whatever is popular
This is the practical "which tool do I actually use?" lesson. You have learned how agents work from scratch -- now you will learn which pre-built frameworks save you from reinventing the wheel, and when to use each one.
Try it! Install LangChain (pip install langchain langchain-anthropic) and build the simplest possible agent: one tool (a calculator), one prompt ("You are a helpful math assistant"), and one question ("What is 15% tip on $47.50?"). Compare the code to the raw API version you would write from scratch. The framework version is about half the code -- that is the value proposition.
In the previous lessons, you built agent loops from scratch. You wrote the observe-think-act cycle, handled tool calls, managed memory, and wired up guardrails. That was essential for understanding -- you need to know what happens beneath the abstraction. But in production, almost nobody writes agents from raw API calls. They use frameworks.
LangChain is the most widely adopted agent framework. It started as a simple chain-of-LLM-calls library and evolved into a comprehensive ecosystem for building LLM-powered applications. Understanding its architecture means understanding the vocabulary that most agent teams speak.
Chains are sequences of operations. The simplest chain takes user input, formats it into a prompt, sends it to an LLM, and parses the output. Chains can be nested -- the output of one chain becomes the input of another. Think of them as composable pipelines where each step transforms data.
Agents are chains that decide their own control flow. Instead of a fixed sequence, an agent examines the current state and decides which tool to call next. The LLM acts as a router: given the conversation so far, it picks the next action. This is the observe-think-act loop you learned, but packaged into a standard interface.
Tools are functions the agent can invoke. LangChain provides a standard Tool interface: a name, a description (critical for the LLM to know when to use it), and an execution function. You can wrap any API, database query, or computation as a tool.
Memory modules persist state across interactions. ConversationBufferMemory stores the full conversation. ConversationSummaryMemory compresses history into summaries. VectorStoreMemory stores and retrieves relevant past interactions using embeddings. You plug a memory module into your chain and it automatically injects context.
LangGraph extends LangChain with explicit graph-based control flow. Instead of letting the LLM decide everything, you define a state machine: nodes are processing steps (LLM calls, tool executions, human reviews) and edges define transitions between them. This gives you the flexibility of agents with the predictability of workflows.
The key insight: not every decision should be made by the LLM. Some transitions are deterministic ("if the tool returns an error, go to the retry node"). Others are LLM-driven ("given this result, decide whether to search more or respond"). LangGraph lets you mix both in a single graph.
State is a typed dictionary that flows through the graph. Every node reads from and writes to state. This makes the agent's progress inspectable at every step -- you can pause, serialize, and resume a graph execution.
Nodes are functions that process state. A node might call an LLM, execute a tool, validate output, or check a condition. Each node takes the current state and returns updated state.
Edges connect nodes. Conditional edges use a function to decide which node to visit next based on the current state. This is how you implement branching logic: "if the agent decided to use a tool, go to the tool-execution node; if it decided to respond, go to the response node."
What Do You Think?
You need an agent that searches the web, writes code, and emails the result. Which framework?
What Do You Think?
You are deciding between Claude Agents SDK / OpenAI Agents SDK and LangGraph for a new 2025 build. Which statement is most accurate?
LangChain/LangGraph is the best fit here. You have a single agent with multiple tools (web search, code execution, email sending), and LangGraph's state machine lets you define the flow explicitly: search -> write code -> test code -> email. CrewAI would be overkill -- you do not need multiple specialized agents with different roles. AutoGen's conversation patterns do not match this sequential workflow. Raw API calls could work, but you would end up rebuilding LangChain's tool dispatch and error handling.
CrewAI takes a different approach. Instead of one agent with many tools, CrewAI creates teams of specialized agents, each with a distinct role, backstory, and set of capabilities. The metaphor is a workplace: you assemble a crew with complementary skills and assign them tasks.
Agents in CrewAI are defined by their role, goal, and backstory. A "Senior Research Analyst" agent has different behavior from a "Technical Writer" agent, even when backed by the same LLM. The role and backstory shape the system prompt, which shapes the agent's personality, tone, and decision-making style.
Tasks define what needs to be done. Each task has a description, expected output format, and an assigned agent. Tasks can depend on other tasks -- "write the report" depends on "gather the research." CrewAI manages these dependencies automatically.
Crews are collections of agents and tasks with an execution strategy. A sequential crew runs tasks one after another, passing outputs forward. A hierarchical crew has a manager agent that delegates tasks to worker agents and reviews their output. The manager decides who does what and whether the result is good enough.
CrewAI excels when your problem naturally decomposes into roles. Content creation (researcher + writer + editor), data analysis (collector + analyst + visualizer), customer support (classifier + responder + escalation handler) -- these map cleanly to CrewAI's model. The framework handles delegation, communication between agents, and result aggregation.
The downside: CrewAI adds overhead for simple single-agent tasks. If you just need one agent with a few tools, CrewAI's role-based abstraction is unnecessary complexity.
Microsoft's AutoGen treats agent collaboration as conversation. Instead of explicit task delegation (CrewAI) or graph-based workflows (LangGraph), AutoGen agents talk to each other. They debate, critique, refine, and build on each other's work through message passing.
Two-agent chat is the simplest pattern. A user proxy agent (representing the human) talks to an assistant agent. The assistant can execute code, use tools, and reason. The user proxy can provide feedback, approve actions, or inject new information. This back-and-forth continues until a termination condition is met.
Group chat extends this to multiple agents. A software team might have a Product Manager agent (defines requirements), a Developer agent (writes code), a Tester agent (reviews and tests), and a Reviewer agent (critiques design). They converse in a shared thread, each contributing based on their expertise. A Group Chat Manager decides who speaks next.
Multi-agent debate is a powerful pattern for improving output quality. Two or more agents argue different positions on a question. Agent A generates an answer. Agent B critiques it. Agent A revises. Agent B critiques again. The debate continues until they converge or a moderator picks the best answer. Research shows this produces more accurate, nuanced results than single-agent generation.
AutoGen has built-in support for code execution. An agent can write Python code, and AutoGen executes it in a sandboxed environment, returning stdout and stderr. If the code fails, the agent sees the error and can debug it -- a mini code agent inside the conversation framework. This makes AutoGen particularly strong for data analysis and programming tasks.
Anthropic's approach is different from the heavyweight frameworks. The Anthropic SDK provides native tool use through the Messages API -- the LLM itself decides when and how to use tools, returning structured tool_use content blocks alongside text.
You define tools as JSON schemas and include them in the API request. When Claude decides to use a tool, its response contains a tool_use content block with the tool name and arguments. Your code executes the tool and sends the result back as a tool_result content block. The conversation continues until Claude responds with only text (no tool calls), signaling task completion.
Streaming is first-class. Tool calls stream as they are generated, so you can show the user what the agent is doing in real time. Partial JSON arguments stream progressively -- useful for long tool calls where you want to display progress.
Extended thinking lets Claude show its reasoning process before making tool calls. Instead of a black box that jumps straight to a tool invocation, you see the agent's chain of thought: "The user wants flight data. I should use the flight_search tool with Tokyo as the destination..."
The Anthropic Agent SDK is intentionally minimal. It does not include memory management, workflow orchestration, or multi-agent coordination. The philosophy: give you the building blocks and let you compose them however you want. For simple tool-use agents, this is the fastest path to production. For complex multi-agent systems, you will need to build more infrastructure yourself -- or combine it with another framework.
Choosing a framework is an engineering decision, not a religious one. Here is how to think about it:
Use LangChain/LangGraph when: You need a single agent with many tools and complex control flow. You want a large ecosystem of pre-built integrations (hundreds of tool connectors, vector store adapters, memory backends). You need explicit state machines with deterministic transitions mixed with LLM decisions. Enterprise teams default here for its maturity and observability (LangSmith).
Use CrewAI when: Your problem naturally decomposes into roles. You need multiple agents with distinct personas collaborating on a task. Content generation, research workflows, and customer support pipelines are sweet spots. You want the highest-level abstraction -- define roles and tasks, and the framework handles orchestration.
Use AutoGen when: You need agents that debate, critique, and refine each other's work. Code generation with built-in execution is a primary use case. Research tasks that benefit from multi-perspective reasoning. You are comfortable with the conversational paradigm and want built-in code sandboxing.
Use Anthropic Agent SDK when: You are building with Claude and want minimal abstraction. Your agent is a single loop with tool use -- no multi-agent coordination needed. You value control and transparency over convenience. You want streaming and extended thinking out of the box.
Use raw API calls when: You are prototyping a concept in an afternoon. Your agent is trivially simple (one tool, one loop). You need maximum control and zero framework overhead. Or you are building a framework yourself.
pythonplayground.py · Pyodide
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
Tests · Add a summarize tool, implement retry logic for tool errors, and add execution tracing with timestamps for each step.
LangChain is the framework most engineers encounter first. Here is what a real LangChain agent looks like -- from tool definition to execution:
pythonplayground.py · Pyodide
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
Tests · Implement a ReAct-style agent that chains Search and Calculator tools to answer multi-step questions, printing the thought-action-observation trace at each step.
#Framework Comparison: LangChain vs CrewAI vs AutoGen vs LlamaIndex
Choosing between frameworks is easier when you see them side-by-side. Here is how the major frameworks compare across the dimensions that matter most in practice:
Not sure which framework to pick? Walk through these questions:
Question 1: How many agents do you need?
One agent -> Go to Question 2
Multiple agents with distinct roles -> Go to Question 3
Question 2: What does your single agent do?
Simple tool use (search, calculate, API calls) -> Anthropic Agent SDK or raw API calls. Minimal abstraction, maximum control. You do not need a framework for a single agent with a few tools.
Complex multi-step workflow with branching logic -> LangGraph. State machines let you define explicit paths with both deterministic and LLM-driven transitions.
Primarily retrieves and reasons over documents/data -> LlamaIndex Agents. Purpose-built for RAG-centric workflows with rich data source connectors.
Question 3: How should your agents collaborate?
Sequential handoffs (researcher -> writer -> editor) -> CrewAI. The role-task-crew model maps perfectly to pipeline workflows.
Debate, critique, and refine each other's work -> AutoGen. Conversation-driven agents that argue and iterate produce the best results for open-ended reasoning tasks.
Dynamic orchestration with conditional routing -> LangGraph. Build a graph where agents are nodes and transitions are edges, mixing deterministic routing with LLM decisions.
Question 4: What are your constraints?
Two-week deadline, small team -> Pick the framework your team already knows. LangChain is the safest bet (largest community, most tutorials).
Need enterprise observability and tracing -> LangChain + LangSmith. No other framework matches LangSmith's production tracing.
Need built-in code execution -> AutoGen. Its sandboxed code execution is the most mature.
Claude-only deployment -> Anthropic Agent SDK. Native streaming, extended thinking, and tool use with zero framework overhead.
In practice, teams often combine frameworks. A common pattern: use the Anthropic SDK for the core LLM interaction (tool calls, streaming), LangGraph for workflow orchestration (state machines, human-in-the-loop gates), and a vector store library for memory. Frameworks are not monolithic -- you can use the pieces that help and ignore the rest.
Another pattern: use CrewAI for the high-level multi-agent coordination but have each individual agent use LangChain internally for its tool management. Or use AutoGen for the debate pattern between two agents, where each agent internally uses the Anthropic SDK for its reasoning.
The frameworks are converging. LangChain added multi-agent support. CrewAI improved its tool integration. AutoGen expanded beyond conversations. Anthropic released higher-level abstractions. By the time you are reading this, the boundaries may have shifted further. The core concepts -- tool registries, memory backends, state machines, role-based delegation, conversation patterns -- remain stable even as the implementations evolve.
Frameworks trade control for speed -- They provide battle-tested building blocks (tool registries, memory backends, orchestration) so you focus on what your agent does, not the plumbing
LangChain/LangGraph excels at single-agent tool use with complex control flow -- State machines, rich tool ecosystem, enterprise observability via LangSmith
CrewAI excels at role-based multi-agent teams -- When your problem decomposes into roles (researcher, writer, reviewer), CrewAI's abstraction is the fastest path
AutoGen excels at conversation-driven collaboration and code execution -- Multi-agent debate, critique-and-refine patterns, and built-in sandboxed code execution
The Anthropic Agent SDK is minimal and powerful -- Native tool use with streaming and extended thinking, maximum control, minimal abstraction
What is the primary advantage of using LangGraph over plain LangChain agents?
You now know the major frameworks and when to use each one. Frameworks give you speed; understanding gives you judgment. Next, we will explore a radically different kind of agent -- one that does not call APIs at all but instead looks at a screen, moves a mouse, and clicks buttons like a human.