04 / 16

Agents & Tool Use

When to let the model drive, and how to keep it on the road.

0/18 studied
01Agents vs workflows

Workflow: your code fixes the path and the LLM fills in steps. Agent: the LLM picks each next step and tool in a loop. Go single call → workflow → agent, climbing only when needed.

Core◇ Diagram</> Code
02Tool / function calling

The model never runs anything: it emits a tool name plus JSON arguments, your code validates and executes it, and the result goes back as a message so the model can continue.

Core◇ Diagram</> Code
03ReAct: the agent loop

The canonical agent loop: the model thinks, picks an action, your harness runs it and feeds back the real observation, and it repeats until done or until a cap you set stops it.

Core◇ Diagram</> Code
04Designing tools for agents (ACI)

Tool names, descriptions, parameters, outputs and errors are prompts the agent reads every call. Expose a few task-shaped tools, return concise results and actionable errors, and tune them on real-task evals.

Advanced◇ Diagram</> Code
05Pattern: prompt chaining

Split a task into a fixed sequence of LLM calls, each consuming the previous output, with code checks between steps: you trade extra latency for accuracy and per-step debuggability.

Core◇ Diagram</> Code
06Pattern: routing

Classify each input first, then send it to the prompt, model or pipeline built for that class: each path stays simple, and easy queries stop paying for the expensive model.

Core◇ Diagram</> Code
07Pattern: parallelization

Run several LLM calls at once and merge them in code: sectioning splits a task into independent parts, voting runs the same task N times. You trade extra tokens for lower latency or higher confidence.

Core◇ Diagram</> Code
08Pattern: orchestrator–workers

A central LLM reads the task, decides at runtime which subtasks it needs, delegates each to a worker LLM and synthesizes the results: parallelization where the model, not your code, writes the task list.

Advanced◇ Diagram</> Code
09Pattern: evaluator–optimizer

One LLM generates, a second evaluates the output against explicit criteria and returns specific feedback, and the generator revises, looping until the output passes or a round limit is hit.

Advanced◇ Diagram</> Code
10Planning (plan-and-execute)

A strong model writes an explicit step-by-step plan first; the steps are executed (often by a cheaper model with tools), and the agent replans only when a step fails or new facts appear.

Advanced◇ Diagram</> Code
11Agent memory

The context window is short-term memory; long-term memory lives outside the model (facts, past runs, rules) and is written, retrieved, updated and deleted by explicit policies, often exposed to the agent as tools.

Advanced◇ Diagram</> Code
12Model Context Protocol (MCP)

An open standard (Anthropic, Nov 2024) for plugging AI apps into tools and data: servers expose tools, resources and prompts over JSON-RPC, so N apps and M integrations need N+M adapters, not N×M.

Core◇ Diagram</> Code
13Agent-to-agent protocols (A2A)

An open protocol (Google, Apr 2025; v1.0 Mar 2026; now in the Linux Foundation's Agentic AI Foundation) for agents from different vendors to discover each other through an Agent Card and delegate long-running tasks over HTTP. It complements MCP (agent-to-tool).

Advanced◇ Diagram</> Code
14Multi-agent systems

Split work across several LLM agents, each with its own context and role, to gain parallelism and context isolation — paying ~15× chat tokens and coordination failures. Worth it for broad, parallel, read-heavy tasks.

Advanced◇ Diagram</> Code
15Computer use & browser agents

Agents that operate a GUI like a person: read a screenshot, then click, type and scroll. They reach apps without APIs, but are slow, brittle, costly and open to prompt injection from any page.

Advanced◇ Diagram</> Code
16Durable execution for agents

Persist the agent's state after every step so it survives crashes, deploys and multi-day human waits: resume from the last checkpoint, retry steps with idempotency keys, never re-run what already succeeded.

Staff+◇ Diagram</> Code
17Human-in-the-loop & approvals

Put a human approval gate in front of consequential or irreversible agent actions, tiered by risk, and escalate low-confidence cases — while keeping prompts rare enough that reviewers still read them.

Core◇ Diagram</> Code
18Agent reliability: budgets & loops

Agents fail by compounding small errors and by looping. Bound every run with step, token, time and dollar budgets, detect repeated calls, feed errors back structurally, checkpoint, and give tools least privilege.

Core◇ Diagram</> Code