Repository navigation
Conversation
Plumb the session-level MaxOutputTokens value through CompactDialogue and Summarize so long summaries are not truncated mid-sentence by the provider's smaller default cap. The chat path at agent.go:802 already sets MaxOutputTokens on its request; Summarize and CompactDialogue were the two missing call sites. A new WithMaxOutputTokens option carries the budget from the session into CompactDialogue, and Summarize now sets MaxOutputTokens on the request when the value is non-zero. A value of 0 (or unset) preserves the existing provider-fallback behaviour. Agent.compact passes the session value through; agentshell /compact keeps the prior behaviour since the compact service is resolved against a separate alias. Regression test TestCompactDialoguePlumbsMaxOutputTokens asserts the captured request carries the configured budget, leaves the field at zero when no option is supplied, and does not coerce an explicit zero into a positive value. Fixes unstablebuild#77 Signed-off-by: Santhi Prakash <[email protected]>
|
Note: the four CI workflows (Linux / Lint / Security / macOS) are showing Pre-flight verification I ran locally before pushing: Sabotage-verified: reverting only the
|
Signed-off-by: Santhi Prakash <[email protected]>
Signed-off-by: Santhi Prakash <[email protected]>
| // a structured summary. It returns the cleaned summary text. When | ||
| // maxOutputTokens is greater than zero it is set on the request so the | ||
| // provider's smaller default cap does not truncate long summaries. | ||
| func Summarize(ctx context.Context, svc llmapi.Service, model llmapi.ModelEntry, messages []llmapi.Message, maxOutputTokens int) (string, error) { |
There was a problem hiding this comment.
nit: can we wrap this function so it doesn't cross 90 characters wide?
There was a problem hiding this comment.
Wrapped the signature in the latest push.
|
|
||
| _, _, err := CompactDialogue( | ||
| context.Background(), svc, llmapi.ModelEntry{}, store, d, | ||
| WithMaxOutputTokens(8192), |
There was a problem hiding this comment.
This test is a good addition but it's insufficient. We should also ensure that we can't, by mistake, drop WithMaxOutputTokens(8192) from agent.go, and suddently regress to exactly where we were prior to this PR.
I think you should be able to reuse the TestAutoCompact harness: call ag.SetMaxOutputTokens(8192) before ag.Run(...), then assert svc.requests[0].MaxOutputTokens == 8192 (request 0 is the summarize request).
| compactedMsgs, archivedID, err := CompactDialogue(ctx, summarizeSvc, a.config.Model, a.store, d) | ||
| compactedMsgs, archivedID, err := CompactDialogue( | ||
| ctx, summarizeSvc, a.config.Model, a.store, d, | ||
| WithMaxOutputTokens(a.MaxOutputTokens()), |
There was a problem hiding this comment.
for the overwhelming majority of runs a.MaxOutputTokens is 0, which is the default value, unless SetMaxOutputTokens is called, and it is only if the user's config has max_tokens (not the default) or the user sets it via /max_tokens inline command, or chatmaxtokens command, so Summarize skips the assignment and the provider falls back to the default i.e 8192. The commit subject says "Fix compaction summary to use session max-output-token budget," but on a default install there is no session budget to use.
I suggest we either set a summarize default that's higher than 8192, either here with a max() statement, or set a default max_tokens higher in the default config, which would apply to all agent runs, not just summaries.
Address review feedback on PR unstablebuild#80: - Wrap Summarize signature so it stays within 90 characters. - Add a model-capped default summary budget (32768) that applies when the session has not set an explicit max-output-token override, fixing the default-install case where the provider fallback (8192) truncated long summaries. - Add regression tests covering both the explicit session override and the default budget path through the auto-compact harness. Signed-off-by: Santhi Prakash <[email protected]>
santhiprakash
left a comment
There was a problem hiding this comment.
Pushed an update addressing the review feedback:
- Wrapped
Summarizeso the signature stays within 90 columns. - Added a model-capped default summary budget (
32768, clamped to the bound
model's documented ceiling viallmarg.MaxOutputTokens) that applies when
the session has not set an explicitmax_tokensoverride. This fixes the
default-install case where the Anthropic 8192 provider fallback truncated
long summaries. - Added
TestAutoCompactPlumbsMaxOutputTokensand
TestAutoCompactUsesDefaultMaxOutputTokensusing theTestAutoCompact
harness to cover both the explicit session override and the default budget
paths.
Local verification: go vet, go build, and go test -race for
./cmd/rune-agent/agent/ all pass.
|
Pushed an update addressing the review feedback:
Local verification: |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Shipped in |
CompactDialogue has two callers. #80 wired the budget through Agent.compact, the auto-compact path, but agentshell.compactConversation still called it bare, so every manual /compact fell back to the provider default of 8192 on Anthropic and truncated the summary mid-sentence. Signed-off-by: ernestrc <[email protected]>
Problem
agent.Summarizebuilds its completion request with onlyMessagesset and never populatesllmapi.Request.MaxOutputTokens. The provider client then applies its own fallback (params.MaxTokens = 8192for Anthropic,config.MaxCompletionTokensfor OpenAI, the provider config limit for Gemini) — much smaller than the budget the session is configured with. On a long conversation the summary stream stops mid-sentence, and the truncated fragment is then persisted as the post-compaction resume prompt. #78 shows the model looping on the unterminated<summary>block.Compare the chat path at
cmd/rune-agent/agent/agent.go:802, which already setsMaxOutputTokens: a.MaxOutputTokens().Triage
The session value lives on
Agent(SetMaxOutputTokens/MaxOutputTokens, set by/max_tokens, validated against the bound model byllmarg.ValidateMaxOutputTokensatcmd/rune-agent/extension/command_adapter.go:482).agent.compact(agent.go:1642) does not pass it through toCompactDialogue, andCompactDialogue(agent.go:1893) does not pass it toSummarize. The chat path is the only site that wires it correctly.Fix
Plumb the session's max-output-token value through to the summarize request:
WithMaxOutputTokens(int)to the existingcompactOptions(alongsideWithCompactHooks).CompactDialoguereadscopts.maxOutputTokensand passes it toSummarize.Summarizenow takes amaxOutputTokens intparameter and setssummaryReq.MaxOutputTokenswhen non-zero. A value of0leaves the provider fallback default in place, matching today's behaviour for callers that don't pass a budget.agent.compactpassesWithMaxOutputTokens(a.MaxOutputTokens())so the session value reaches the summarize request./compactcommand keeps the prior behaviour — the compact service is resolved against a separate alias and there is no session value to pass through.Per the issue, I did not clamp the value against a provider-specific ceiling. The session value is already validated against the bound model, and each provider client applies its own ceiling (
effectiveMaxOutputTokensatinternal/llm/gemini/client.go:160).Verification
Regression test
TestCompactDialoguePlumbsMaxOutputTokensincmd/rune-agent/agent/agent_test.go(table-driven acrossWithMaxOutputTokensset / unset / explicit zero). Sabotage-verified: reverting only theif maxOutputTokens > 0block inSummarizefails the "set option" subtest withexpected 8192, actual 0.Notes / Risks
CompactDialogueandSummarizeare exported;Summarize's newmaxOutputTokens intparameter is a breaking signature change for any out-of-tree caller. The only internal caller isCompactDialogue, updated here./compactpath is intentionally untouched. If the maintainer wants that path plumbed as well, follow-up is straightforward — pass the shell's session config through a newWithMaxOutputTokenscall.go build/go vetclean for the touched package.Fixes #77