feat(adk): add EnhancedRead with custom FileContentPart types#973
feat(adk): add EnhancedRead with custom FileContentPart types#973
Conversation
JonXSnow
commented
Apr 16, 2026
- 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 Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
4f972fe to
1e81be8
Compare
- 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
1e81be8 to
471bc2a
Compare
| // 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 { |
There was a problem hiding this comment.
MultiModalReader 会更好吗?EnhancedTool 的定位是最终会替换掉第一版的 Tool。这个 EnhancedReader 的定位也是最终会替换掉之前的 Reader 吗?
| } | ||
| } | ||
|
|
||
| func (t *toolResultOffloading) enhancedInvoke(endpoint compose.EnhancedInvokableToolEndpoint) compose.EnhancedInvokableToolEndpoint { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
需要支持 'Backend Implementation' 自定义 FileContentPartType 吗
| merged = make(map[string]any, len(p.Extra)) | ||
| } | ||
| for k, v := range p.Extra { | ||
| merged[k] = v |
There was a problem hiding this comment.
mergeExtra 这个要复用那个 RegisterCustomMergeFunc 之类的吗?这里是 key 冲突直接覆盖,可能打破用户预期
| } | ||
|
|
||
| // Multimodal result: convert FileContentPart to ToolOutputPart | ||
| if len(fileCt.Parts) > 0 { |
There was a problem hiding this comment.
fileCt 可能是 nil,需要防御
| if p.MIMEType == "" { | ||
| return nil, fmt.Errorf("FileContentPart.MIMEType is empty for type %s", p.Type) | ||
| } | ||
| b64 := base64.StdEncoding.EncodeToString(p.Data) |
There was a problem hiding this comment.
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()
考虑换成这个
| // 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 { |
There was a problem hiding this comment.
注释加一下:EnhancedReader implementation 需要实现自己的文件最大 size 限制