Agents & Tool Use

LLM Agents and MCPagentsthe agent loop, tool design and the Model Context Protocol. Function Calling and Structured OutputagentsJSON schemas, validation and repair of model output. LangGraph and DSPyagentsstateful graphs for control flow and declarative prompt optimisation.

Agent loops, the Model Context Protocol, function calling with structured output, and orchestration frameworks.

An LLM agent is a loop around a model: the model chooses a tool and its arguments, ordinary code runs the tool, the result is appended to the conversation, and the model decides what to do next. This section covers the protocol layer, the reliability of tool arguments, and the frameworks that structure longer workflows.

LLM Agents and the Model Context Protocol (MCP)

An "agent" in 2026 is just a loop: the model proposes a tool call, your code executes it, you feed the result back, repeat until the model emits a fin

Function Calling and Structured Output

Most production LLM bugs are not "the model is dumb" — they're "the model returned when downstream code expected a number." This page c

LangGraph and DSPy

Two ways to build LLM apps in 2026 beyond linear LangChain chains: LangGraph , which models your app as a stateful graph with conditional edges and…

1. How the pieces fit

The Agent Loop User goal task + context LLM plan next step Tool call JSON arguments Executor your code / MCP Final answer no more tools tool result fed back Ends on a text reply or a step limit.

Three concerns recur in every agent. First, how tools are described and connected: the Model Context Protocol (MCP) standardises tool and resource discovery so one server can be reused across clients. Second, how the model's output is made machine-readable: function calling and structured output constrain responses to a JSON schema so downstream code does not have to parse prose. Third, how multi-step control flow is organised: graph frameworks make branching, retries and human approval explicit, while prompt-optimisation frameworks tune the prompts inside each step.

2. When to use which

SituationStart with
Extract fields from text into a fixed shapeStructured output, no agent loop
Model must look things up or take actionsFunction calling in a simple loop
Same tools shared across several apps or clientsAn MCP server
Branching, retries, human approval stepsLangGraph-style state graph
Prompt quality must be tuned against a metricDSPy optimisers

Use the smallest structure that works. A single structured-output call is easier to test than an agent, and a plain while-loop with a step limit is easier to debug than a framework. Add a graph or an optimiser only when the control flow or the prompt tuning becomes the hard part.

Agents usually need retrieval; see Retrieval and RAG. Running agents reliably is covered in Production, and Agent Zero describes a complete agent framework.