Skip to content

Compact mid-turn when a tool loop fills the context #184

Closed

Description

@hakula139

Goal

Auto-compaction runs only between prompts, so a single long tool loop can exceed the context window before the turn ends. Compacting at a round boundary within the turn lets long agentic runs continue without user intervention.

Acceptance criteria

  • When usage after a tool round crosses the auto-compaction threshold, the loop compacts before the next model request and continues the same turn from the summary.
  • Compaction occurs after every tool result in the round has been recorded, so the transcript never contains an unresolved tool call.
  • The summary preserves the in-progress task, and the continuation message tells the model to resume it.
  • Queued prompts and cancellation behave as they do at other round boundaries.
  • The existing failure circuit breaker also covers mid-turn attempts.
  • A failed mid-turn compaction ends the turn with TurnFailed and a hint to run /compact.
  • The auto-compaction design doc describes the new trigger point and amends decisions 3 and 7.

Notes

Mid-turn compaction conflicts with two decisions in the auto-compaction design doc: decision 3 (boundary-only compaction) and decision 7 (no automatic continue prompt).

Decision: amend both. Compaction may also run at a round boundary inside a turn, and only that mid-turn case adds an automatic continuation message, since the model is resuming work the user already asked for. Compaction between prompts still waits for user input.

Metadata

Metadata

Assignees

Labels

area: agentenhancement

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions