When to reach for it
- The agent has so many tools that their definitions crowd the context window.
- Intermediate results are large and only a filtered part matters.
- A task chains several tool calls with loops or conditions.
One program calls many tools; only its result reaches the model.
Tools are presented to the model as a code API instead of as individual tool definitions; the model writes one program that calls several tools inside a sandbox, and only what the program logs or returns enters the model's context.
In practiceAn agent asked to attach a meeting transcript from a document store to a CRM record writes one script that fetches the transcript and updates the record; the transcript never passes through the model.
The tools stay where they are; what changes is how the model reaches them. It no longer emits one call at a time but writes a program, and the harness runs that program somewhere safe.
1 · Set up, once
2 · Every task
| Stage | Direct tool calls | As a program |
|---|---|---|
| Tool definitions | All of them in the context, up front | Two files read, on demand |
| Fetch the transcript | The whole transcript enters the context as a tool result | It lands in a variable in the sandbox |
| Update the record | The model writes the transcript out again as an argument | The variable is passed on |
| In total | 150,000 tokens | 2,000 tokens |
import * as gdrive from "./servers/google-drive";
import * as salesforce from "./servers/salesforce";
// The transcript lives in a variable. It never enters the model's context.
const transcript = (await gdrive.getDocument({ documentId: "abc123" })).content;
await salesforce.updateRecord({
objectType: "SalesMeeting",
recordId: "00Q5f000001abcXYZ",
data: { Notes: transcript },
});
console.log("Transcript attached."); // the only line the model seesWhen to reach for it
When it backfires
A tool call does one thing. A program can loop, combine tools and move data from one system to another, so an injected instruction has more to work with.
Countermeasure
Run the program in a sandbox without general network access, expose only the tools the task needs, and set limits on time and resources.
Intermediate results stay in the sandbox. A wrong record, an error message or an instruction hidden in a tool result is processed by the program and never read by the model.
Countermeasure
Validate in code what the next step depends on, log what the model has to judge, and record every tool call at the harness.
Keep going
Search patterns, frameworks, and pages.