Long conversations or dense tool outputs blow through the context window. The model forgets the goal, repeats itself, and costs spike because every turn rereads everything.
Long sessions, agents that read lots of files, research tasks that keep exploring instead of converging.
Short stateless calls. The summarisation step is overhead with no benefit when the context is already small.
Drop this into an app.yaml. Adjust the credential refs and module names to fit your existing setup.
1schema_version: 223app:4 app_id: summarize-and-feed-back5 name: "Summarise and feed back"6 version: "1.0.0"78modules:9 filesystem: { config: { workspace: "." } }10 web: {}11 memory: { config: { working_memory: true } }1213runtime:14 mode: conversation15 entry_agent: helper16 hooks:17 - id: compact_when_pressured18 "on": turn_end19 condition: { type: context_pressure, threshold: 0.7 }20 action:21 type: compact_context2223agents:24 - id: helper25 modules: [filesystem, {web: [search]}, {memory: [set_goal, remember]}]26 brain: { provider: anthropic, model: claude-sonnet-5, credential: { ref: anthropic_main, scope: per_user, provider: anthropic } }Walking through the YAML one block at a time so the design is clear, not memorised.
The hook fires at 70% of the model's context window, not at a fixed turn number. Long turns trigger it sooner, short turns later.
It's the same auto-compaction mechanism the runtime uses by default - this hook just moves the trigger point earlier, before pressure gets severe.
memory.set_goal on the first user message keeps the objective pinned. Even after older turns are summarised away, the model still sees what it's working toward.
Compaction runs only when pressure crosses the threshold, not on every turn - most sessions never trigger it at all.
The pattern above is not the only answer. Here is when something else is the right call.
Drop oldest turns silently. Cheap, lossy, can lose critical context the model needed.
Push facts into a rag knowledge base and recall them with rag.query on demand. Robust for very long-running agents, more setup, slower per-turn.
Engineering notes from the Digitorn team. No marketing, no launch announcements, no "10 prompts that will change your life". Just the things we write that we'd want to read.