-
Notifications
You must be signed in to change notification settings - Fork 52
Tools can also return DocumentBlock, ImageBlock, VideoBlock #396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
… string and JSONValue
|
👋 Welcome @dpruessner and thanks for this contribution! This looks like an interesting enhancement allowing tools to return richer content types (DocumentBlock, ImageBlock, VideoBlock). This would enable more sophisticated tool outputs beyond simple text. Hoping maintainers can take a look when they have a chance! 👀 🤖 This comment was generated by an AI agent using strands-agents. Workflow Run: 20944495454 |
| expect(result.type).toBe('documentBlock') | ||
| expect(result.name).toBe('RESULT') | ||
| expect(result.format).toBe('md') | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue: Test coverage is incomplete for media block returns.
Only DocumentBlock return is tested. Consider adding tests for ImageBlock and VideoBlock returns to ensure consistent behavior across all media types.
Suggestion: Add similar tests for ImageBlock and VideoBlock:
it('handles ImageBlock return', async () => {
const { ImageBlock } = await import('../../types/media.js')
const imgTool = tool({
name: 'create_image',
description: 'Creates an image',
inputSchema: z.object({ data: z.string() }),
callback: (input) => {
return new ImageBlock({
format: 'png',
source: { bytes: new TextEncoder().encode(input.data) },
})
},
})
const result = await imgTool.invoke({ data: 'test' })
expect(result.type).toBe('imageBlock')
expect(result.format).toBe('png')
})
Review SummaryAssessment: Comment (Request minor changes before approval) Key ThemesStrengths:
Areas Needing Attention:
OverallThis is a valuable enhancement that enables richer tool outputs. The core implementation in Bedrock and the type system changes look solid. The main suggestions focus on cross-provider compatibility and test coverage to ensure a robust feature. Nice work on this contribution! 🎉 |
🔗 Cross-Reference: Issue #443This PR is directly related to issue #443 ("Solidify plan for ToolUse and ToolResponse messages"). OpenAI Compatibility ConcernIn const contentText = toolResult.content
.map((c) => {
if (c.type === 'textBlock') { return c.text }
else if (c.type === 'jsonBlock') { return JSON.stringify(c.json) }
return '' // ⚠️ Silent data loss for DocumentBlock, ImageBlock, VideoBlock
})
.join('')Suggestion: Add explicit handling for media blocks: else if (c.type === 'documentBlock' || c.type === 'imageBlock' || c.type === 'videoBlock') {
logger.warn(`content_type=<${c.type}> | OpenAI does not support media blocks in tool results, content omitted`)
return `[${c.type}: content not supported by OpenAI]`
}This ensures users are aware of the limitation rather than experiencing silent data loss. |
Description
Enables tools to return
DocumentBlock,ImageBlock, andVideoBlockcontent directly to multi-modal models.Previously, tools could only return strings or JSON. This PR adds support for rich media blocks, allowing more efficient processing of documents, images, and videos through the Bedrock Converse API.
Key Changes:
ToolReturnValuetype supporting media blockstool()helper to accept DocumentBlock/ImageBlock/VideoBlock returnsRelated Issues
Closes #395
Documentation PR
Type of Change
New feature
Testing
How have you tested the change?
npm run checkChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.