Code Mode (programmatic tool calling)

intermediate resultmatched record
JSON tool loopContextAPI36 rows ingestedCode ModeContextSandboxAPI
  1. Same query over the same API records.
  2. JSON tool loop: intermediate results transit the context.
  3. Code Mode: a script filters inside a sandboxed runtime.
  4. Only the final return value enters context.
Notes & references

Use when

Pagination, joins, filtering and multi-tool composition.

Avoid

Single small calls, or no isolated runtime.

// written by the model, run once in the sandbox
const orders = await shop.listOrders({ month: "May" });

const late = orders
    .filter(o => o.status === "late")
    .slice(0, 3);

return late;      // only this reaches the model