Implement OutputResponseProcessor to enable use of OutputSchema and tools#441
Implement OutputResponseProcessor to enable use of OutputSchema and tools#441dpasiukevich merged 6 commits intogoogle:mainfrom
Conversation
tools
on Gemini models that does not support structured outputs with tools [1]
Based on adk-python [2], if both specified on non-supported model,
- Do not set output schema on the model config,
- Add a special tool called set_model_response using the output schema,
- Instruct the model to use this tool to output its final result,
rather than output text directly.
Fixes google#307
Tested via https://gist.github.com/caglar10ur/52e49e9be5f64f5ac47107810c9e60fb
[1] https://ai.google.dev/gemini-api/docs/structured-output?example=recipe#structured_outputs_with_tools
[2] google/adk-python@af63567
Signed-off-by: Çağlar Onur <caglaronur@google.com>
Summary of ChangesHello @caglar10ur, 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 system's ability to handle structured outputs from Gemini models, particularly those that lack native support for combining structured outputs with tool usage. It achieves this by implementing a new processor that, when necessary, injects a custom Highlights
🧠 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. Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request implements a workaround for Gemini models that don't support using both tools and an output schema simultaneously. It introduces an outputSchemaRequestProcessor that, when needed, injects a special set_model_response tool. This tool is defined with the desired output schema, and the model is instructed to use it for its final structured response. The response from this tool call is then extracted and treated as the final model output. The changes are well-structured and include comprehensive tests. My review includes a few suggestions for improving performance and test code quality by adhering to Go best practices.
Signed-off-by: Çağlar Onur <caglaronur@google.com>
|
Hi @caglar10ur, thank you for the contribution! There are some lint checks failing and the test files are missing the copyright header, let me know if you are able to fix them! |
Signed-off-by: Çağlar Onur <caglaronur@google.com>
Just pushed a commit hopefully addressing those issues. |
|
@caglar10ur the checks are still failing. There seems to be missing a line break between the copyright header and the package. The lint check also mentions the indentation on the // http://www.apache.org/licenses/LICENSE-2.0 part and a missing line break for the "github.com/google/go-cmp/cmp" import in outputschema_processor_test.go |
Signed-off-by: Çağlar Onur <caglaronur@google.com>
Sorry about the noise, turns out I was not using goimports with correct flags (-local google.golang.org/adk was missing), pushed another commit to solve the remaining cosmetic issues. |
dpasiukevich
left a comment
There was a problem hiding this comment.
Thanks for the PR!
Left a couple of questions/clarifications.
Signed-off-by: Çağlar Onur <caglaronur@google.com>
Signed-off-by: Çağlar Onur <caglaronur@google.com>
|
@dpasiukevich let me know if you want more changes. Thanks! |
|
LGTM! |
…ools (google#441) * Implement OutputResponseProcessor to enable use of OutputSchema and tools on Gemini models that does not support structured outputs with tools [1] Based on adk-python [2], if both specified on non-supported model, - Do not set output schema on the model config, - Add a special tool called set_model_response using the output schema, - Instruct the model to use this tool to output its final result, rather than output text directly. Fixes google#307 Tested via https://gist.github.com/caglar10ur/52e49e9be5f64f5ac47107810c9e60fb [1] https://ai.google.dev/gemini-api/docs/structured-output?example=recipe#structured_outputs_with_tools [2] google/adk-python@af63567 Signed-off-by: Çağlar Onur <caglaronur@google.com> * Address gemini-code-assist comments Signed-off-by: Çağlar Onur <caglaronur@google.com> * Add missing copyright headers and fix formatting isssues Signed-off-by: Çağlar Onur <caglaronur@google.com> * Address remaining formatting isssues Signed-off-by: Çağlar Onur <caglaronur@google.com> * Address incorrect return after yield comment Signed-off-by: Çağlar Onur <caglaronur@google.com> * Adjust the tests based on the previous change Signed-off-by: Çağlar Onur <caglaronur@google.com> --------- Signed-off-by: Çağlar Onur <caglaronur@google.com>
on Gemini models that does not support structured outputs with tools [1]
Based on adk-python [2], if both specified on non-supported model,
Fixes #307
Tested via https://gist.github.com/caglar10ur/52e49e9be5f64f5ac47107810c9e60fb
[1] https://ai.google.dev/gemini-api/docs/structured-output?example=recipe#structured_outputs_with_tools
[2] google/adk-python@af63567