Gisting: Compressing LLM Agent Context for Improved Throughput and Cost Efficiency

Shopify2026
View original source

Shopify's engineering team implemented "gisting" to compress their Sidekick GraphQL agent's system prompt from ~6,000 tokens to ~1,500 gist tokens (a 4:1 reduction) without sacrificing prediction quality. This technique uses knowledge distillation to learn embeddings for special tokens that replace lengthy natural-language prompts, allowing the model to behave as if it had seen the full prompt while reducing computational costs. At 350 requests per minute, the implementation achieved a 19% reduction in time to first token (438ms to 354ms), a 38% decrease in end-to-end latency (6.8s to 4.2s), and a 16% increase in throughput (20.2 to 23.4 QPS), ultimately enabling Shopify to reduce GPU allocation by 14% for their GraphQL agent traffic.

Industry

E-commerce

Technologies

Overview

Shopify’s engineering team developed and deployed a production implementation of “gisting” for their Sidekick GraphQL agent, addressing a critical LLMOps challenge: the computational and economic costs of long system prompts in production LLM deployments. This case study demonstrates how Shopify optimized their LLM inference pipeline to achieve significant improvements in latency, throughput, and resource utilization without compromising model quality.

The core problem Shopify faced was that system prompts for their LLM agents could account for thousands of tokens per request. In their GraphQL agent specifically, the system prompt consumed approximately 6,000 tokens. Longer prompts translate directly to slower and more expensive inference, requiring more GPUs to accommodate the same traffic volume when serving models on dedicated hardware. This presents a fundamental tension in LLMOps: comprehensive system prompts that provide detailed instructions and context improve model behavior and reliability, but they also impose substantial operational costs.

Technical Implementation of Gisting

Gisting, as originally proposed in the 2022 paper “Prompt Compression and Contrastive Conditioning for Controllability and Toxicity Reduction in Language Models” by Wingate, Shoeybi, and Sorensen, offers an elegant solution to this problem. The technique compresses context into a set of learned tokens while preserving the quality of the model’s outputs, making the model both faster and cheaper to run in production.

The implementation works by introducing special “gist tokens” to the model’s vocabulary. These gist tokens are trained such that their embeddings, when substituted for the full natural-language prompt, induce the model to behave as if it had seen the complete original prompt. At Shopify’s chosen 4:1 compression ratio, one gist token replaces every four tokens from the original prompt. Critically, the approach freezes the weights of the base model and only trains the gist embeddings themselves, making it a lightweight intervention that doesn’t require full model retraining.

The learning process relies on knowledge distillation. For each training trajectory, Shopify runs two forward passes through the model. In the “teacher pass,” the model processes the full natural-language prompt and generates teacher logits for each position in the response. In the “student pass,” the gist tokens replace the full prompt, and the same frozen model runs again to produce student logits. The gist embeddings are optimized using the KL divergence between teacher and student logits, training until the student’s predictions closely match the teacher’s behavior.

A particularly valuable aspect of this approach from an operational perspective is its simplicity at deployment time. Once training completes, the learned gist embeddings are written directly into the model’s embedding matrix, and the new gist tokens are registered as special tokens in the tokenizer. The resulting model loads and runs like any standard model at inference time—no custom attention masks, additional encoders, or special serving paths are required. The only change needed is on the request side: replacing the natural-language prompt with the string of gist tokens. This design means the entire computational cost of compression is paid once during training, not repeatedly at inference time.

Relationship to Prefix Caching

Shopify’s case study provides important clarity on how gisting relates to prefix caching, a common optimization in modern LLM serving. All contemporary serving engines maintain a KV (key-value) cache that stores keys and values for previously-seen sequences. When new requests include sequences that exist in the cache (typically including the system prompt), the KV tensors for those sequences are fetched rather than recomputed, saving prefill computation.

However, as Shopify correctly notes, prefix caching doesn’t eliminate decode costs. Every time the model generates a token during the decode phase, that token must attend over every key in the sequence, whether cached or not. Because decode is memory-bandwidth-bound, each generated token requires streaming the entire KV cache from high-bandwidth memory, and this memory read grows linearly with the cached sequence length. Gisting reduces both the cost of attention computations and KV cache reads—the latter being especially impactful on throughput when batch sizes grow large.

Importantly, the optimizations of gisting and prefix caching are complementary and compound each other. Shopify uses both in their experimental setup and production serving infrastructure, demonstrating mature LLMOps practice that combines multiple optimization techniques rather than viewing them as alternatives.

