Skip to content

feat: allow multipart tool responses to include a metadata field.#4865

Draft
pavelgj wants to merge 2 commits intomainfrom
pj/tool_response_metadata
Draft

feat: allow multipart tool responses to include a metadata field.#4865
pavelgj wants to merge 2 commits intomainfrom
pj/tool_response_metadata

Conversation

@pavelgj
Copy link
Collaborator

@pavelgj pavelgj commented Mar 1, 2026

Checklist (if applicable):

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the MultipartToolResponse by introducing an optional metadata field. This allows tools to return arbitrary, structured data alongside their primary output and content parts, providing greater flexibility for tool developers to convey additional context or information. The changes ensure consistency across the TypeScript, Go, and JSON schema definitions, and include necessary updates to the JavaScript implementation and comprehensive test coverage.

Highlights

  • Metadata Field Introduction: An optional metadata field has been added to the MultipartToolResponse structure across TypeScript, Go, and JSON schema definitions, allowing tools to return arbitrary data.
  • Tool Function Signature Update: The defineTool function in JavaScript has been updated to support returning the new metadata field from multipart tool functions.
  • Tool Response Resolution: The tool resolution logic has been extended to correctly process and include the metadata field when handling multipart tool responses.
  • Comprehensive Test Coverage: New and updated unit tests have been added to validate the functionality of multipart tool responses, specifically verifying the correct handling and propagation of the metadata field.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • genkit-tools/common/src/types/parts.ts
    • Added an optional metadata field to the MultipartToolResponseSchema definition.
  • genkit-tools/genkit-schema.json
    • Included a new metadata property, defined as an object with additional properties, within the MultipartToolResponse schema.
  • go/ai/gen.go
    • Added an optional Metadata field of type map[string]any to the MultipartToolResponse struct.
  • js/ai/src/generate/resolve-tool-requests.ts
    • Modified the resolveToolRequest function to include the metadata field when constructing the ToolResponse.
  • js/ai/src/parts.ts
    • Added an optional metadata field to the MultipartToolResponseSchema definition.
  • js/ai/src/tool.ts
    • Updated the MultipartToolFn type to allow its return promise to include an optional metadata field.
  • js/ai/tests/generate/generate_test.ts
    • Modified existing test cases to include an example metadata field in the expected MultipartToolResponse.
  • js/ai/tests/tool_test.ts
    • Added a new test case to verify that a multipart tool can successfully return and process a metadata field.
Activity
  • The pull request author has marked the PR title as following conventional commits and confirmed manual testing.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds a metadata field to multipart tool responses. The changes have been applied to the TypeScript types, the JSON schema, and the Go struct. Tests have been added to verify the new functionality. The implementation is consistent across the codebase, with one minor readability issue in the auto-generated Go code that I've commented on.

Comment on lines +329 to 332
Content []*Part `json:"content,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
// Output contains the structured output data from the tool.
Output any `json:"output,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The new Metadata field is inserted between Content and the comment for Output, which makes the code harder to read. It also lacks a comment explaining its purpose, unlike other fields in the struct.

For better readability and consistency, I suggest moving the Metadata field to the end of the struct and adding a descriptive comment.

I see that this file is auto-generated. If a manual edit is not possible, this might indicate an issue in the jsonschemagen tool that needs to be addressed, as it seems to be misplacing comments when sorting struct fields alphabetically.

	Content  []*Part        "json:\"content,omitempty\""
	// Output contains the structured output data from the tool.
	Output   any            "json:\"output,omitempty\""
	// Metadata contains arbitrary key-value data associated with this response.
	Metadata map[string]any "json:\"metadata,omitempty\""

@github-actions github-actions bot added the python Python label Mar 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants