Generative AI & Agentic AILLM fundamentals and prompt design

Compress a conversation without losing task constraints

PK
Pankit Kumar
Sr. Data Scientist at Parexel (a Goldman Sachs–backed company) · 20 September 2026 · 2 min read
Technically reviewed by Ishaan Sharma
In this article (5 sections)

Long conversations accumulate goals, formatting requirements, rejected choices, permissions and unresolved questions. A prose summary can shorten them while silently dropping the one constraint that prevents a harmful action.

Treat compression as a state transformation with invariants.

Preserve typed fields

The offline foundations lab defines five required values.

python
from foundation_cases import compression_case

result = compression_case()
assert result["passes"] is True
assert result["missing_keys"] == []
assert result["changed_values"] == []
print(result["compressed"])

The compressed record retains the goal, citation requirement, 120-word limit, approval requirement and open policy-version question. This deterministic equality check covers an authored fixture; real conversations need richer schemas and review.

Separate durable state from dialogue

Store fields such as objective, user constraints, verified facts, source references, decisions, rejected options, tool results, approvals, pending questions and next action. Include provenance: which message established the value and whether it was later superseded.

Do not convert a proposal into an approval. “We could email the customer after review” must not compress to “email the customer.” Keep authorization scope, actor and expiry explicit. Secrets and unnecessary personal data should be excluded or protected according to the application policy.

Evaluate compression by downstream tasks

Create conversations with changed dates, negative constraints, nested exceptions and conflicting corrections. Compare the structured state before and after compression. Then run the next task using full and compressed context and measure constraint violations, answer support and token reduction.

When fields conflict, preserve both with their timestamps or escalate rather than choosing silently. Allow the user or reviewer to inspect and correct durable state in consequential workflows. Version the compression prompt and schema like any other component.

The Generative & Agentic AI course connects this pattern to agent state, checkpoints and recovery.

Exercise

Write a 20-turn synthetic conversation containing one correction, one prohibition, one approval and one open question. Compress it into a typed record, add invariants for all four and demonstrate that an intentionally bad summary fails.

Continue learning

This article is part of the LLM fundamentals and prompt design sequence. Use the neighbouring tasks when you need the prerequisite or the next application.

Reference: LangGraph persistence concepts.

PK
Pankit Kumar
Lead Instructor, NeuraPath Academy

Pankit Kumar has 10 years in Data Science & AI, building and shipping production systems in regulated pharma and clinical environments. He is a freelance trainer at Boston Institute of Analytics, AnalytixLabs and Scaler, and has taught this material to thousands of working professionals.

This article is part of our Generative & Agentic AI programme — 3 months. Add practical GenAI, retrieval and agent-building skills to your existing toolkit.

Explore Generative & Agentic AI
Counselling is free · no obligation

Not sure which programme fits?

Tell us your background and we will map it to the right entry point — including saying so when a cheaper programme is the better fit. A counsellor replies within one working day.