One create_agent run, from invoke to the last checkpoint
One invoke of a create_agent agent runs four graph steps, makes two model calls and one tool call, and with a checkpointer saves five checkpoints.
You call agent.invoke with one question and get four messages back. The reply looks like one exchange with a model. Behind it, a graph ran four steps, the model ran twice, and a tool ran once. When a run fails later, the error names one of those steps, so you need to know their order.
When you finish this section, you can name each step of one agent run and the state after it. You can also say what a checkpointer saves at each step, and what a trace records.
The run
The agent from the first run has one tool, add, and the system prompt You add numbers.. Its model is Qwen3 4B on Ollama. It called add with 2 and 3, and then answered. This is the state at the end of the run:
{
"type": "HumanMessage",
"content": "What is 2 + 3?",
"id": "<uuid-1>"
},
{
"type": "AIMessage",
"content": "",
"id": "lc_run--<uuid-2>-0",
"tool_calls": [
{
"name": "add",
"args": {
"a": 2,
"b": 3
},
"id": "<uuid-3>",
"type": "tool_call"
}
],
…
{
"type": "ToolMessage",
"content": "5",
"name": "add",
"id": "<uuid-4>",
"tool_call_id": "<uuid-3>",
"status": "success"
},
{
"type": "AIMessage",
"content": "2 + 3 = 5.",
"id": "lc_run--<uuid-5>-0",The state holds one key, messages. The system prompt is not in it. The two model replies have ids that start with lc_run--, because LangChain gives each model output the id of its run. The human and tool messages get a plain UUID when the graph adds them. The tool call id is a UUID too, because ChatOllama makes one for each call. Each reply also carries response_metadata and usage_metadata from Ollama, with the token counts of the call.
What the model received
The kit records each call with a callback handler. The model ran twice, and both calls got the system prompt first and the same bound tool:
"call": 1,
"messages": [
"system: You add numbers.",
"human: What is 2 + 3?"
],
"tools": [
"add"
]
…
"call": 2,
"messages": [
"system: You add numbers.",
"human: What is 2 + 3?",
"ai: calls add",
"tool: 5"
],So the agent sends the whole conversation on every call, and it adds the system prompt to the front of each request. Section 3.5 explains why the prompt stays out of the state.
Step by step
Figure 1.5 draws the run. The numbers in this list match the rows of the figure.
invokeputs the input on the graph. With a checkpointer, LangGraph saves the input checkpoint, step-1.- The
__start__node writes the human message intomessages. Checkpoint step0says the next node ismodel. - The
modelnode adds the system prompt, binds the tools, and calls the model. The model answers with one tool call. Checkpoint step1says the next node istools. - The
toolsnode runsadd(a=2, b=3)and appends aToolMessagewhosetool_call_idis the id of the call. Checkpoint step2says the next node ismodel. - The
modelnode calls the model again with all three messages. The model answers with text and no tool call. - The edge after
modelsees no tool call and goes to__end__. Checkpoint step3has no next node, andinvokereturns the state.
The edges in the compiled graph say the same. Two edges out of model are conditional, and the tool calls choose between them:
[
"__start__ -> model",
"model -> __end__ (conditional)",
"model -> tools (conditional)",
"tools -> model (conditional)"
]A graph with no tools has no tools node. It is __start__, model, and __end__, and it runs one model call.
Figure 1.6 draws the graph of this agent from the Mermaid text that the compiled graph returns. Section 4.1 shows how to draw your own.
The checkpoints
Checkpoint: the saved state of one thread after one step, with the step number, the next nodes, and the id of the checkpoint before it.
The run above had no checkpointer. The kit runs the same shape of agent with InMemorySaver in two other scenarios. One asks What is 2 + 3? and then a second question on the same thread. After both turns the thread had 8 checkpoints, and the last was step 6:
"step": 6,
"source": "loop",
…
8 checkpointsThe first turn saved steps -1 to 3, which is five checkpoints. The second turn saved steps 4 to 6. It made one model call, because the model answered without a tool.
The other scenario asks a charge tool to charge 10 and reads the history back, newest first. Its steps match the list above, one for one:
"step": 3,
"source": "loop",
"next": [],
…
"step": 2,
"source": "loop",
"next": [
"model"
],
…
"step": 1,
"source": "loop",
"next": [
"tools"
],
…
"step": 0,
"source": "loop",
"next": [
"model"
],
…
"step": -1,
"source": "input",
"next": [
"__start__"
],A checkpoint whose next names a node is a place where the run can stop and resume. Part 5 says when each checkpoint is written, and what a crash between two of them repeats.
The stream of the same run
Every compiled StateGraph has the default stream mode updates, and an agent is one. So agent.stream(input) with no mode yields one chunk for each step, keyed by the node that ran:
chunk 0 keys:
[
"model"
]
chunk 1 keys:
[
"tools"
]
chunk 2 keys:
[
"model"
]Three chunks for three node runs. The __start__ step yields no chunk. Part 5 shows the other stream modes.
The trace
With tracing on, LangChain sends one run to LangSmith for each piece of work. The kit wraps the same agent in a local trace and records what the client would send:
"PATCH /runs/<run-id>": 7,
"POST /runs": 7
}
chain agent_turn
chain LangGraph
chain model
llm ChatOllama
chain tools
tool add
chain model
llm ChatOllamaThe tree has eight runs. The outer agent_turn is the traceable function of the kit, and it stayed in memory. The seven LangChain runs below it each got one POST when it started and one PATCH when it ended. Figure 1.7 draws the tree. Each node of the graph is a chain run, and the model calls and the tool call are leaves.
The recursion limit
Each step counts against the recursion limit of the run. create_agent sets that limit to 9999 on the compiled graph, just under the LangGraph default of 10007 for other graphs:
{
"recursion_limit": 9999,
"metadata": {
"ls_integration": "langchain_create_agent"
},
"configurable": {}
}A model that never stops asking for a tool runs until the limit. The kit told Qwen3 4B to count upward with add and never stop. With recursion_limit=6 in the config, the run stopped after three model calls and two tool calls, with GraphRecursionError: Recursion limit of 6 reached without hitting a stop condition.
We measured a looping agent on the x86 server guest. With Qwen3 4B, it made 121 model calls before the script stopped it at 1200 s, and it showed no sign of stopping. recursion_limit=25 stopped it after 13 model calls, in 3 of 3 runs. Set a limit that fits your task, because a loop costs every model call it makes. Raw runs
LangChain (Python): langchain, langchain-core, langgraph, deepagents, langsmith 1.5.0 · c2f4036 · 2026-11-11 · Edition 2026.11