Lab 02 — Understand tool calling
From cognokratos/simple-agent-template · docs/tutorials/02-understand-tool-calling.md · pinned revision a02b5367273a
Objective
See exactly what the model is given (tool names, descriptions, schemas), how that steers its choices, and where the line falls between the model requesting a call and the runtime executing it.
Concept
A tool is an externally implemented capability exposed through a typed interface. The model chooses a tool and arguments based purely on text you wrote: the description and the schema. Tool descriptions are prompts. → Concept 2
Architecture before
flowchart LR
LLM{{LLM}} -->|"tool_call: name + JSON args"| RT[Rust agent]
RT -->|"tools/call"| MCP[MCP server]
MCP --> DB[(PostgreSQL)]
Exercise
- Read the two tools in
mcp-server/src/main.rs: the argument structsSearchTicketsArgsandGetTicketArgs(the doc comments become schema descriptions), and the#[tool(description = ...)]on each function. - Read
tools.mcpinagent/config.yml. Noteinclude(which tools the agent may use at all) andoverrides(the descriptions the model actually sees, which replace the Rust ones). - Read the
workflow.system_promptrules that mention tools.{tools}and{tool_names}are filled in by the agent at startup from MCP discovery. - Optionally, look at the raw MCP surface with the loopback-only, token-gated MCP Inspector:
make inspector # start the optional inspector (dev profile)
make inspector-tools # tools/list straight from the MCP server, bypassing the agent
make open-inspector # or browse it
Run it
Run these scenarios from TEST-SCENARIOS.md in the UI, and watch the tool cards:
| Prompt | Expected tools |
|---|---|
Show me my open tickets. | search_tickets(status="open") |
Show me the complete details and history for ticket TKT-1001. | get_ticket(ticket_id="TKT-1001") |
Show me the complete details for ticket TKT-9999. | get_ticket, which returns a "not found" error |
What kinds of support ticket questions can you help me with? | none |
Show the history for all open tickets. | search_tickets, then get_ticket × 5 |
Observe
- Expand a tool card: the input is exactly the JSON the model produced, and the output is what the MCP server returned, with credential-shaped values redacted and configured PII masked for display. The model sees the raw output on its next turn.
TKT-9999: the tool'sinvalid_paramserror ("Ticket 'TKT-9999' was not found") reaches the model as the tool's result (mcp/tools.rsreturns it asError: …rather than failing the run). Observed answer on the default model: "The ticket ID "TKT-9999" could not be found. Please verify the ticket ID and try again."- The last prompt is the interesting one. Count the
get_ticketcards. On the default model we observed threeget_ticketcalls for five open tickets, in every run, on the retired NAT agent (details, and what to compare, in lab 04).
Break it
Both changes are local edits to agent/config.yml, followed by
make rebuild-agent. Revert afterwards.
A. Remove the fan-out instruction. In tools.mcp.overrides.get_ticket.description,
delete the sentence "When the user asks for history across multiple tickets,
call this tool separately once for every ticket ID returned by search_tickets."
Rebuild and rerun "Show the history for all open tickets." several times.
Count get_ticket calls and compare with the baseline above.
B. Remove a capability. Delete - get_ticket from tools.mcp.include.
Rebuild and ask for TKT-1001's history. Then:
make logs-agent
At startup the agent logs the tools it kept after discovery:
discovered MCP tools tools=["get_ticket", "search_tickets"]
Compare that line before and after the change. Then try asking for
limit: "5" (a string, not an integer) or an extra argument.
Why it failed
- A shows that descriptions are behavioural configuration. Whatever you
observed (more calls, fewer, no change), the description is an input to a
probabilistic decision, and only repeated runs or an evaluation tell you its
effect. The
toolssuite exists for exactly this (TOOLS-FANOUT-OPEN-TICKETS). - B is deterministic: a tool not in
includeis never advertised to the model, and before any tool runs the agent asks one deterministic policy,ToolPolicy::decideinguardrails/tools.rs, at Rig's dispatch hook. A call to a tool outside the allow-list, a wrongly typed argument or an undeclared field is refused — never coerced — with a reason the model sees, and the trace shows atool.policyspan withpolicy.decision = deny. No prompt can make the runtime call a removed tool. Capability is configuration and code, not model behaviour. That is the property later labs rely on. → Agent internals, lessons 04–06
Architecture after
Unchanged, but you can now name every input to the model's tool decision:
flowchart LR
SP[system_prompt rules] --> LLM{{LLM}}
TO["tools.mcp.overrides<br/>descriptions"] --> LLM
SC["JSON schemas<br/>from Rust structs"] --> LLM
INC["tools.mcp.include"] -->|"filters what exists"| RT[Rust agent]
LLM -->|"requests"| POL[ToolPolicy::decide] -->|"allowed"| RT -->|"executes"| MCP[MCP server]
What you learned
- The model sees names, descriptions and schemas, never your code.
- Tool descriptions steer behaviour as strongly as the system prompt, and need evaluating the same way.
- Errors returned as data let the agent explain failure instead of inventing.
tools.mcp.includeand the tool policy are a hard capability boundary. Descriptions are soft guidance.