Want a quick email when a new article is published? Subscribe

When the model holds the loop: one agent, three frameworks

9 min read • 9 Nov 2026

Part 3 of 3 of Who holds the loop?, a series that builds the same jobs with no framework, LangChain, LangGraph, Pydantic AI and the Claude Agent SDK, and compares them line by line.

aiagentslanggraphclaude agent sdkframeworksllm

Every agent framework runs the same loop, and you could write it yourself in eight lines. What separates the frameworks is everything around that loop, and the place it mattered most was the moment an agent has to stop and ask a person before doing something it can’t take back.

The agent here carries out spoken instructions (“mark that one done”, “remind me to book the dentist”) on a kanban board through its API, and the model decides which tools to call and in what order. I built it by hand, with the Claude Agent SDK and with LangGraph’s ready-made agent, all against a sandbox board of invented cards, with the same tools, instructions and checks. The first article in this series explains the difference between a workflow and an agent and how the comparison was run.

An agent is a loop you could write in eight lines

Every agent, whatever framework sits on top, runs this loop:

messages = [instructions, what_was_said]
while True:
    reply = model(messages, tools)
    if not reply.tool_calls:
        return reply.text
    for call in reply.tool_calls:
        messages.append(run_tool(call))

The model can only ask for a tool. Your code decides whether to run it. That’s where a guardrail lives: my code locked every tool to the sandbox board, and I gave the agent no delete tool at all.

All three versions carried out all six test instructions correctly. They found the right cards, set flags, added comments, moved cards, set due dates and created new ones. The differences were in everything around the result:

By handClaude Agent SDKLangGraph
Lines of code415838 (15 for the agent, 23 for tracing)
Time per instruction3.0 s4.9 s3.8 s
Describing tools to the modelA helper reading type hintsA JSON schema per tool, by handAutomatic, from type hints and docstrings

The Claude Agent SDK starts Claude Code as a separate process, which costs about a second per instruction, and its built-in shell and file tools have to be switched off explicitly. LangGraph’s agent function printed a warning that it’s moving to a different package and will be removed in the next major version. For an agent this size, none of them changed whether the job got done.

This figure is interactive and needs JavaScript. The text around it describes what it shows.

One agent, three builds. Pick a build and an instruction to see each model turn, each tool call and the board afterwards.

A guardrail limits what an agent can do, not what it decides to do

The most useful failure of the project came from a vaguely worded instruction. It asked the agent to “clear out” a set of cards, and the agent had no tool that could delete anything.

The hand-written agent found the nearest thing it was allowed to do. It marked two unfinished cards as complete, then explained politely that it couldn’t delete cards, so the completed ones were now in Done. The Claude Agent SDK version, given the same request, stopped and asked which cards I meant.

Both stayed inside the guardrail. The guardrail did exactly its job, and still couldn’t tell a sensible use of “mark complete” from a harmful one. Locking down an agent’s tools controls what it’s able to do. Getting it to understand what you meant is a separate problem, and the practical fix is to make it ask before anything bulk or irreversible.

When an agent can stop anywhere, LangGraph wins

So I added a rule, written once in plain code and shared by all three agents: ask before marking any card done, and ask before changing a second card within one instruction. When the rule fires, the run saves itself and the process exits. Your answer starts a new process that carries on.

In a pipeline with one fixed pause point, a hand-written save-and-resume had been shorter than LangGraph’s. An agent is different: it can stop between any two tool calls, at points the model chooses. Each version handled that differently:

This figure is interactive and needs JavaScript. The text around it describes what it shows.

Stop, ask, carry on. Each box is a separate process, and the band between them is the run waiting on disk for an answer.

All three passed every case, including the ones where the answer was no. This is where LangGraph was clearly the best fit, and it’s exactly the situation it was designed for.

Parallel tool calls will break your stateful rules

The first LangGraph run let a change through that the rule should have stopped. Asked to flag two cards, the model requested both updates in a single turn, and LangGraph ran them at the same moment. They started a millisecond apart. Both checked the “second card” rule before either had touched anything, so both went ahead, with no error anywhere.

The hand-written loop never hit this, because it ran tool calls one after another. The fix belonged in the rule itself: check it and record the change in one locked step. Most frameworks run tool calls in parallel by default, so any rule that depends on what has already happened in the run needs that lock.

Parallel calls caught me out a second time. Told to mark two cards done, the model asked for both at once, both paused, and LangGraph refused to resume until it had a separate answer for each pause, identified by its id. My code assumed one question at a time, and the first time two arrived together it crashed. Once tools can run together, so can the questions they ask you.

Every framework hides behaviour you’ll only find by tracing

The project was small, and I still found six behaviours that no documentation had warned me about:

None of these is a reason to avoid the tool. Each is a reason to trace real runs before you trust one, because a larger system has more of them, and they’re harder to find.

A framework’s benefit tracks the complexity it was built to absorb

It’s tempting to conclude that frameworks pay off once a task gets complicated enough. That’s true for some kinds of complication and not for others.

LangGraph’s benefit grew with control flow, and I measured it directly. With one pause point, the hand-written version was shorter. With pauses possible anywhere in an agent’s loop, the hand-written loop had to be restructured, while LangGraph needed one function call. Add more branches, more agents, longer-running jobs or the ability to rewind, and the gap widens further. LangChain core’s value grows with the number of integrations you need: model providers, document loaders, embedding models, vector stores. I used one model provider and one API, so it had almost nothing to do. If I built search across all my recordings, a library would handle the chunking, embeddings and vector store far more cheaply than writing them myself.

Other complexity didn’t move at all. Choosing the fields, writing the confirmation rule, handling vague instructions and living with answers that change between runs were the hardest parts of the project, and no framework helped with any of them. Frameworks even introduced problems the hand-written versions never had: the parallel race, the double pause and the hook that silently stopped matching.

There’s a timing point as well. LangChain appeared when model APIs couldn’t return structured output or call tools reliably, and much of its early value was filling that gap. The providers’ own SDKs now do both well, so a lot of what a framework used to save you is now built into the API it wraps.

Which one I’d choose

If your job is…ChooseBecause
A few fixed model calls with a schemaThe provider’s SDKIt’s short, it hides nothing, and you can see every request
Structured extraction you need to trustPydantic AIIt sends a rejected answer back with the reason, and traces through OpenTelemetry
Connecting many models, documents and storesLangChainIts value is the integrations behind one interface
A run that can stop anywhere and resume laterLangGraphinterrupt() and a checkpointer, with no change to the agent
An agent that needs file and shell tools, subagents and permissionsClaude Agent SDKYou get Claude Code’s whole engine, with its weight

Choose the framework for the kind of complexity you actually have. The complexity in your own problem is still yours.


Who holds the loop? Series index · Method and numbers

Share this article

Email LinkedIn X

Comments

Loading comments...

Leave a Comment

All comments are moderated and may take a short while to appear.