Agent Frameworks

Understand why agent frameworks exist, what they provide (graphs, state, tools, checkpoints, tracing), how LangChain and LangGraph and other popular frameworks fit in, and how to choose between a framework and a custom implementation.

28 minIntermediateCode Examples

The Core Idea: An agent framework packages the parts you have been writing by hand: the loop, tools, state, workflows, memory, checkpoints and tracing. The core idea is always a graph of steps with shared state. Whether to use a framework or build your own depends on your needs.

  1. Beginner: Why Frameworks Exist

Every agent project needs the same building blocks: calling a model, defining tools, running the loop, keeping state, handling errors and recording traces. Writing all of it again for each project is slow and error-prone. Frameworks provide these parts ready-made.

Building blockWhat you would write by handWhat a framework offers
Model accessCode for each providerOne interface for many providers
ToolsSchemas and a registryDecorators and ready-made integrations
Loop and workflowYour own while loopGraphs, edges and prebuilt agent patterns
State and memoryDictionaries and filesState objects, storage and checkpointing
ObservabilityPrint statementsBuilt-in tracing and debugging tools
Human approvalCustom pause logicInterrupt and resume features

Remember: A framework does not make an agent smarter. It saves you plumbing.

  1. Beginner: LangChain Agents

LangChain is a widely used toolkit of components for LLM applications: model wrappers, prompt templates, document loaders, vector store connections, tool definitions and ready-made agent constructors. Its strength is the huge number of integrations.

Good to know: Agent frameworks change quickly. Function names and recommended patterns are updated often, so always check the current documentation and not old tutorials.

Typical use
Quickly connect a model to many tools and data sources, and get a working agent in a few lines.

  1. Medium: LangGraph and Graph-Based Agents

LangGraph models an agent as a graph: nodes are steps (call the model, run a tool, check a result), edges say which step comes next, and a shared state flows through the graph. Conditional edges choose the next node from the state, which allows loops and branches.

The code in this lesson builds a tiny graph engine in about twenty lines. Nodes return updates that are merged into the state, a conditional edge decides whether to loop or end, and a step limit protects against endless runs.

Why graphs are popular: They make control flow explicit: you can draw the agent, test each node, add checkpoints between nodes, pause for a human, and resume. This matches the workflow and state machine lesson.

  1. Medium: Other Agent Frameworks

Many frameworks exist, and each makes different trade-offs. Some well-known examples:

StyleExamplesIdea
Graph and workflow basedLangGraph and similar toolsExplicit nodes, edges and state
Role-based multi-agent teamsCrewAI, AutoGen and similarDefine agents with roles and let them collaborate
Provider SDKsThe agent SDKs from model providersA thin, official layer around that provider's tool-calling
Data and retrieval centeredLlamaIndex and similarStrong tools for documents and RAG
Lightweight and code-firstsmolagents, Pydantic AI and similarMinimal abstractions, plain Python

Note: This is a snapshot. The landscape changes fast, so treat the list as examples of styles, not as a ranking.

  1. Advanced: Framework vs. Custom Implementation

QuestionFrameworkCustom code
Speed to first prototypeFastSlower
Control and transparencyLess, because of abstractionsFull
Learning curveLearn the framework's conceptsLearn the basics deeply
DebuggingCan be hard behind layersDirect
Features like tracing and checkpointsBuilt inYou build them
Risk of changeAPI changes and lock-inYour own maintenance

Practical advice: Understand the basic loop first (this series). Prototype with a framework if it speeds you up. If it gets in your way, a small custom loop is perfectly fine, because the core is only a few dozen lines.

Avoid: Adopting a heavy framework before you know what you need. Start simple, and add structure when the problems appear.

  1. Visual Explanation: A Graph and a Plain Loop Give the Same Result

The figure compares the graph-based version of the agent from the code with the hand-written loop, then lists what frameworks add on top.