Hyperparameter Optimization Through Autoresearch

Shopify employed an autoresearch loop to tune hyperparameters for their gisting implementation, demonstrating sophisticated MLOps practices. The autoresearch system proposes a recipe (hyperparameter configuration), trains gist embeddings, evaluates the resulting model, and iterates. This automated experimentation approach is crucial for LLMOps at scale, where manual hyperparameter tuning would be prohibitively expensive.

Three optimizations emerged as particularly high-impact from this autoresearch process:

Initialization strategy: Rather than initializing gist embeddings with random noise, Shopify split the system prompt into sequences of length k (where k derives from the k:1 compression ratio) and initialized the nth gist embedding with the mean of the nth system prompt chunk. This seemingly simple change reduced initial loss by a factor of 7, dramatically accelerating training convergence.

Compression ratio selection: Through systematic experimentation across a range of compression ratios, Shopify identified 4:1 as optimal for their domain’s complexity. Beyond this ratio, prediction quality began to degrade. This finding highlights an important LLMOps principle: optimal hyperparameters are domain-specific and require empirical validation rather than assumption. What works for one use case may not transfer directly to another.

Data quantity and diversity: Curating a large and diverse training dataset closed the remaining quality gap. This emphasizes that even with clever architectural innovations like gisting, data quality and coverage remain fundamental to production LLM performance.

Beyond hyperparameter selection, the autoresearch loop also drove important training infrastructure optimizations. Shopify discovered that their loss normalization strategy significantly impacted results: averaging loss per response token caused the model to hallucinate, while averaging over the batch preserved more signal from long responses and produced stable embeddings. They also achieved major efficiency gains by precomputing teacher logits and pre-tokenizing data, cutting a full training run from thirty hours to six—a 5x speedup that makes iterative experimentation far more practical.

Production Performance Results

Shopify conducted rigorous load testing comparing the gisted model against the full-prompt baseline, providing concrete data on production performance improvements. At 350 requests per minute (RPM)—a realistic production load—the results were substantial:

These improvements become even more pronounced as request concurrency rises and batches grow larger, which is exactly the scenario that matters most for production serving at scale. The latency reductions directly improve user experience, while the throughput gains translate to better hardware utilization.

Most importantly from a business perspective, the 16% throughput gain translated directly into GPU savings. For the hardware configuration serving Shopify’s GraphQL agent traffic, they were able to reduce GPU allocation by 14%. In an era where GPU demand consistently outpaces supply and cloud GPU costs are substantial, this represents meaningful cost savings and improved resource efficiency.

Integration with Continual Learning

Shopify’s case study also describes how gisting integrates with their continual learning loop, demonstrating forward-looking LLMOps architecture. Once they have distilled gist embeddings for a model, they can treat that model as a new starting point for continual learning. They can apply post-training using the gist embeddings as the prefix and update gradients for both the model weights and the gist embeddings themselves.

This approach allows Shopify to continuously calibrate and improve their models on incremental data without the computational burden of distilling gist embeddings from scratch each time. This is a sophisticated LLMOps pattern that balances the need for ongoing model improvement with computational efficiency—a critical consideration for sustainable production ML systems.

Critical Assessment

While Shopify’s results are impressive, it’s worth considering the technique’s limitations and applicability. The 4:1 compression ratio that worked for Shopify’s GraphQL agent may not generalize to all domains or prompt types. As Shopify acknowledges, “other domains vary,” suggesting that teams adopting this approach should budget for experimentation to find their optimal compression ratio.

The technique also requires an upfront investment in training infrastructure and data curation. Shopify’s autoresearch loop and the ability to iterate rapidly (even with the optimized 6-hour training time) suggests significant engineering resources. Smaller teams may find the initial setup cost prohibitive, though the long-term inference savings could justify the investment.

Additionally, while Shopify reports no loss in prediction quality, they don’t provide detailed evaluation metrics or describe their quality assessment methodology. Production LLM evaluation remains challenging, and understanding exactly how they validated that gisting preserved behavior would strengthen the case study’s technical rigor.

The interaction between gisting and other prompt optimization techniques also warrants consideration. How does gisting perform when combined with techniques like few-shot prompting, chain-of-thought reasoning, or other prompt engineering patterns? The case study focuses on system prompts, which are typically static instructions, but production LLM systems often involve dynamic prompting strategies.

