Overview
Curated: · Written: · Reviewed:
LLM Agents & Tool Use
In one line
An LLM agent lets a model choose tool calls (APIs, other models, code) across several steps instead of answering in one pass. Reach for it when the answer depends on live state or the task has side effects, and treat the model as an untrusted planner: deterministic code owns identity, authorization, validation, budgets, execution and completion.
Key definitions
- Tool contract: name, description, JSON Schema, effect class, auth context, idempotency semantics, timeout, error schema, rollback story.
- Schema validation: checks shape and types only. It does not authorize anything.
- Authorization at execution: the executor checks the authenticated subject, tenant and exact object/action/state, recomputed at call time.
- Idempotency key: a stable key reused on every retry of the same operation, so the provider can deduplicate it.
- Completion condition: a verified end state (for example a settled ledger entry), not the model's final message.
- Observation: any tool result or retrieved text. It is data, never policy.
Formulas and complexity
The step cap bounds cost and time per run. It does not stop repeated identical calls inside the cap.
How it works
The model proposes a call with arguments. The kernel validates the schema, resolves subject and tenant from the session (never the prompt), authorizes the exact target, and applies any approval gate. The executor runs the call with an idempotency key, then checks the result against the expected state before the model sees it as an observation. The loop ends only when a verified completion check passes or a budget trips.
When to use and when not to
| Situation | Use an agent loop | Prefer fixed code or a single call |
|---|---|---|
| Steps depend on live results | Yes | No |
| Path is known in advance | No | Yes |
| Read-only lookups | Yes, with budgets | Yes |
| Irreversible writes | Only behind approval and idempotent commit | Fixed workflow with checks |
| Broad shell, SQL or HTTP access | No, use narrow domain tools | No |
Traps interviewers probe
- Trusting the guard model. A second LLM that reads the ticket can be fooled by the same text. Fix: check the proposal against the order record in code (order total, original payment method, amount cap).
- Treating schema as security. A pattern like
^/data/accepts/data/../tenants/acme/x, and a tenant-agnostic handler will act on it. Fix: canonicalize the path and authorize it against the caller's tenant. - Retrying side effects with fresh keys. A new UUID per attempt makes the provider see a new refund. Fix: generate the key once per logical operation and reuse it on every retry.
- Declaring completion from a 202. Acceptance is not settlement. Fix: poll or subscribe to the terminal settled state, and treat failure states as failures.
- Approving the proposal instead of the action. Edits after approval slip through. Fix: bind approval to a canonical action hash and expiry, and have the executor recheck it before execution.
Interview tips
Open with the trust boundary: the model proposes, deterministic code decides and executes. Name the effect class of the tool first, because that sets the controls.
Expected follow-ups:
- How do you stop a retry from duplicating a charge? (Same idempotency key, provider-side dedupe window, reconcile unknown outcomes by key before retrying.)
- Where does the policy check live when several clients share a tool executor? (In the executor, keyed on caller identity, not the prompt.)
- How do you detect a stuck loop? (Hash observable state per step; identical state plus repeated identical calls triggers a stop.)
- How do you contain a runaway agent? (Revoke the credential or stop the consumer at the executor or provider, not only the agent's own flag.)
30-second outline: "The model only proposes. Each call passes schema validation, then authorization on the exact object and tenant from the session, then approval if policy requires it. Side effects carry one idempotency key across retries. Completion is a verified end state, and the loop stops on a budget or a repeated no-progress state. Tool output is data, not instructions, and every effect is audited with its policy decision."
Feedback on this overview
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.