


- Keep recent events in full fidelity so the model can reason about the freshest context.
- Summarize or compress older events into concise descriptions so the prompt stays small.
- Store large artifacts and long-lived data outside the session, and keep only references or embeddings in the summary.
Common ADK configuration example (Python)
prompt_token_count keeps climbing turn after turn, the conversation is getting more expensive — that’s exactly the issue compaction is meant to solve.
Example usage metadata
Monitor
prompt_token_count over many turns. If it spikes or grows without bound, adjust your token threshold or retention size until the prompt size stabilizes.- Large uploaded artifacts (for example, a 30‑page PDF) and long-lived project data don’t belong in the prompt. Store them in durable storage (object stores, document stores) or a vector database and keep a compact reference or an embedding in the session summary.
- When the agent needs to inspect the full content, retrieve it from storage on demand; do not include the full artifact in every prompt.
- Use token-based or sliding-window compaction to keep prompts manageable.
- Configure retention (events to keep in full) and thresholds (token caps) to match your workload and model capacity.
- Monitor usage metadata (
prompt_token_count,total_token_count) to confirm compaction is effective. - Store large artifacts and long-lived records outside the session; reference them from summaries or use embeddings for retrieval.
- Tokenization and prompt-sizing concepts: https://platform.openai.com/docs/guides/analyze-models/tokenizer (general reference)
- Vector databases and retrieval: https://www.pinecone.io/
- Document storage / indexing examples: https://www.elastic.co/guide/ (Elasticsearch guide)