telemetry: add deterministic tool-call receipt contract#4503
telemetry: add deterministic tool-call receipt contract#4503davidahmann wants to merge 1 commit intogoogle:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
Implemented a deterministic tool-call receipt payload in tracing with schema-backed tests that verify required fields and stable serialization for equivalent argument payloads. This contribution was informed by patterns from Gait: https://github.com/davidahmann/gait |
Summary of ChangesHello @davidahmann, 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 addresses a limitation in tool-call tracing by implementing a deterministic, machine-readable receipt. This new receipt provides a stable payload for auditing and replaying tool calls, enhancing the reliability and traceability of agent interactions. The changes involve adding new serialization logic and integrating the receipt into the existing tracing mechanism, alongside comprehensive test updates. 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. Changelog
Activity
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
|
|
Response from ADK Triaging Agent Hello @davidahmann, thank you for creating this PR! Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). You can visit https://cla.developers.google.com/ to see your current agreements or to sign a new one. This information will help reviewers to review your PR more efficiently. Thanks! |
There was a problem hiding this comment.
Code Review
This pull request introduces a deterministic tool-call receipt to telemetry, which is a valuable addition for audit and replay purposes. The implementation in src/google/adk/telemetry/tracing.py correctly uses stable JSON serialization and hashing to create a deterministic receipt. The tests in tests/unittests/telemetry/test_spans.py are comprehensive, covering the new functionality well, including the deterministic nature of the receipt. My feedback includes a couple of suggestions to enhance code readability and maintainability.
| if ( | ||
| function_response_event is not None | ||
| and function_response_event.content is not None | ||
| and function_response_event.content.parts | ||
| ): | ||
| function_response = function_response_event.content.parts[0].function_response | ||
| if function_response is not None: | ||
| if function_response.id is not None: | ||
| tool_call_id = function_response.id | ||
| if function_response.response is not None: | ||
| outcome = 'success' |
There was a problem hiding this comment.
To improve readability, you can simplify the nested if statements. The current logic is correct, but flattening the structure slightly by removing redundant is not None checks and combining conditions can make it easier to follow.
| if ( | |
| function_response_event is not None | |
| and function_response_event.content is not None | |
| and function_response_event.content.parts | |
| ): | |
| function_response = function_response_event.content.parts[0].function_response | |
| if function_response is not None: | |
| if function_response.id is not None: | |
| tool_call_id = function_response.id | |
| if function_response.response is not None: | |
| outcome = 'success' | |
| if ( | |
| function_response_event | |
| and function_response_event.content | |
| and function_response_event.content.parts | |
| ): | |
| function_response = function_response_event.content.parts[0].function_response | |
| if function_response: | |
| if function_response.id is not None: | |
| tool_call_id = function_response.id | |
| if function_response.response is not None: | |
| outcome = 'success' |
| receipt_calls = [ | ||
| call_obj | ||
| for call_obj in mock_span_fixture.set_attribute.call_args_list | ||
| if call_obj.args[0] == 'gcp.vertex.agent.tool_call_receipt' | ||
| ] | ||
| assert len(receipt_calls) == 1 | ||
| receipt = json.loads(receipt_calls[0].args[1]) |
There was a problem hiding this comment.
This logic for extracting the tool call receipt is repeated in several tests (test_trace_tool_call_with_dict_response, test_trace_tool_call_disabling_request_response_content). To improve maintainability and reduce code duplication, consider extracting this into a helper function within the test module.
Problem
Tool-call tracing lacked a deterministic machine-readable receipt payload suitable for stable audit/replay linkage.
What changed
tool_call_receiptserialization totrace_tool_call.Validation
uv sync --extra testuv run ruff check src/google/adk/telemetry/tracing.py tests/unittests/telemetry/test_spans.pyuv run python -m pytest tests/unittests/telemetry/test_spans.py -k "trace_tool_call"Refs #4502