feat(in-app-agent): unbounded conversation context growth — no token-budget handling on replay
Author: Yoel-qinCreated Sep 29, 2026Updated Sep 29, 2026
Labelsbugfeat-in-app-agent
Problem
The in-app agent's conversation context grows without bound. Conversation history is event-sourced in in_app_agent_events and replayed into model messages on every step, and as far as I can tell there is no token-limit handling anywhere on that path — no truncation, no rolling window, no summarization:
- Replay:
getConversationMessagesForReplay→sanitizeConversationMessagesForReplayinpackages/shared/src/in-app-agent/server/persistence.tsonly drops reasoning messages, redirect tool results, and unpaired tool calls — a syntax-level cleanup, not a budget. - The only length-related mechanisms I found are storage-side (
compactPersistedEventDeltasineventCompaction.tsmerges text/reasoning deltas) and the opt-in "silent MCP output" convention (redactSilentToolMessages, full results persisted to/workspace/tool_callsin the sandbox), which depends on the model choosing to passsilent.
So a long-running conversation eventually exceeds the model's context window and the run fails, with no graceful degradation.
Proposed direction
A token-budget layer when building replay messages:
- Estimate the replay payload against a configurable budget (tunable alongside the existing
IN_APP_AGENT_*tunables). - When over budget, replace the oldest tool-result blocks with a short reference to the already-persisted full output (the
/workspace/tool_callsconvention already gives the agent a way to re-read them via the sandbox), or with a summary placeholder event. - Only trim from the tail of the history so the cache-stable prefix (system prompt compiled per run, volatile context appended as a trailing user message by
TrailingContextProcessor) is preserved — mirroring the existing prompt-cache design. - Keep the three projections consistent: compaction happens at replay derivation, so
in_app_agent_eventsstays the lossless source of truth and the display projection is unaffected.
Scope / questions
- MVP could be tool-result-redaction only (no LLM summarization), which is deterministic and cheap to reason about; summarization could be a second step behind a tunable.
- Is this already on your roadmap for the assistant, or would a PR along these lines be welcome? Happy to write this up in more detail or start with a design sketch — the constraint I'd want maintainer input on is whether compaction should live in
sanitizeConversationMessagesForReplay(shared) or in the worker-side runtime where the model call happens.
Source: langfuse/langfuse