feat: first-class context cache metrics in BigQuery analytics plugin#5332
Draft
caohy1988 wants to merge 1 commit intogoogle:mainfrom
Draft
feat: first-class context cache metrics in BigQuery analytics plugin#5332caohy1988 wants to merge 1 commit intogoogle:mainfrom
caohy1988 wants to merge 1 commit intogoogle:mainfrom
Conversation
Promote context cache data to first-class view columns and log cache_metadata as a structured attribute in the BQ analytics plugin. - Add cache_metadata field to EventData and wire it through after_model_callback from LlmResponse.cache_metadata - Store cache_metadata in attributes via _enrich_attributes - Add usage_cached_tokens, context_cache_hit_rate, and cache_metadata columns to the LLM_RESPONSE view definition This enables cache hit-rate analysis directly in BigQuery SQL without manual JSON extraction from raw attributes. Implements google#5210 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
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. |
Collaborator
|
Response from ADK Triaging Agent Hello @caohy1988, thank you for creating this PR! It looks like you have not yet signed the Contributor License Agreement (CLA). Please visit https://cla.developers.google.com/ to sign it. This information will help reviewers to review your PR more efficiently. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements #5210
Promotes context cache token data to first-class BigQuery view columns and logs
cache_metadataas a structured attribute, enabling cache hit-rate analysis directly in SQL without manual JSON extraction.Changes
bigquery_agent_analytics_plugin.py(~25 lines):EventData: Addedcache_metadata: Any = Nonefieldafter_model_callback(): Passesllm_response.cache_metadatathrough toEventData_enrich_attributes(): Stores truncatedcache_metadatain attributes when present_EVENT_VIEW_DEFS["LLM_RESPONSE"]: Three new view columns:usage_cached_tokens—INT64fromattributes.usage_metadata.cached_content_token_countcontext_cache_hit_rate—FLOAT64viaSAFE_DIVIDE(cached/prompt), NULL when no cachecache_metadata— JSON fromattributes.cache_metadataWhat does NOT change
content.usageextraction (still onlyprompt/completion/total) — no content schema evolutioncontent,attributes)Usage
Test plan
test_cache_metadata_stored_in_attributes— verifiescache_metadataappears in attributes with correct fieldstest_no_cache_metadata_when_absent— verifies nocache_metadatakey whenLlmResponsehas nonetest_view_def_includes_cache_columns— verifies view definition contains all three new columns🤖 Generated with Claude Code