feat(bq-plugin): Schema auto-upgrade, tool provenance (incl. A2A), HITL tracing, and span hierarchy fix#4556
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. |
Summary of ChangesHello @caohy1988, 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 enhances the BigQuery agent analytics plugin by introducing three key features. It provides an opt-in mechanism for automatic BigQuery table schema evolution, ensuring that new columns are seamlessly integrated into existing tables. It also enriches tool event logs with detailed provenance information, allowing for a clearer understanding of tool origins within the system. Finally, it adds granular tracing for Human-in-the-Loop interactions, providing more specific insights into agent-user collaborations without impacting current analytics workflows. 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 @caohy1988, thank you for your contribution! It looks like the Contributor License Agreement (CLA) has not been signed. Please sign the CLA to proceed with the review process. You can find more information in the "checks" section at the bottom of the pull request. Thank you! |
There was a problem hiding this comment.
Code Review
The pull request introduces several significant enhancements to the BigQuery Agent Analytics plugin, including an opt-in schema auto-upgrade feature, tool provenance tracking, and dedicated HITL (Human-in-the-loop) tracing. The implementation of the schema auto-upgrade is robust, using table labels for versioning and ensuring that only additive changes are made to existing BigQuery tables. Tool provenance correctly identifies the origin of tools (LOCAL, MCP, SUB_AGENT, etc.) while handling inheritance hierarchies appropriately (e.g., ensuring TransferToAgentTool is distinguished from its parent FunctionTool). The HITL tracing adds valuable visibility into human-interaction tools without breaking existing query patterns. The code is well-structured, follows existing patterns, and includes comprehensive unit tests covering all new functionality and edge cases.
…n hierarchy fix to BigQuery Agent Analytics plugin This CL adds four enhancements to the BigQuery Agent Analytics plugin and fixes a span hierarchy corruption bug. - **Schema Auto-Upgrade:** Additive-only schema migration that automatically adds missing columns to existing BQ tables on startup. A `adk_schema_version` label on the table (starting at `"1"`, bumped with each schema change) makes the check idempotent — the diff runs at most once per version. Enabled by default (`auto_schema_upgrade=True`) because upgrades are additive-only and fail-safe. Pre-versioning tables (no label) are treated as outdated, diffed, and stamped. No previous schema versions need to be stored; the logic diffs actual columns against the current canonical schema. - **Tool Provenance:** Adds `tool_origin` to TOOL_* event content, distinguishing six origin types — `LOCAL` (FunctionTool), `MCP` (McpTool), `A2A` (AgentTool wrapping RemoteA2aAgent), `SUB_AGENT` (AgentTool), `TRANSFER_AGENT` (TransferToAgentTool), and `UNKNOWN` (fallback) — via `isinstance()` checks with lazy imports to avoid circular dependencies. - **HITL Tracing:** Emits dedicated HITL event types (`HITL_CONFIRMATION_REQUEST`, `HITL_CREDENTIAL_REQUEST`, `HITL_INPUT_REQUEST` + `_COMPLETED` variants) for human-in-the-loop interactions. Detection lives in `on_event_callback` (for synthetic `adk_request_*` FunctionCall events emitted by the framework) and `on_user_message_callback` (for `adk_request_*` FunctionResponse completions sent by the user), not in tool callbacks — because `adk_request_*` names are synthetic function calls that bypass `before_tool_callback`/`after_tool_callback` entirely. - **Span Hierarchy Fix (google#4561):** Removes `context.attach()`/`context.detach()` calls from `TraceManager.push_span()`, `attach_current_span()`, and `pop_span()`. The plugin was injecting its spans into the shared OTel context, which corrupted the framework's span hierarchy when an external exporter (e.g. `opentelemetry-instrumentation-vertexai`) was active — causing `call_llm` to be re-parented under `llm_request` and parent spans to show shorter durations than children. The plugin now tracks span_id/parent_span_id via its internal contextvar stack without mutating ambient OTel context. Total tests: 139 (up from 105). Closes google#4554 Fixes google#4561 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
330c8e6 to
0fb959d
Compare
Summary
Implements three of the five enhancements from #4554 (the plugin-side items), plus a bug fix for #4561:
auto_schema_upgrade=True). Aadk_schema_versionlabel on the table tracks which version was applied.tool_originto TOOL_* event content, distinguishing six origin types:LOCAL,MCP,A2A,SUB_AGENT,TRANSFER_AGENT, andUNKNOWNviaisinstance()checks on the tool object. A2A origin is detected by checking if anAgentToolwraps aRemoteA2aAgent.HITL_CONFIRMATION_REQUEST,HITL_CREDENTIAL_REQUEST,HITL_INPUT_REQUEST+_COMPLETEDvariants) by detecting syntheticadk_request_*function calls in the event stream (on_event_callback) and user-sent completion responses (on_user_message_callback). Backwards-compatible — existing queries continue to work.context.attach()/context.detach()calls fromTraceManager.push_span(),attach_current_span(), andpop_span(). The plugin was injecting its spans into the shared OTel context, which corrupted the framework's span hierarchy when an external exporter (e.g.opentelemetry-instrumentation-vertexai) was active.Schema Auto-Upgrade Design
How it works:
_ensure_schema_exists()checks if the BQ table existsadk_schema_version = "1"labelauto_schema_upgrade=True(default):adk_schema_versionlabel from the table_SCHEMA_VERSION→ skips (already up to date)Key properties:
Future schema changes:
SchemaFieldentries to_get_events_schema()_SCHEMA_VERSIONfrom"1"to"2"_maybe_upgrade_schemasees"1" ≠ "2"→ diffs → adds new columns → stamps"2"Tool Origin Categories
LOCALisinstance(tool, FunctionTool)MCPisinstance(tool, McpTool)A2AAgentToolwrappingRemoteA2aAgentSUB_AGENTisinstance(tool, AgentTool)(non-A2A)TRANSFER_AGENTisinstance(tool, TransferToAgentTool)UNKNOWNBaseToolsubclassesHITL Tracing Design
The
adk_request_credential,adk_request_confirmation, andadk_request_inputnames are synthetic function calls injected by the ADK framework — they never pass throughbefore_tool_callback/after_tool_callback. HITL detection therefore lives in:on_event_callback— detectsadk_request_*FunctionCall parts in events emitted by the framework (request events)on_user_message_callback— detectsadk_request_*FunctionResponse parts in user messages (completion events)Key Design Decisions
auto_schema_upgradedefaults toTrue"1"adk_request_*are synthetic FunctionCalls that bypass tool callbackstool_originin content dict (not column)contentJSON is the extensibility pointcontext.attach()(#4561)Files Changed
src/google/adk/plugins/bigquery_agent_analytics_plugin.py— Core implementationtests/unittests/plugins/test_bigquery_agent_analytics_plugin.py— 34 new testsTest plan
Closes #4554
Fixes #4561
🤖 Generated with Claude Code