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.
- 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 block | What you would write by hand | What a framework offers |
|---|---|---|
| Model access | Code for each provider | One interface for many providers |
| Tools | Schemas and a registry | Decorators and ready-made integrations |
| Loop and workflow | Your own while loop | Graphs, edges and prebuilt agent patterns |
| State and memory | Dictionaries and files | State objects, storage and checkpointing |
| Observability | Print statements | Built-in tracing and debugging tools |
| Human approval | Custom pause logic | Interrupt and resume features |
Remember: A framework does not make an agent smarter. It saves you plumbing.
- 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.
- 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.
- Medium: Other Agent Frameworks
Many frameworks exist, and each makes different trade-offs. Some well-known examples:
| Style | Examples | Idea |
|---|---|---|
| Graph and workflow based | LangGraph and similar tools | Explicit nodes, edges and state |
| Role-based multi-agent teams | CrewAI, AutoGen and similar | Define agents with roles and let them collaborate |
| Provider SDKs | The agent SDKs from model providers | A thin, official layer around that provider's tool-calling |
| Data and retrieval centered | LlamaIndex and similar | Strong tools for documents and RAG |
| Lightweight and code-first | smolagents, Pydantic AI and similar | Minimal abstractions, plain Python |
Note: This is a snapshot. The landscape changes fast, so treat the list as examples of styles, not as a ranking.
- Advanced: Framework vs. Custom Implementation
| Question | Framework | Custom code |
|---|---|---|
| Speed to first prototype | Fast | Slower |
| Control and transparency | Less, because of abstractions | Full |
| Learning curve | Learn the framework's concepts | Learn the basics deeply |
| Debugging | Can be hard behind layers | Direct |
| Features like tracing and checkpoints | Built in | You build them |
| Risk of change | API changes and lock-in | Your 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.
- 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.
Click to see when custom code is the better choiceCompare ▼
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.
- 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.
# 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.")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
Key Points
The Big Picture
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.