-
Notifications
You must be signed in to change notification settings - Fork 171
fix: Allow injecting ObjectMapper in FunctionTool, default to ObjectMapper (re. #473) #487
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
Summary of ChangesHello @vorburger, 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 significantly improves the Highlights
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
|
7d99d03 to
f628dc9
Compare
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.
Code Review
This pull request successfully refactors FunctionTool to allow injecting a custom ObjectMapper, which is a great step towards better flexibility and testability.
I've left a couple of comments on areas that could be improved for consistency and correctness:
- The
ObjectMapperused for schema generation inFunctionCallingUtilsis still separate from the one injected intoFunctionTool, which could lead to inconsistencies. - There's a potential bug in how
Listparameters are handled in thecallLivemethod, which is different from the more robust implementation in thecallmethod.
Addressing these points will make the FunctionTool more robust, especially when dealing with custom types. Overall, this is a valuable change.
| this.funcDeclaration = | ||
| FunctionCallingUtils.buildFunctionDeclaration( | ||
| this.func, ImmutableList.of("toolContext", "inputStream")); | ||
| this.objectMapper = objectMapper; |
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.
While the runtime argument conversion now uses the injected objectMapper, the function declaration schema is built using FunctionCallingUtils, which has its own static, non-configurable ObjectMapper. This can lead to inconsistencies if the injected objectMapper has custom serializers, as the generated schema will not reflect them. This could cause mismatches between what the LLM expects and what the tool can handle at runtime. To ensure consistency, FunctionCallingUtils should also be updated to use the same ObjectMapper instance.
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.
TBD...
| } | ||
|
|
||
| private static List<Object> createList(List<Object> values, Class<?> type) { | ||
| private List<Object> createList(List<Object> values, Class<?> type) { |
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.
The callLive method, a caller of this function, has a potential bug. It obtains a java.lang.reflect.Type and casts it directly to Class before passing it here. This is unsafe and will cause a ClassCastException if the type is a ParameterizedType (e.g., for a List<Map<String, String>>). The call method contains the correct, more robust logic for handling this, which should be replicated in callLive to prevent runtime errors.
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.
==> #489
Update core/src/main/java/com/google/adk/sessions/VertexAiSessionService.java Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> test: Add tests for ExampleUtils Note the bug in the "no input" test. The header is missing. PiperOrigin-RevId: 822299706 feat: add `GoogleMapsTool` to enable Google Maps search integration for Gemini 2 models refactor: Refactoring ExampleUtil - convertExamplesToText() is broken down into smaller methods (header, user turn, model turns, footer). - The Example header is always added, even if the input is missing. PiperOrigin-RevId: 822643263 refactor: Simplify LlmRequest code PiperOrigin-RevId: 822715169 docs: Adds missing comments PiperOrigin-RevId: 822718215 fix: Add OpenTelemetry context propagation to span creation Resolves issue google#403 where ADK Java spans were not properly linking to parent contexts, causing distributed tracing to break across RxJava async boundaries. Add Telemetry traceFlowable and use in Runner and BaseAgent Impact: - Enables unified trace hierarchy in observability tools - Preserves backward compatibility (Context.current() safe when no parent) - All 656 existing tests pass Test coverage: - Parent-child span linking - Root span creation when no parent exists - Nested span hierarchy (4 levels deep) - Parallel tool execution - Thread boundary context propagation feat: HITL/Introduce ToolConfirmations and integrate them into ToolContext This is a port of the python implementation and part of the "human in the loop" workflow. PiperOrigin-RevId: 823136285 test: Adding a test for telemetry in RunnerTest PiperOrigin-RevId: 823192673 refactor: Simplifying TestUtils Basically, the single Event case and multi-Event case had duplicate code. I consolidated the implementation, and broke down different parts of the process into helper methods. PiperOrigin-RevId: 823580027 fix: Avoid ClassCastException and reduce copy/pasta 🍝 in FunctionTool Prompted by google#487 (comment).
Update core/src/main/java/com/google/adk/sessions/VertexAiSessionService.java Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> test: Add tests for ExampleUtils Note the bug in the "no input" test. The header is missing. PiperOrigin-RevId: 822299706 feat: add `GoogleMapsTool` to enable Google Maps search integration for Gemini 2 models refactor: Refactoring ExampleUtil - convertExamplesToText() is broken down into smaller methods (header, user turn, model turns, footer). - The Example header is always added, even if the input is missing. PiperOrigin-RevId: 822643263 refactor: Simplify LlmRequest code PiperOrigin-RevId: 822715169 docs: Adds missing comments PiperOrigin-RevId: 822718215 fix: Add OpenTelemetry context propagation to span creation Resolves issue google#403 where ADK Java spans were not properly linking to parent contexts, causing distributed tracing to break across RxJava async boundaries. Add Telemetry traceFlowable and use in Runner and BaseAgent Impact: - Enables unified trace hierarchy in observability tools - Preserves backward compatibility (Context.current() safe when no parent) - All 656 existing tests pass Test coverage: - Parent-child span linking - Root span creation when no parent exists - Nested span hierarchy (4 levels deep) - Parallel tool execution - Thread boundary context propagation feat: HITL/Introduce ToolConfirmations and integrate them into ToolContext This is a port of the python implementation and part of the "human in the loop" workflow. PiperOrigin-RevId: 823136285 test: Adding a test for telemetry in RunnerTest PiperOrigin-RevId: 823192673 refactor: Simplifying TestUtils Basically, the single Event case and multi-Event case had duplicate code. I consolidated the implementation, and broke down different parts of the process into helper methods. PiperOrigin-RevId: 823580027 fix: Avoid ClassCastException and reduce copy/pasta 🍝 in FunctionTool Prompted by google#487 (comment). feat: add `GoogleMapsTool` to enable Google Maps search integration for Gemini 2 models refactor: Refactoring ExampleUtil - convertExamplesToText() is broken down into smaller methods (header, user turn, model turns, footer). - The Example header is always added, even if the input is missing. PiperOrigin-RevId: 822643263 refactor: Simplify LlmRequest code PiperOrigin-RevId: 822715169 docs: Adds missing comments PiperOrigin-RevId: 822718215 fix: Add OpenTelemetry context propagation to span creation Resolves issue google#403 where ADK Java spans were not properly linking to parent contexts, causing distributed tracing to break across RxJava async boundaries. Add Telemetry traceFlowable and use in Runner and BaseAgent Impact: - Enables unified trace hierarchy in observability tools - Preserves backward compatibility (Context.current() safe when no parent) - All 656 existing tests pass Test coverage: - Parent-child span linking - Root span creation when no parent exists - Nested span hierarchy (4 levels deep) - Parallel tool execution - Thread boundary context propagation feat: HITL/Introduce ToolConfirmations and integrate them into ToolContext This is a port of the python implementation and part of the "human in the loop" workflow. PiperOrigin-RevId: 823136285 test: Adding a test for telemetry in RunnerTest PiperOrigin-RevId: 823192673 refactor: Simplifying TestUtils Basically, the single Event case and multi-Event case had duplicate code. I consolidated the implementation, and broke down different parts of the process into helper methods. PiperOrigin-RevId: 823580027 fix: Avoid ClassCastException and reduce copy/pasta 🍝 in FunctionTool Prompted by google#487 (comment). feat: HITL/Introduce ToolConfirmations and integrate them into ToolContext This is a port of the python implementation and part of the "human in the loop" workflow. PiperOrigin-RevId: 824617972
This is needed for the policy engine which consumes metadata from the tools. The current design allows tools to be created first and then they get metadata during registration. PiperOrigin-RevId: 822277777 listSessions returns sessions with empty state Update core/src/main/java/com/google/adk/sessions/VertexAiSessionService.java Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> test: Add tests for ExampleUtils Note the bug in the "no input" test. The header is missing. PiperOrigin-RevId: 822299706 feat: add `GoogleMapsTool` to enable Google Maps search integration for Gemini 2 models refactor: Refactoring ExampleUtil - convertExamplesToText() is broken down into smaller methods (header, user turn, model turns, footer). - The Example header is always added, even if the input is missing. PiperOrigin-RevId: 822643263 refactor: Simplify LlmRequest code PiperOrigin-RevId: 822715169 docs: Adds missing comments PiperOrigin-RevId: 822718215 fix: Add OpenTelemetry context propagation to span creation Resolves issue google#403 where ADK Java spans were not properly linking to parent contexts, causing distributed tracing to break across RxJava async boundaries. Add Telemetry traceFlowable and use in Runner and BaseAgent Impact: - Enables unified trace hierarchy in observability tools - Preserves backward compatibility (Context.current() safe when no parent) - All 656 existing tests pass Test coverage: - Parent-child span linking - Root span creation when no parent exists - Nested span hierarchy (4 levels deep) - Parallel tool execution - Thread boundary context propagation feat: HITL/Introduce ToolConfirmations and integrate them into ToolContext This is a port of the python implementation and part of the "human in the loop" workflow. PiperOrigin-RevId: 823136285 test: Adding a test for telemetry in RunnerTest PiperOrigin-RevId: 823192673 refactor: Simplifying TestUtils Basically, the single Event case and multi-Event case had duplicate code. I consolidated the implementation, and broke down different parts of the process into helper methods. PiperOrigin-RevId: 823580027 fix: Avoid ClassCastException and reduce copy/pasta 🍝 in FunctionTool Prompted by google#487 (comment). test: Add tests for ExampleUtils Note the bug in the "no input" test. The header is missing. PiperOrigin-RevId: 822299706 feat: add `GoogleMapsTool` to enable Google Maps search integration for Gemini 2 models refactor: Refactoring ExampleUtil - convertExamplesToText() is broken down into smaller methods (header, user turn, model turns, footer). - The Example header is always added, even if the input is missing. PiperOrigin-RevId: 822643263 refactor: Simplify LlmRequest code PiperOrigin-RevId: 822715169 docs: Adds missing comments PiperOrigin-RevId: 822718215 fix: Add OpenTelemetry context propagation to span creation Resolves issue google#403 where ADK Java spans were not properly linking to parent contexts, causing distributed tracing to break across RxJava async boundaries. Add Telemetry traceFlowable and use in Runner and BaseAgent Impact: - Enables unified trace hierarchy in observability tools - Preserves backward compatibility (Context.current() safe when no parent) - All 656 existing tests pass Test coverage: - Parent-child span linking - Root span creation when no parent exists - Nested span hierarchy (4 levels deep) - Parallel tool execution - Thread boundary context propagation feat: HITL/Introduce ToolConfirmations and integrate them into ToolContext This is a port of the python implementation and part of the "human in the loop" workflow. PiperOrigin-RevId: 823136285 test: Adding a test for telemetry in RunnerTest PiperOrigin-RevId: 823192673 refactor: Simplifying TestUtils Basically, the single Event case and multi-Event case had duplicate code. I consolidated the implementation, and broke down different parts of the process into helper methods. PiperOrigin-RevId: 823580027 fix: Avoid ClassCastException and reduce copy/pasta 🍝 in FunctionTool Prompted by google#487 (comment). feat: HITL/Introduce ToolConfirmations and integrate them into ToolContext This is a port of the python implementation and part of the "human in the loop" workflow. PiperOrigin-RevId: 824617972 listSessions returns sessions with empty state Update core/src/main/java/com/google/adk/sessions/VertexAiSessionService.java Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> test: Add tests for ExampleUtils Note the bug in the "no input" test. The header is missing. PiperOrigin-RevId: 822299706 feat: add `GoogleMapsTool` to enable Google Maps search integration for Gemini 2 models refactor: Refactoring ExampleUtil - convertExamplesToText() is broken down into smaller methods (header, user turn, model turns, footer). - The Example header is always added, even if the input is missing. PiperOrigin-RevId: 822643263 refactor: Simplify LlmRequest code PiperOrigin-RevId: 822715169 docs: Adds missing comments PiperOrigin-RevId: 822718215 fix: Add OpenTelemetry context propagation to span creation Resolves issue google#403 where ADK Java spans were not properly linking to parent contexts, causing distributed tracing to break across RxJava async boundaries. Add Telemetry traceFlowable and use in Runner and BaseAgent Impact: - Enables unified trace hierarchy in observability tools - Preserves backward compatibility (Context.current() safe when no parent) - All 656 existing tests pass Test coverage: - Parent-child span linking - Root span creation when no parent exists - Nested span hierarchy (4 levels deep) - Parallel tool execution - Thread boundary context propagation feat: HITL/Introduce ToolConfirmations and integrate them into ToolContext This is a port of the python implementation and part of the "human in the loop" workflow. PiperOrigin-RevId: 823136285 test: Adding a test for telemetry in RunnerTest PiperOrigin-RevId: 823192673 refactor: Simplifying TestUtils Basically, the single Event case and multi-Event case had duplicate code. I consolidated the implementation, and broke down different parts of the process into helper methods. PiperOrigin-RevId: 823580027 fix: Avoid ClassCastException and reduce copy/pasta 🍝 in FunctionTool Prompted by google#487 (comment). feat: add `GoogleMapsTool` to enable Google Maps search integration for Gemini 2 models refactor: Refactoring ExampleUtil - convertExamplesToText() is broken down into smaller methods (header, user turn, model turns, footer). - The Example header is always added, even if the input is missing. PiperOrigin-RevId: 822643263 refactor: Simplify LlmRequest code PiperOrigin-RevId: 822715169 docs: Adds missing comments PiperOrigin-RevId: 822718215 fix: Add OpenTelemetry context propagation to span creation Resolves issue google#403 where ADK Java spans were not properly linking to parent contexts, causing distributed tracing to break across RxJava async boundaries. Add Telemetry traceFlowable and use in Runner and BaseAgent Impact: - Enables unified trace hierarchy in observability tools - Preserves backward compatibility (Context.current() safe when no parent) - All 656 existing tests pass Test coverage: - Parent-child span linking - Root span creation when no parent exists - Nested span hierarchy (4 levels deep) - Parallel tool execution - Thread boundary context propagation feat: HITL/Introduce ToolConfirmations and integrate them into ToolContext This is a port of the python implementation and part of the "human in the loop" workflow. PiperOrigin-RevId: 823136285 test: Adding a test for telemetry in RunnerTest PiperOrigin-RevId: 823192673 refactor: Simplifying TestUtils Basically, the single Event case and multi-Event case had duplicate code. I consolidated the implementation, and broke down different parts of the process into helper methods. PiperOrigin-RevId: 823580027 fix: Avoid ClassCastException and reduce copy/pasta 🍝 in FunctionTool Prompted by google#487 (comment). feat: HITL/Introduce ToolConfirmations and integrate them into ToolContext This is a port of the python implementation and part of the "human in the loop" workflow. PiperOrigin-RevId: 824617972
Related to #473.
Intentionally just for
FunctionTool, for now; but this should eventually really be done everywhere like this (IMHO).Alternative (and superior) to the initial #486 - but put on hold, until at least that basic version is merged (thus this is Draft).