1.3

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:

jsonthe final state of one runFull log
  {
    "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 key list and the metadata of each reply are cut. All four messages are shown.

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:

jsonthe two model callsFull log
    "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"
    ],
Cut to the messages and the bound tools. The model label is cut.

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.

Fig. 1.5one create_agent run, step by stepsequence
One create_agent run, step by step Five lifelines under small drawings: your code as a terminal, the model node, the chat model, the tools node, and the checkpointer as a cylinder. A sixth column shows the messages in each checkpoint as chips. Six numbered steps, which match the list in the text: 1, the input checkpoint at step -1 with no messages and next __start__. 2, the checkpoint at step 0 with the human message and next model. 3, the model node calls the chat model with the system prompt "You add numbers." and the human message, gets a tool call add with 2 and 3, and saves step 1 with next tools. 4, the model node sends the tool call to the tools node, which saves step 2 with the ToolMessage for <uuid-3> and next model. 5, the second model call gets 4 messages and answers "2 + 3 = 5.". 6, the checkpoint at step 3 has 4 messages and no next node, and invoke returns them. your code agent.invoke model node model chat model agent tools node add checkpointer InMemorySaver STATE.MESSAGES in each checkpoint put, step -1 next: __start__ empty 1 put, step 0 next: model H 2 call 1: 2 messages tool_calls: add(2, 3) put, step 1 next: tools H AI 3 Send: add, <uuid-3> put, step 2: ToolMessage 5 next: model H AI T 4 call 2: 4 messages 2 + 3 = 5. 5 put, step 3 next: none H AI T AI 4 messages 6 H human AI AIMessage T ToolMessage bold: new in that step
The model node runs twice and the tools node once, and the checkpointer saves the state after the input and after each of the four steps. Read the rows from top to bottom. Each teal arrow is one checkpoint, with its step number. The amber note under each checkpoint is the node that runs next. The chips on the right are the messages in each checkpoint, and a bold chip is new in that step.
  1. invoke puts the input on the graph. With a checkpointer, LangGraph saves the input checkpoint, step -1.
  2. The __start__ node writes the human message into messages. Checkpoint step 0 says the next node is model.
  3. The model node adds the system prompt, binds the tools, and calls the model. The model answers with one tool call. Checkpoint step 1 says the next node is tools.
  4. The tools node runs add(a=2, b=3) and appends a ToolMessage whose tool_call_id is the id of the call. Checkpoint step 2 says the next node is model.
  5. The model node calls the model again with all three messages. The model answers with text and no tool call.
  6. The edge after model sees no tool call and goes to __end__. Checkpoint step 3 has no next node, and invoke returns 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:

jsonthe edges of the agent graphFull log
[
  "__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.

Fig. 1.6the graph of the agent in this runstructure
The graph of the agent in this run The compiled graph of create_agent with one tool, drawn from its draw_mermaid output. It has 4 nodes: __start__, model, tools, __end__. One plain edge goes from __start__ to model. Three conditional edges go from model to tools, from model to __end__, and from tools back to model. The tools node lists the tool add. THE COMPILED GRAPH 4 nodes, 1 plain edge, 3 conditional __start__ model tools __tools = add __end__ plain edge conditional edge, chosen at run time
One plain edge leads into model, and three conditional edges leave model and tools, so the run picks its path at run time. Read from __start__ at the top. Solid arrows are plain edges, and dashed amber arrows are conditional edges. The tools node lists its one tool.

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:

outputthe thread after two turnsFull log
  "step": 6,
  "source": "loop",
…
8 checkpoints
Cut to the step of the last checkpoint and the count.

The 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:

jsonthe history of one turn, newest firstFull log
  "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__"
  ],
Cut to the step, the source, and the next nodes of each checkpoint. The ids and the messages are cut.

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:

jsonthe chunks of a stream with no modeFull log
chunk 0 keys:
[
  "model"
]

chunk 1 keys:
[
  "tools"
]

chunk 2 keys:
[
  "model"
]
The last section of the file. Each chunk is cut to its keys.

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:

outputthe runs of one traced agent turnFull log
  "PATCH /runs/<run-id>": 7,
  "POST /runs": 7
}

chain agent_turn
  chain LangGraph
    chain model
      llm ChatOllama
    chain tools
      tool add
    chain model
      llm ChatOllama
Cut to the request counts and the tree of runs, which sit at lines 82 to 99 of the file.

The 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.

Fig. 1.7the runs of one traced agent turntree
The runs of one traced agent turn An indented tree of 8 runs in the order they started, one row each: chain agent_turn, chain LangGraph, chain model, llm ChatOllama, chain tools, tool add, chain model, llm ChatOllama. The root agent_turn is the traceable function of the kit, inside tracing_context with enabled local, and it stayed in memory. Each of the 7 runs below it has a dashed olive arrow to a client lane on the right, because the client got one POST /runs when the run started and one PATCH when it ended: 7 POST and 7 PATCH in all. Each graph node is a chain run, the two model calls are llm leaves, and the tool call is a tool leaf. the client records each request RUN TREE, IN THE ORDER THE RUNS STARTED name above its run type agent_turn chain run kept in memory: tracing_context(enabled='local') LangGraph chain run POST, then PATCH model chain run ChatOllama llm run tools chain run add tool run model chain run ChatOllama llm run 7 runs below the root, 7 POST /runs and 7 PATCH at the client. a graph node a model call a tool call
A traced turn is a tree of runs, with one chain run for each graph node and one leaf for each model call and tool call. Read from the root at the top. Each box is one run, with its name above its run type. The violet root stayed in memory, and the client got the seven runs below it. The plum leaves are model calls and the green leaf is the tool call.

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:

jsonthe config on the compiled agentFull log
{
  "recursion_limit": 9999,
  "metadata": {
    "ls_integration": "langchain_create_agent"
  },
  "configurable": {}
}
The config of the compiled graph, from the same file.

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