Page 5 of 8~120 min topic

Tools in code

Debug string-eval calculator in the tool registry runtime

Page 5 reproduces and repairs the characteristic failure of the calculator + knowledge lookup tool registry: string-eval calculator, or lookup that returns entire DB on missing id.

~15 min this pageDebugging

1Learn the idea

Read

Reproduce before you repair

Do not start with a speculative fix for the tool registry runtime. Force the failure on purpose, save the before output, then change one cause at a time. Retries are allowed only for transient conditions—not for bad input that will fail forever on tools-in-code.

Read

Force the failure

for (let attempt = 0; attempt <= maxRetries; attempt++) {
  try { return await operation(signal); }
  catch (error) {
    const failure = classify(error);
    if (!failure.retryable || attempt === maxRetries) throw failure;
    await sleep(jitteredBackoff(attempt), signal);
  }
}
throw new Error("unreachable");

Expected evidence: duplicate names, stale schemas, timeouts, oversized results, and unsafe side effects. If you cannot reproduce on demand, you do not yet control the failure mode for tools-in-code.

Read

Repair with a reviewable diff

After repair, rerun the exact reproduction command. Keep the failing fixture as a regression seed for the observability page. For the calculator + knowledge lookup tool registry, remember the claim you are restoring: unknown tools are rejected; calculator and lookup return typed results.

Read

Lab notebook: reproduce on command

Store a one-command reproduction for: string-eval calculator, or lookup that returns entire DB on missing id. The command should use registry with calc and kb.lookup or a minimal mutant of it. Paste the failing output into notes/failure-before.txt (or your shell scrollback as copied text). After the fix, paste notes/failure-after.txt and keep both.

Retries belong only on transient faults. If the failure is bad input, a bad allowlist, or a logic bug in the tool registry runtime, retrying will amplify cost without repairing trust around route model tool requests through a registry that validates names and args.

Read

Worked judgment

Classify the failure as prevent, detect, contain, or recover—using this lab’s language, not a generic poster. For tools-in-code, the first fix should usually be detect+prevent at the boundary, because string-eval calculator, or lookup that returns entire DB on missing id is cheaper to stop early than to explain in production prose.

Read

Why this stage matters for the tool registry runtime

At the debugging stage for tools-in-code, the job is narrower than finishing a product demo. You are creating one progressive evidence piece about registry with calc and kb.lookup that later pages inherit without redefining success. Keep that fixture small enough to inspect by hand, keep outputs copy-pasteable as text, and refuse to narrate this baseline as if it were a production SLA: inline if/else tool routing without schemas.

For this page specifically, success looks like before/after evidence for the characteristic failure while still centering the user decision to route model tool requests through a registry that validates names and args. If you cannot point to a file, command, or assertion that proves that for the tool registry runtime, stay on this page instead of advancing.

Glossary: tool · Glossary: structured output · Cheatsheet: production ops signals

Previous · Next

Go deeper

Before you start

Why this matters

Describe the smallest fixture that triggers string-eval calculator. Predict the first visible symptom (exception, wrong label, silent empty success). You will compare that prediction with the reproduction below.

In the wild

See how this idea shows up as a product and a company — then come back to the lesson. Skills transfer across vendors.

Check your understanding

Page assessment

Answer from memory. Completion is saved from this evidence, not from opening the next page.

1. Can you reproduce the failure with a one-command fixture?
2. Did you avoid retrying non-transient bad input?
3. Is before/after evidence saved as text (not only a screenshot)?
4. Does the repair restore the metric path toward: allowlist reject count?

All responses are required.