Urgent.News

What's breaking now, across thousands of outlets.

Tech

The systems guide to production token optimization

When enterprise AI applications scale, they inevitably hit a wall. For many engineering teams this wall is initially diagnosed as The post The systems guide to production token optimization appeared first on The New Stack .

The systems guide to production token optimization

Enterprise AI applications often face a cost barrier during scaling. Initially, engineering teams may attribute this to billing concerns, but token consumption should not be viewed as merely a financial matter. Instead, it is a distributed systems and hardware utilization challenge. This article examines how two agents, Concierge and Pathfinder, were affected by autoregressive bottlenecks as they expanded, and discusses solutions for optimization.

Tokens are not solely words. They are subword units produced through byte-pair encoding (BPE). While common words remain intact, rarer words or punctuation become fragmented. Budgeting in production must account for the differentiated pricing of input and output tokens, with output tokens being 4-5 times more expensive than input tokens.

LLM provider APIs are completely stateless, meaning the model's prior outputs are repeatedly billed as inputs for subsequent steps. This compounding effect leads to a quadratic increase in input token volume and costs. For Concierge, a latency-sensitive, synchronous agent, this results in 45,300 tokens consumed per 10-turn ticket. Pathfinder, an asynchronous, multi-step agent, has a steeper cost curve with 150,000 tokens consumed per 15-step turn.

To address these issues, we implemented prompt hygiene by removing static reference documentation from the system prompt and switching to dynamic injection. Concierge's prompt size was reduced from 3,100 tokens to 380 tokens, a 60% reduction for a 10-turn thread. Pathfinder applied automated prompt compression using LLMLingua-2, decreasing incoming tool observations by 3X without sacrificing debugging accuracy.

Another optimization involved eliminating retries. Instead of open-ended instructions, strict structural contracts via forced schema validation were enforced for output format. This converted the output format to a strict pydantic schema for tool-calling mode and tool-execution payloads, eliminating malformed outputs and tail latency spikes caused by cascading queues.

Written by urgent.news from The New Stack's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at thenewstack.io →

More in Tech

More from Thursday 3 September →