Broader LLMOps Implications

Shopify’s gisting implementation exemplifies mature LLMOps practices in several ways. First, it demonstrates a quantitative, metrics-driven approach to optimization, with clear measurement of latency, throughput, and resource utilization. Second, it shows intelligent composition of multiple optimization techniques (gisting plus prefix caching) rather than seeking a single silver-bullet solution. Third, the integration with continual learning shows architectural thinking beyond immediate optimization toward sustainable, evolvable systems.

The case study also highlights the importance of inference optimization in the current GPU-constrained environment. While much ML discussion focuses on training efficiency, Shopify’s work underscores that inference costs dominate for production systems serving high request volumes. A 14% reduction in GPU requirements for a single agent represents substantial cost savings when multiplied across an organization’s ML workloads.

Finally, Shopify’s adoption of gisting “as the new standard” suggests they view this not as an experimental optimization but as a production-ready technique suitable for widespread deployment. This represents a meaningful validation of the approach beyond academic research, though it also reflects Shopify’s specific engineering capabilities and infrastructure maturity.

Conclusion

Shopify’s implementation of gisting for their Sidekick GraphQL agent demonstrates how academic research in prompt compression can be successfully operationalized to solve real production LLMOps challenges. By compressing 6,000-token system prompts to 1,500 gist tokens while maintaining prediction quality, they achieved significant improvements in latency, throughput, and resource efficiency. The 14% reduction in GPU requirements particularly stands out as a concrete business outcome in an environment where GPU resources are constrained and expensive.

The case study showcases sophisticated LLMOps practices including automated hyperparameter optimization, careful attention to training infrastructure efficiency, rigorous production load testing, and forward-looking integration with continual learning systems. While some details about evaluation methodology and generalization would strengthen the technical narrative, the reported results are compelling and the approach appears sound. For organizations operating LLM agents at scale with lengthy system prompts, gisting represents a promising optimization technique worth serious consideration, though teams should expect to invest in experimentation to adapt the approach to their specific domains and requirements.

More Like This

Large-Scale Personalization and Product Knowledge Graph Enhancement Through LLM Integration

DoorDash2025

DoorDash faced challenges in scaling personalization and maintaining product catalogs as they expanded beyond restaurants into new verticals like grocery, retail, and convenience stores, dealing with millions of SKUs and cold-start scenarios for new customers and products. They implemented a layered approach combining traditional machine learning with fine-tuned LLMs, RAG systems, and LLM agents to automate product knowledge graph construction, enable contextual personalization, and provide recommendations even without historical user interaction data. The solution resulted in faster, more cost-effective catalog processing, improved personalization for cold-start scenarios, and the foundation for future agentic shopping experiences that can adapt to real-time contexts like emergency situations.

customer_supportquestion_answeringclassification+64

Building Production AI at Scale with Internal Tooling and Agent-Based Systems

Shopify2026

Shopify's CTO discusses how the company has achieved near-universal AI adoption internally, with nearly 100% of employees using AI tools daily as of December 2025. The company has developed sophisticated internal platforms including Tangle (an ML experimentation framework), Tangent (an auto-research loop for automatic optimization), and SimGym (a customer simulation platform using historical data). These systems have enabled dramatic productivity improvements including 30% month-over-month PR merge growth, significant code quality improvements through critique loops, and the ability to run hundreds of automated experiments. The company provides unlimited token budgets to employees and emphasizes quality token usage over quantity, focusing on efficient agent architectures with critique loops rather than many parallel agents. They've also implemented Liquid AI models for low-latency applications, achieving 30-millisecond response times for search queries.

code_generationcustomer_supportchatbot+48

Agentic AI Copilot for Insurance Underwriting with Multi-Tool Integration

Snorkel2025

Snorkel developed a specialized benchmark dataset for evaluating AI agents in insurance underwriting, leveraging their expert network of Chartered Property and Casualty Underwriters (CPCUs). The benchmark simulates an AI copilot that assists junior underwriters by reasoning over proprietary knowledge, using multiple tools including databases and underwriting guidelines, and engaging in multi-turn conversations. The evaluation revealed significant performance variations across frontier models (single digits to ~80% accuracy), with notable error modes including tool use failures (36% of conversations) and hallucinations from pretrained domain knowledge, particularly from OpenAI models which hallucinated non-existent insurance products 15-45% of the time.

healthcarefraud_detectioncustomer_support+90