claudeanthropicllmagentmcpai

How Claude Works: Context, Tool Calls and the Agent Loop

Follow a prompt through context, generated output and tool results. Separate documented API behavior from a conceptual model of inference.

CodePic Team10 min read

Quick answer

Claude generates output from the context provided to a request. Tools run through the surrounding application or a server-side feature; results can feed another model request. The diagram is a conceptual client workflow, not a disclosure of Claude’s proprietary internals.

How we verified this: Uses Anthropic’s tool-use documentation and agent design explanation. API-visible behavior is separated from simplified inference and training concepts; no exact hidden architecture or private reasoning trace is asserted.

Claude produces a response from supplied context. If a response requests a client tool, the surrounding application executes it and returns the result so Claude can continue. This context → output → tool result loop explains an agent workflow without pretending the model itself directly operates every external system.

The five frames below are a conceptual guide. Observable API behavior is different from Claude's proprietary model architecture, and a Claude app can add retrieval, tools and orchestration beyond a single model call.

The 30-second version

Claude's runtime is essentially a loop with four stages:

  1. Input Assembly — everything the model sees is packed into a single prompt
  2. Reasoning Pipeline — the model turns that prompt into a distribution over next tokens
  3. Response — tokens stream out; some become text, some are structured (tool calls, thinking blocks)
  4. Agentic Loop — if the response contains a tool call, an outer runtime executes the tool and feeds the result back into step 1

Everything else — the specific transformer architecture, extended thinking, MCP integration — is a detail sitting inside one of those four stages. If you can hold this four-stage loop in your head, you can reason about almost any Claude behavior.

Frame 1 — Input Assembly (what the model actually sees)

A request may include a system instruction, user and assistant messages, attachments, tool definitions and selected external context. Not every request has every source. The host decides what to include; connecting an MCP server does not automatically insert all its resources into the model context.

The Messages API represents these inputs with roles and content blocks. “One prompt” is a useful shorthand for available context, not a claim that the application literally concatenates everything as plain text. Text, images and other supported content can have different representations and costs.

If a response misses an important fact, check whether that fact was actually supplied or retrieved. A file existing somewhere in a workspace does not establish that the model read it. Long conversations can be truncated or summarized by an application, so also check which version of an instruction survived.

For a diagramming request, useful context includes the people or components, relationships, required labels and the desired source format. Ask for a small, checkable artifact rather than assuming the model knows your organization's private process.

Frame 2 — Inference (a conceptual view)

A language model generates output conditioned on its available context. Tokenization represents content in model-consumable units; a token is not a fixed number of English letters or Chinese characters. Use the model's counting facilities when an exact budget matters.

Next-token prediction is a useful broad explanation of text generation. It is not evidence for a specific layer count, attention topology or hidden processing sequence in Claude. This diagram intentionally avoids presenting proprietary architecture as a documented fact.

Thinking features can allocate additional generation to reasoning, depending on the model and request configuration. They are not a separate, universally ordered hardware stage after a transformer pass. Output can include documented thinking-related content, but it should not be treated as a complete transcript of internal computation.

For debugging, the practical questions are observable: which context was provided, which model and settings were used, what output was returned, and how the application handled it. Those facts are more useful than inventing a precise five-stage internal pipeline.

Frame 3 — Response (what comes out)

The output stream isn't just "text." It's a structured sequence with four possible components:

  • Streamed text tokens — the visible response, token by token
  • Thinking blocks — the extended-thinking content, optionally shown to end users
  • Tool call (JSON) — a structured request to invoke a tool with specific parameters
  • Stop reason — why the model stopped generating: end_turn (done), tool_use (waiting for tool result), max_tokens (ran out of budget)

The stop reason is the most operationally important field. end_turn means the response is complete; tool_use means the runtime needs to execute a tool before continuing. Everything about "agentic behavior" hinges on this signal.

Frame 4 — Agentic Loop (the outer runtime)

When the response includes a tool_use stop reason, control leaves the model and enters the agentic loop. This is the layer where Claude becomes an agent rather than just a text generator.

The loop has three concrete steps:

  1. Decide — actually the model already made this decision by emitting a tool call. The runtime just reads it.
  2. Execute — call the tool. Tools come in three flavors:
    • Built-in tools (like web search, code execution) — provided by Anthropic
    • User-defined tools — arbitrary functions the developer registered
    • MCP tools — external servers exposing capabilities via the Model Context Protocol. CodePic is one of these — it lets Claude create and edit hand-drawn diagrams by calling MCP tools.
  3. Feed the result back — the tool's output is encoded as a tool_result message and appended to the conversation. This is the "as next turn" arrow in the diagram: the result becomes a new user turn, and the whole loop restarts from Frame 1.

The loop terminates when a response comes back with end_turn instead of tool_use. In practice, this might be 1 iteration (simple lookup), 5 iterations (research task), or 50+ iterations (long-running agent job).

Why this matters: every "agent framework" you've heard of — LangChain, Anthropic's own Agents SDK, custom in-house harnesses — is essentially a specific implementation of Frame 4. They differ in how they manage the loop (parallel tool calls, retry logic, sub-agent orchestration), but the core shape is the same.

