Skip to content

LLM CLI: add auto-compacting#11297

Merged
vito merged 15 commits into
dagger:mainfrom
vito:llm-compact
Nov 6, 2025
Merged

LLM CLI: add auto-compacting#11297
vito merged 15 commits into
dagger:mainfrom
vito:llm-compact

Conversation

@vito
Copy link
Copy Markdown
Contributor

@vito vito commented Oct 24, 2025

Adds two pretty low-level APIs to LLM for clearing either system prompts or user messages. The compaction dance uses both: first we swap out the system prompt, since the compacting agent is single-purpose, and then we swap out the user messages with the prompt returned by the compacting agent.

The compacting agent is implemented in the CLI at the moment. An earlier iteration had this directly implemented by the API (LLM.compact) but this setup gives us a bit more flexibility without requiring us to maintain a compacting prompt in the core API.

@vito vito requested review from a team as code owners October 24, 2025 22:04
@vito vito requested a review from kpenfound October 24, 2025 22:04
@vito vito force-pushed the llm-compact branch 2 times, most recently from 6f3452d to c89b89a Compare November 4, 2025 18:13
Comment thread cmd/dagger/llm.go
break
}

// Check if we need to compact in-between steps
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems, from reading the code, that we call autoCompact while HasPrompt could still true, so Compact + WithoutMessageHistory() would wipe the tool-output user message that the next Step is supposed to send no ?

Basically, we seem to have chosen to allow compaction in-between steps, which could be a destroying operation ?

What was the impact on the agent’s ability from your experience?

To test, I dropped the compaction threshold to 0.1 (even 0.0 but this led to an infinite loop ahah): it seemed fine-ish on small vibe feeling tasks

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well - you have to interrupt to auto-compact at some point, otherwise the agent will just keep going and going until it thinks it's done, and the point of auto-compacting is to keep it from blowing out the context window while it's working away.

Basically, we seem to have chosen to allow compaction in-between steps, which could be a destroying operation ?

The tool results are fed to the compacting agent, since that works by just appending the compacting prompt to the message history so far. So they're not really dropped; they're fed in with the rest of the history, and then the entire history is reset to the summarized prompt.

What was the impact on the agent’s ability from your experience?

It's been decent; compacting will always be lossy, and there have been moments where I wanted to disable it, but overall it's helped a lot for long-running sessions, and acts as a nice defensive mechanism for when the agent gets caught down a bad path and needs to take a step back.

vito added 14 commits November 6, 2025 14:53
Signed-off-by: Alex Suraci <alex@dagger.io>
These are useful building blocks for implementing support for
summarizing/compacting message histories, without coupling the core to a
specific prompt.

Signed-off-by: Alex Suraci <alex@dagger.io>
Signed-off-by: Alex Suraci <alex@dagger.io>
Signed-off-by: Alex Suraci <alex@dagger.io>
Signed-off-by: Alex Suraci <alex@dagger.io>
Signed-off-by: Alex Suraci <alex@dagger.io>
Signed-off-by: Alex Suraci <alex@dagger.io>
Feels like this is generically useful - Doug was implementing this for
EditFile, and now doesn't need to.

Signed-off-by: Alex Suraci <alex@dagger.io>
Signed-off-by: Alex Suraci <alex@dagger.io>
* mark AsPatch output as verbose so we can opt to show the whole thing
  when it's reasonably sized

Signed-off-by: Alex Suraci <alex@dagger.io>
I've observed LLMs tend to run batches of tool calls that involve 1. a
change to make, and 2. a test to run assuming the change is made. Right
now when that happens we guarantee that the test runs WITHOUT the
changes, which confuses the LLM.

Instead we should do all the changes and _then_ the read-only calls,
which will read the freshest state.

Signed-off-by: Alex Suraci <alex@dagger.io>
Signed-off-by: Alex Suraci <alex@dagger.io>
Signed-off-by: Alex Suraci <alex@dagger.io>
Signed-off-by: Alex Suraci <alex@dagger.io>
Signed-off-by: Alex Suraci <alex@dagger.io>
@vito vito merged commit 0c00287 into dagger:main Nov 6, 2025
52 of 57 checks passed
@vito vito deleted the llm-compact branch November 6, 2025 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants