---
title: "Gisting: Compressing LLM Agent context to ↑ throughput and ↓ cost"
description: "Shopify compressed the ~6,000-token system prompt of its Sidekick GraphQL agent into ~1,500 learned gist tokens (4:1) without losing prediction quality."
url: "https://swe.quest/articles/gisting-compressing-llm-agent-context-to-throughput-and-cost-77b1a192c9e3be28"
canonical: "https://shopify.engineering/gisting"
source: "Shopify Engineering"
published: "2026-08-19"
difficulty: "hard"
kind: "Case study"
reading_minutes: 5
tags: ["inference","llms","model-training","cost-optimization","performance"]
---

# Gisting: Compressing LLM Agent context to ↑ throughput and ↓ cost

A post on [Shopify Engineering](https://swe.quest/sources/shopify.md), published 2026-08-19, 5 min read, Case study. Original: [https://shopify.engineering/gisting](https://shopify.engineering/gisting)

## Summary

Shopify compressed the ~6,000-token system prompt of its Sidekick GraphQL agent into ~1,500 learned gist tokens (4:1) without losing prediction quality. The gist embeddings are trained by knowledge distillation (KL divergence between full-prompt teacher logits and gist-prompt student logits) with model weights frozen, then written into the embedding matrix so serving needs no special path. Gisting complements prefix caching because decode still streams the whole KV cache per generated token. At 350 RPM, median TTFT fell 19%, end-to-end latency about 38%, and throughput rose 16%, allowing 14% fewer GPUs. Key recipe findings from an autoresearch loop: initialize gists from mean prompt-chunk embeddings, batch-level loss normalization, and precomputed teacher logits cutting training from 30 to 6 hours.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [Inference & serving](https://swe.quest/tags/inference.md) (AI & ML)
- [LLMs](https://swe.quest/tags/llms.md) (AI & ML)
- [Model training](https://swe.quest/tags/model-training.md) (AI & ML)
- [Cost optimization](https://swe.quest/tags/cost-optimization.md) (Reliability & operations)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)

## Prerequisites

- transformer inference basics ([easy posts on Inference & serving](https://swe.quest/tags/inference.md?difficulty=easy))
- KV cache ([easy posts on Caching](https://swe.quest/tags/caching.md?difficulty=easy))
- knowledge distillation
- token embeddings ([easy posts on RAG & retrieval](https://swe.quest/tags/rag.md?difficulty=easy))

## Keywords

gisting, Sidekick, prefix caching, KV cache, knowledge distillation, KL divergence

## Related posts

- [Sidekick's continual learning loop](https://swe.quest/articles/sidekick-s-continual-learning-loop-f72e46000910fa09.md): Shopify Engineering · 2026-08-05 · Hard · 9 min read · Model training, Evaluation, Inference & serving, LLMs, Cost optimization
  Shopify's Sidekick GraphQL agent improves daily through a continual learning loop that turns production failures into model weight updates, beating frontier-model quality while cutting estimated serving costs from about $27M to $1M per year (96%).
- [How GPT-5.6 fuses frontier intelligence with frontier efficiency](https://swe.quest/articles/how-gpt-5-6-fuses-frontier-intelligence-with-frontier-efficiency-a9efc2ffff6e005e.md): OpenAI · 2026-07-29 · Easy · 7 min read · Inference & serving, AI agents, Performance engineering, Cost optimization, LLMs
  GPT-5.6's cost efficiency comes from optimizations across inference and the agentic harness, many of them landed by GPT-5.6 Sol running in Codex.
- [Speeding up language models for travel applications](https://swe.quest/articles/speeding-up-language-models-for-travel-applications-59383cdd398ccff9.md): Amazon Science · 2026-10-29 · Medium · 4 min read · Inference & serving, Model training, LLMs, Performance engineering, Cost optimization
  Combining knowledge distillation with Medusa multi-token decoding let Booking.com replace large LLMs with a 1.1B-parameter TinyLlama student that matches a Llama-3.1 70B teacher while running 10 to 20 times as fast.
- [Making Knowledge Distillation Cheap Enough to Run at Scale](https://swe.quest/articles/making-knowledge-distillation-cheap-enough-to-run-at-scale-f55a4297b4be9cef.md): Hugging Face · 2026-08-10 · Hard · 8 min read · Model training, LLMs, Performance engineering, Memory management
  Two systems changes make LLM knowledge distillation far cheaper: caching the teacher's top-100 logits offline so the teacher never shares memory with the student, and a fused chunked KL loss that folds the output projection into the loss and recomputes chunks in the backward pass, so the full vocabulary × sequence logits grid is never materialized.
- [How we make AI coding more cost efficient without sacrificing task quality](https://swe.quest/articles/how-we-make-ai-coding-more-cost-efficient-without-sacrificing-task-quality-07be31d835dcfb01.md): GitHub Engineering · 2026-09-02 · Medium · 10 min read · AI agents, AI for coding, LLMs, Evaluation, Cost optimization
  GitHub Copilot cut agent costs by optimizing for whole-task outcomes rather than per-tool-call token counts, after finding that aggressive shell-output compression (RTK) made agents reread or rerun commands and raised end-to-end cost.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
