Skip to content

fix(adk): bound summarization model input - #1165

Open
March-77 wants to merge 1 commit into
cloudwego:mainfrom
March-77:agent/issue-940-limit-summary-input
Open

fix(adk): bound summarization model input#1165
March-77 wants to merge 1 commit into
cloudwego:mainfrom
March-77:agent/issue-940-limit-summary-input

Conversation

@March-77

Copy link
Copy Markdown

What type of PR is this?

fix

Check the PR title.

  • This PR title matches the required format.
  • The description is user-oriented and clear.
  • No separate documentation PR is required; the behavior is documented on the existing config field.

(Optional) Translate the PR title into Chinese.

fix(adk): 限制摘要模型的输入长度

(Optional) More detailed description for this PR(en: English/zh: Chinese).

en:

When conversation history crosses the summarization threshold, the default input builder currently forwards the complete over-limit history to the summarization model. If that model has the same or a smaller context window, the recovery mechanism fails with another context-length error.

This change uses Trigger.ContextTokens as the input budget for the default summary request. After reserving space for the system and user summary instructions, it keeps the newest contiguous message window that fits and evicts older messages. Keeping a suffix preserves current user intent and tool-call/result ordering. Custom GenModelInput callbacks remain untouched and retain full control.

It also fixes a related trigger edge case: configuring only ContextMessages previously left ContextTokens at zero, causing any non-empty history below the message threshold to trigger anyway. A disabled token condition now falls back to the documented default 160k threshold.

User impact: default summarization no longer retries an already oversized history unchanged, and message-only trigger configurations behave as documented.

Compatibility/risk: no new API. The window applies only to the default model-input builder; users needing different retention semantics can continue using GenModelInput.

Validation:

  • go test ./adk/middlewares/summarization -run "TestMiddlewareShouldSummarize|TestMiddlewareBuildSummarizationModelInput|TestWindowMessagesByTokenLimit" -count=10
  • go test -race ./adk/middlewares/summarization -run "TestMiddlewareShouldSummarize|TestMiddlewareBuildSummarizationModelInput|TestWindowMessagesByTokenLimit" -count=1
  • go test ./adk/middlewares/summarization
  • go test ./adk
  • go test ./...
  • go vet ./...

golangci-lint could not be completed locally because the pinned runner repeatedly stalled while downloading github.com/MirrexOne/unqueryvet v1.5.4.

(Optional) Which issue(s) this PR fixes:

Fixes #940

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

关于adk/middlewares/summarization/summarization.go中总结时的输入可能超出模型上下文窗口的问题

1 participant