Skip to content

feat(adk): add EnhancedRead with custom FileContentPart types#973

Open
JonXSnow wants to merge 1 commit intoalpha/09from
feat/enhancedread
Open

feat(adk): add EnhancedRead with custom FileContentPart types#973
JonXSnow wants to merge 1 commit intoalpha/09from
feat/enhancedread

Conversation

@JonXSnow
Copy link
Copy Markdown
Contributor

  • Define FileContentPartType, FileContentPart in filesystem package to replace direct schema.ToolOutputPart dependency, supporting only Image (bytes) and File (bytes) types
  • Add EnhancedReader interface and Pages field to ReadRequest
  • Add enhancedReadFileArgs extending readFileArgs with PDF pages param
  • Convert FileContentPart to schema.ToolOutputPart with base64 encoding in middleware layer
  • Add EnhancedInvokable support to large tool result offloading
  • Add textOnlyContent helper for multimodal result detection
  • Add enhanced read file tool description suffix (EN/CN)
  • Add tests for image, file, unsupported type, pages passthrough

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 16, 2026

Codecov Report

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

Files with missing lines Patch % Lines
adk/middlewares/filesystem/large_tool_result.go 82.22% 6 Missing and 2 partials ⚠️
adk/middlewares/filesystem/filesystem.go 92.00% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             alpha/09     #973   +/-   ##
===========================================
  Coverage            ?   82.38%           
===========================================
  Files               ?      162           
  Lines               ?    20698           
  Branches            ?        0           
===========================================
  Hits                ?    17052           
  Misses              ?     2444           
  Partials            ?     1202           

☔ 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.

@JonXSnow JonXSnow force-pushed the feat/enhancedread branch 2 times, most recently from 4f972fe to 1e81be8 Compare April 17, 2026 02:54
- Define FileContentPartType, FileContentPart in filesystem package
  to replace direct schema.ToolOutputPart dependency, supporting
  only Image (bytes) and File (bytes) types
- Add EnhancedReader interface and Pages field to ReadRequest
- Add enhancedReadFileArgs extending readFileArgs with PDF pages param
- Convert FileContentPart to schema.ToolOutputPart with base64
  encoding in middleware layer
- Add EnhancedInvokable support to large tool result offloading
- Add textOnlyContent helper for multimodal result detection
- Add enhanced read file tool description suffix (EN/CN)
- Add tests for image, file, unsupported type, pages passthrough
@JonXSnow JonXSnow force-pushed the feat/enhancedread branch from 1e81be8 to 471bc2a Compare April 17, 2026 03:07
Comment thread adk/filesystem/backend.go
// EnhancedReader is an optional extension interface for Backend.
// Backends that implement this interface support multimodal file reading
// (e.g. returning images as base64 image parts).
type EnhancedReader interface {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

MultiModalReader 会更好吗?EnhancedTool 的定位是最终会替换掉第一版的 Tool。这个 EnhancedReader 的定位也是最终会替换掉之前的 Reader 吗?

}
}

func (t *toolResultOffloading) enhancedInvoke(endpoint compose.EnhancedInvokableToolEndpoint) compose.EnhancedInvokableToolEndpoint {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

enhancedStream 怎么处理

default:
// FileContentPartType is defined by Backend implementations.
// Unrecognized types are unlikely but should fail explicitly rather than silently.
return nil, fmt.Errorf("unsupported FileContentPartType: %s", p.Type)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

需要支持 'Backend Implementation' 自定义 FileContentPartType 吗

merged = make(map[string]any, len(p.Extra))
}
for k, v := range p.Extra {
merged[k] = v
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

mergeExtra 这个要复用那个 RegisterCustomMergeFunc 之类的吗?这里是 key 冲突直接覆盖,可能打破用户预期

}

// Multimodal result: convert FileContentPart to ToolOutputPart
if len(fileCt.Parts) > 0 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

fileCt 可能是 nil,需要防御

if p.MIMEType == "" {
return nil, fmt.Errorf("FileContentPart.MIMEType is empty for type %s", p.Type)
}
b64 := base64.StdEncoding.EncodeToString(p.Data)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

var sb strings.Builder
sb.Grow(base64.StdEncoding.EncodedLen(len(p.Data)))
enc := base64.NewEncoder(base64.StdEncoding, &sb)
enc.Write(p.Data)
enc.Close()
b64 := sb.String()

考虑换成这个

Comment thread adk/filesystem/backend.go
// EnhancedReader is an optional extension interface for Backend.
// Backends that implement this interface support multimodal file reading
// (e.g. returning images as base64 image parts).
type EnhancedReader interface {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

注释加一下:EnhancedReader implementation 需要实现自己的文件最大 size 限制

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.

2 participants