Agent Swarm cuts AI token costs by 99.2% with code mode
The company reports that shifting from individual API calls to sandboxed scripts has reduced token consumption from an estimated 815,000 to just 6,450 for a single workflow task.
Agent Swarm has released production data demonstrating a 99.2 per cent reduction in token usage and associated costs by implementing a technique referred to as "code mode". The company states this approach is already standard practice in its swarm sessions, governed by system prompts that instruct agents to prefer scripts for bulk operations rather than making numerous individual tool calls.
The technique involves agents executing scripts within a sandboxed environment, thereby preventing raw data from entering the model's context window. By keeping large data payloads out of the conversation history, the method avoids the token inflation that typically occurs when an agent processes multiple raw JSON responses sequentially.
A specific internal script, "workflow-triage", was used as a case study to measure the impact. The script scans 24 workflows and 60 schedules to identify automation status. Under traditional methods, this task would require 26 separate API calls, with each raw payload sitting in the agent's context. The code mode implementation allowed the script to execute these calls internally, returning only a single distilled summary object to the agent.
The measurement, conducted using live production data, showed that token consumption for the task dropped from an estimated 815,000 to 6,450. This shift lowered the cost to $0.02 for the task involving 26 calls. The wall-clock execution time for the script was measured directly at 13.12 seconds, while the raw sequential call time was an estimate.
Pricing was calculated using direct-provider API rates pulled from the swarm’s live pricing table, verified on 8 July 2026, rather than router or resale prices. The specific measurement ran on Claude Sonnet 5, but the company describes the 99.2 per cent reduction figure as model-invariant, holding true regardless of the specific model used.
