Skip to content

fix: DefaultFinalizer return assistant message#1036

Open
mrh997 wants to merge 83 commits into
mainfrom
feat/mrh/summarize
Open

fix: DefaultFinalizer return assistant message#1036
mrh997 wants to merge 83 commits into
mainfrom
feat/mrh/summarize

Conversation

@mrh997

@mrh997 mrh997 commented May 19, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

Check the PR title.

  • This PR title match the format: <type>(optional scope): <description>
  • The description of this PR title is user-oriented and clear enough for others to understand.
  • Attach the PR updating the user documentation if the current PR requires user awareness at the usage level. User docs repo

(Optional) Translate the PR title into Chinese.

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

en:
zh(optional):

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

(optional) The PR that updates user documentation:

mrh997 and others added 30 commits May 6, 2026 09:37
feat(agentic_model):
- format print
- support agentic chat template
- support to compose agentic odel&agentic tools node
- support agentic tool node
- support agentic message concat
#882)

feat(adk): add agentmd middleware for auto-injecting Agents.md into model input

Change-Id: I34add4f925a23c6d6821925c482a21f6cddfddd4
shentongmartin and others added 28 commits May 6, 2026 09:41
feat(adk): add MultiModalRead with custom FileContentPart types

- Define FileContentPartType, FileContentPart in filesystem package
  to replace direct schema.ToolOutputPart dependency, supporting
  only Image (bytes) and File (bytes) types
- Add MultiModalReader interface and MultiModalReadRequest with Pages field
- Add multiModalReadFileArgs extending readFileArgs with PDF pages param
- Convert FileContentPart to schema.ToolOutputPart with base64
  encoding in middleware layer
- Guard against nil FileContent returned from Backend.Read and
  MultiModalRead; return human-readable fallback instead of panicking
- Reuse base64 encoding buffer across multimodal parts via base64Encoder
- Add tests for image, file, unsupported type, pages passthrough,
  schema fields, custom desc, empty data error, nil result, and routing
* feat(adk): validate pages parameter in MultiModalReadFileTool

- Add validatePages function to check format (must be "N" or "N-M")
- Reject invalid formats such as "1-", "-5", non-numeric values
- Enforce end >= start and max 20 pages per request
- Return validation error as ToolResult so the model can self-correct

* test(adk): add unit tests for validatePages function

- Cover valid formats: single page, range, same start/end, max boundary
- Cover invalid formats: trailing dash, leading dash, non-numeric, zero
- Cover logic errors: end < start, range exceeds 20 pages
Replace FunctionToolResult.Result string field with Blocks
[]*FunctionToolResultBlock to uniformly represent all tool results
(text-only and multimodal) as structured content blocks.

- Add FunctionToolResultBlock type supporting text, image, audio,
  video, and file content with String() method
- Remove FunctionToolResult.Result field; text results are now
  wrapped as FunctionToolResultBlock{Text: ...}
- Update FunctionToolResultAgenticMessage to accept blocks parameter
- Convert MessageInputPart to FunctionToolResultBlock in compose layer
- Update concatFunctionToolResults to merge via Blocks append
- Add comprehensive tests for multimodal and streaming tool results
…xt, and DeepAgent for AgenticMessage support (#988)
…1004)

refactor(adk): build ToolsNodeConfig via shallow copy + field override

Replace explicit field-by-field struct literals with a shallow copy of
the source ToolsNodeConfig followed by overriding only the fields that
need per-run isolation (Tools and ToolCallMiddlewares). New fields added
to compose.ToolsNodeConfig in the future will be forwarded automatically
instead of being silently dropped.

- applyBeforeAgent: reuse the already-cloned toolsNodeConf local instead
  of rebuilding the struct
- prepareExecContext: shallow-copy a.toolsConfig.ToolsNodeConfig then
  cloneSlice the Tools/ToolCallMiddlewares that will be appended to

No behavior change: every field is assigned the same value as before.
…base

Swap handler positions in InnermostGetsOriginalOutput subtests to match
the forward-iteration semantics from #1000. The tests assumed the old
reverse-iteration order where handlers[0] was innermost.

Change-Id: Ib319b3ea687870db9f69c4c93e1ee69369ea2fe8
…eep-copy (#1007)

fix(serialization): ensure pointer-receiver MarshalJSON is invoked in InternalSerializer

When InternalSerializer marshals a struct value that implements
json.Marshaler via pointer receiver (e.g. *ToolInfo), rv.Interface()
produces a non-addressable copy. json.Marshal then cannot call the
pointer method and falls back to default struct encoding, which skips
unexported fields — causing ParamsOneOf data loss after deepCopyState
during interrupt/resume.

Fix: pass a pointer to json.Marshal by using rv.Addr() when addressable,
or copying into reflect.New() otherwise.
feat(schema): refactor FunctionToolResult types and add streaming merge

- Rename FunctionToolResultBlock to FunctionToolResultContentBlock
- Rename FunctionToolResultBlockType constants (drop "Type" infix)
- Rename Result field to Content across FunctionToolResult,
  ServerToolResult, and MCPToolResult
- Remove NewXxxFunctionToolResultBlock constructor functions
- Add streaming merge logic in concatFunctionToolResults: aggregate
  content blocks by StreamingMeta index with fail-fast consistency check
- Text blocks with same index are concatenated; non-text blocks with
  duplicate index return an error
- Merge Extra fields via internal.ConcatItems for text aggregation
…are (#1016)

* feat(adk): optimize default token estimation in summarization middleware

Refactor the default token counter to be role-aware and type-specific:
- Split into estimateMessageTokens and estimateAgenticMessageTokens for
  accurate per-field token estimation instead of using generic .String()
- Leverage assistant message's TokenUsage.TotalTokens as baseline,
  only estimate incremental messages after the last assistant response
- Handle multimodal content (image/audio/video/file) as fixed 2000 tokens
- Properly account for ReasoningContent, ToolCalls, ToolSearchResult,
  and FunctionToolResult in token estimation
- Rename getMsgTextContent to getUserMsgTextContent to clarify intent
- Inline model response text extraction in finalizeSummary
* fix: concat agentic response meta

* feat: define Summarize method
@codecov

codecov Bot commented May 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 28.57143% with 25 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (alpha/09@c394335). Learn more about missing BASE report.

Files with missing lines Patch % Lines
adk/middlewares/summarization/finalizer_builder.go 0.00% 25 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             alpha/09    #1036   +/-   ##
===========================================
  Coverage            ?   82.97%           
===========================================
  Files               ?      162           
  Lines               ?    23088           
  Branches            ?        0           
===========================================
  Hits                ?    19158           
  Misses              ?     2674           
  Partials            ?     1256           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Base automatically changed from alpha/09 to main May 19, 2026 10:04
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.

8 participants