Frame 5 — Training Pipeline (background, not runtime)

The four frames above describe what happens every time you send a message. But the model itself is the result of a separate, one-time-ish pipeline:

  • Pretraining — feed the model an enormous text corpus, train it to predict the next token
  • Supervised fine-tuning (SFT) — give it human-written examples of good responses to specific instructions
  • Constitutional AI (RLAIF) — Anthropic's variant of RLHF that uses AI feedback guided by a written constitution to shape safe/helpful behavior
  • Red teaming — adversarial testing to find and patch failure modes
  • Deployment — the trained model gets served via the API, Claude.ai, or Claude Desktop

None of this runs when you send a message. The training pipeline is why the model in Frame 2 behaves the way it does, but at request time it's frozen. This is why the diagram puts training in a gray, dashed frame at the bottom — it's context, not part of the runtime loop.

Where MCP fits (and why it matters)

MCP appears twice in the diagram: once as an input source (Frame 1 — resources and prompts pulled from MCP servers into the context) and once as a tool type (Frame 4 — MCP tools invoked during the agentic loop).

This dual role is the point of MCP. Traditional tool use requires the developer to hand-code every tool the model can call. MCP lets tools be discovered at runtime from external servers — the model doesn't need to be retrained to gain new capabilities. Just point a Claude client at a new MCP server, and its tools are now callable.

For a concrete example: CodePic exposes an MCP server that lets Claude create diagrams by calling create_diagram or create_from_template. From Claude's side, these look identical to any other tool call. From the user's side, "make a mind map of my project" produces an actual editable diagram in the browser — because MCP bridged the two systems.

Thinking output is not an internal transcript

Thinking behavior and controls depend on the model and API version. Read the current documentation for the selected model rather than applying one configuration to every Claude release. Thinking output can be summarized or otherwise handled by the service and client; do not infer that a displayed block reveals every hidden operation.

In the API, structured thinking content is not simply an arbitrary HTML-like tag in ordinary text. Applications must handle the documented content blocks and preserve required information when continuing a tool conversation. Extra reasoning also has budget and latency implications; it is not unbounded.

Choose settings by a task you can evaluate. For a small diagram, check nodes and branches against the request. For a multi-step investigation, check the evidence and stop conditions. A longer visible explanation alone is not proof of greater correctness.

Reading the diagram in one direction

The way to read the How Claude Works diagram top-to-bottom:

  1. Follow the solid arrows through Frames 1 → 2 → 3
  2. If the response contains tool_use, follow the dashed arrow into Frame 4
  3. Follow Frame 4's inner arrows: decision → tool execution → result node
  4. Follow the dashed "as next turn" arrow back up to Frame 2
  5. Loop until you land on a response with end_turn
  6. Frame 5 sits at the bottom as background — where the model's capabilities came from, but not part of the request-time flow

That's the entire runtime. Every specific behavior — a fast one-shot answer, a long agentic session with 20 tool calls, an image-input request, an MCP-backed workflow — is a specific path through this same shape.

Try it

The How Claude Works diagram is an editable template. Open it, walk through with a specific interaction you've had with Claude, and trace which frames it touched. Understanding the shape once makes every future "why did Claude do that?" question much easier to answer.

If you build with Claude — via the API, Claude Code, or MCP — this diagram is a good thing to keep pinned. Debugging model behavior is much faster when you can point to a specific frame and say "the problem is happening here."

Trace one diagram request through the loop

Here is a hypothetical client trace, not a record of a live API call. The user asks for a refund process with an approval branch. The application supplies the relevant diagram tool schema and any required account connection. Claude can propose tool arguments, but the tool's runtime decides whether those arguments are accepted.

Observable eventWhat it establishesWhat it does not establish
A tool-use block requests a diagramThe model selected a tool and inputsThe diagram has been saved
The host executes the requestThe external operation was attemptedThe operation succeeded
A tool result returns a document IDThe tool reported an artifactEvery branch matches the requirement
The user requests a revisionA new editing task existsEarlier tool results remain current

If the tool returns an authentication error, return that error through the documented tool-result path. Do not replace it with an invented document URL. If it returns a source document, inspect the approval and rejection branches before reporting success.

Then ask for a second change: add “needs more information” as a distinct route. The host may need another tool call and another result. A final answer should identify the artifact and any unresolved validation issue rather than exposing a guessed internal thought process.

This is also why tool access and model knowledge are separate. A new tool can add an operation without retraining model weights, but a host must still register or discover it, authorize access and process the result. MCP standardizes parts of that connection; it does not make every server safe, available or automatically permitted.

Sources and verification

Official references used to verify the facts and comparisons in this article.

Frequently Asked Questions

Does the model itself execute every tool?

Client tools run through the surrounding application; some service-side tools are handled by the service. The model’s tool request and execution result are separate events.

Does connecting MCP include every resource automatically?

No. The host selects or retrieves context and controls available tools and access.

Does visible thinking show every internal operation?

No. Thinking content and display depend on the model and configuration and should not be treated as a complete internal transcript.

Does a normal request retrain the model?

Ordinary inference uses the served model. A request is not the pretraining or post-training pipeline.

Related Posts