Operate

Compaction

Summarize older messages when the window fills.

Long orchestrator threads can blow the context window. Compaction uses LangChain SummarizationMiddleware: when the trigger hits, older messages are summarized and replaced; recent turns stay.

Defaults: trigger at 40 messages, keep the last 20. Specialists stay off by default — they usually receive one rewritten query.

python
from convax_adk import AdkSettings, Agent, resolve_model

settings = AdkSettings()
settings.compaction_enabled = True
settings.compaction_trigger = "fraction:0.75|messages:60"
settings.compaction_keep = "messages:15"

helper = Agent(
    name="helper",
    description="Handles general questions.",
    system_prompt="Answer briefly.",
)
root = Agent(
    name="desk",
    description="Routes helpers.",
    system_prompt="Coordinate the helper.",
    model=resolve_model(),
    sub_agents=[helper],
)
app = root.build(settings=settings)

Triggers accept messages:N, tokens:N, fraction:0.75, or an OR-list joined by |. Disable with settings.compaction_enabled = False. Set compaction_on_subagents only if specialists keep long histories.