Part 1 · The Same Agent Two WaysIdentical result
Graph frameworkNodes and edges
plan node
↓
act node, loops while steps are left
↓
Conditional edge ends the run
↓
Trace: plan, act, act, act
Hand-written loopPlain Python
Call plan once
↓
while steps are left, call act
↓
Same final log: True
Part 2 · What a Framework AddsBeyond the loop
Checkpoints
Resume
Save state between nodes.
Streaming
Live output
Show steps as they happen.
Tracing
See inside
Record every call.
Approval
Pause
Wait for a human.
Click to see when custom code is the better choiceCompare ▼
If your agent is a simple loop with a few tools, a framework may add more concepts than it removes. Custom code stays transparent, and you control exactly what happens.

Part 1 shows that the two versions produce the same result. Part 2 lists the extras a framework provides. Open the bar to see when custom code wins.

  1. Python Implementation: A Tiny Graph Engine Built From Scratch

This script builds a small graph engine with nodes, edges, conditional edges, state merging and a step limit, runs a plan and act agent on it, and shows that a plain loop gives the identical result.

mini_graph_framework.pyPython 3.10+ · standard library only
# What a framework gives you: a small graph engine (nodes, edges, conditional edges, state merging)class Graph:    def __init__(self):        self.nodes, self.edges, self.routers = {}, {}, {}     def add_node(self, name, fn):        self.nodes[name] = fn     def add_edge(self, source, target):        self.edges[source] = target     def add_conditional_edges(self, source, router):        self.routers[source] = router     def run(self, start, state, max_steps=20):        node, trace = start, []        for _ in range(max_steps):                       # a built-in step limit            if node == "END":                break            update = self.nodes[node](state)            state = {**state, **update}                  # merge what the node returned into the state            trace.append(node)            node = self.routers[node](state) if node in self.routers else self.edges[node]        return state, trace def plan(state):    return {"steps_left": 3, "log": state["log"] + ["planned 3 steps"]} def act(state):    left = state["steps_left"] - 1    return {"steps_left": left, "log": state["log"] + ["did a step, " + str(left) + " left"]} graph = Graph()graph.add_node("plan", plan)graph.add_node("act", act)graph.add_edge("plan", "act")graph.add_conditional_edges("act", lambda s: "END" if s["steps_left"] == 0 else "act") final_state, trace = graph.run("plan", {"log": []})print("Framework run trace:", trace)print("Final log:", final_state["log"]) # The same behavior written by hand as a plain loopdef custom_loop():    state = {"log": []}    state = {**state, **plan(state)}    while state["steps_left"] > 0:        state = {**state, **act(state)}    return state print("Same result with a hand-written loop:", custom_loop()["log"] == final_state["log"])print("What the framework adds on top: checkpoints, streaming, tracing, ready-made tools, human approval pauses.")
EXPECTED OUTPUT (your numbers may differ slightly)
Framework run trace: ['plan', 'act', 'act', 'act']
Final log: ['planned 3 steps', 'did a step, 2 left', 'did a step, 1 left', 'did a step, 0 left']
Same result with a hand-written loop: True
What the framework adds on top: checkpoints, streaming, tracing, ready-made tools, human approval pauses.

The graph runs plan once and act three times, then ends through the conditional edge. The hand-written loop gives exactly the same log. The framework's value is the extras around this core, such as checkpoints, tracing and approval pauses, not the loop itself.

Knowledge Check

Question 1: What do agent frameworks mainly provide?
Question 2: In a graph-based agent, what does a conditional edge do?

Key Points

✓Frameworks package the loop, tools, state, workflows, memory, checkpoints and tracing.
✓LangChain offers many components and integrations. LangGraph models agents as graphs with shared state.
✓Other frameworks focus on roles, provider SDKs, data and retrieval, or minimal code.
✓Frameworks change fast, so check current documentation.
✓The core of an agent is small. A framework adds plumbing and extras.
✓Learn the basic loop first, then choose a framework or custom code based on your needs.

The Big Picture

Frameworks in One Line

Same core idea (a graph of steps with state), different amounts of plumbing

Knowing how to build the core by hand makes you a better user of any framework.

Up Next: Frameworks need a standard way to connect to tools and data. In Model Context Protocol (MCP) you will learn the open protocol that standardizes those connections.