The 2026 shift from tool-calling to Code Mode: let the agent write one script instead of narrating fifty tool calls — and watch context tokens drop ~99%.

TL;DR: The classic agent loop loads every tool definition into the context window and pipes every intermediate result back through the model. Connect a few dozen tools and the context is full before the user even speaks. The 2026 move — Code Mode — is to let the agent write one short script that calls tools directly; bulk data stays in a sandbox and only the final answer comes back. In a tiny runnable demo it cut context from 36,781 tokens to 222 — a 99.4% reduction. Same answer, no API key.

Mental model: instead of reading a worker every page of 50 manuals and every row of a spreadsheet out loud, you hand them the 3 manuals the job needs and let them do the math at their own desk. You only get back the final answer — not the raw data.

The problem: tool-calling doesn't scale with tool count

Function/tool-calling is how most agents act today. It works beautifully with five tools. But the whole tool surface gets serialized into the context window on every request, and every intermediate result the model asks for is streamed back through the context too.