Repository navigation
Commit 2198289
committed
feat(plugins): project LlmResponse finish_reason to BigQuery analytics
Projects `finish_reason` from `LlmResponse` to the `attributes` JSON
column of `LLM_RESPONSE` events written to BigQuery by
`BigQueryAgentAnalyticsPlugin`, and exposes it as a typed column in the
generated per-event SQL view. Without this, classifying model failure
modes (MAX_TOKENS, SAFETY, MALFORMED_FUNCTION_CALL, RECITATION, etc.)
via SQL against the analytics table is impossible — the signal lives
only in unstructured Cloud Logging output that is not joinable to the
structured event stream.
Changes:
- `EventData` gets a `finish_reason: Optional[str]` field.
- `after_model_callback` reads `llm_response.finish_reason.name` via a
defensive getattr (same back-compat pattern as `cache_metadata`,
covering legacy response shapes).
- `_enrich_attributes` writes `attrs["finish_reason"]` only when set,
keeping existing consumers and partial streaming events unaffected.
- `_EVENT_VIEW_DEFS["LLM_RESPONSE"]` projects
`JSON_VALUE(attributes, '$.finish_reason')` as `finish_reason`.
- Schema-field description for `attributes` mentions the new key with
example values.
Tests:
- `test_after_model_callback_projects_finish_reason` — MAX_TOKENS
round-trips end-to-end into the BQ row's attributes.
- `test_after_model_callback_omits_finish_reason_when_absent` — key is
omitted when `LlmResponse.finish_reason` is None.
- `TestEnrichAttributes::test_finish_reason_included_when_set` and
`..._omitted_when_none` — direct `_enrich_attributes` coverage.
- Existing 229 plugin tests still pass; 5 skipped (pre-existing).
Fixes google#56441 parent c35a579 commit 2198289
2 files changed
Lines changed: 93 additions & 2 deletions
File tree
- src/google/adk/plugins
- tests/unittests/plugins
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1746 | 1746 | | |
1747 | 1747 | | |
1748 | 1748 | | |
1749 | | - | |
1750 | | - | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
1751 | 1753 | | |
1752 | 1754 | | |
1753 | 1755 | | |
| |||
1847 | 1849 | | |
1848 | 1850 | | |
1849 | 1851 | | |
| 1852 | + | |
1850 | 1853 | | |
1851 | 1854 | | |
1852 | 1855 | | |
| |||
1958 | 1961 | | |
1959 | 1962 | | |
1960 | 1963 | | |
| 1964 | + | |
1961 | 1965 | | |
1962 | 1966 | | |
1963 | 1967 | | |
| |||
2821 | 2825 | | |
2822 | 2826 | | |
2823 | 2827 | | |
| 2828 | + | |
| 2829 | + | |
| 2830 | + | |
2824 | 2831 | | |
2825 | 2832 | | |
2826 | 2833 | | |
| |||
3417 | 3424 | | |
3418 | 3425 | | |
3419 | 3426 | | |
| 3427 | + | |
| 3428 | + | |
| 3429 | + | |
| 3430 | + | |
| 3431 | + | |
3420 | 3432 | | |
3421 | 3433 | | |
3422 | 3434 | | |
| |||
3428 | 3440 | | |
3429 | 3441 | | |
3430 | 3442 | | |
| 3443 | + | |
3431 | 3444 | | |
3432 | 3445 | | |
3433 | 3446 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1530 | 1530 | | |
1531 | 1531 | | |
1532 | 1532 | | |
| 1533 | + | |
| 1534 | + | |
| 1535 | + | |
| 1536 | + | |
| 1537 | + | |
| 1538 | + | |
| 1539 | + | |
| 1540 | + | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
| 1548 | + | |
| 1549 | + | |
| 1550 | + | |
| 1551 | + | |
| 1552 | + | |
| 1553 | + | |
| 1554 | + | |
| 1555 | + | |
| 1556 | + | |
| 1557 | + | |
| 1558 | + | |
| 1559 | + | |
| 1560 | + | |
| 1561 | + | |
| 1562 | + | |
| 1563 | + | |
| 1564 | + | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
| 1568 | + | |
| 1569 | + | |
| 1570 | + | |
| 1571 | + | |
| 1572 | + | |
| 1573 | + | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
1533 | 1587 | | |
1534 | 1588 | | |
1535 | 1589 | | |
| |||
3755 | 3809 | | |
3756 | 3810 | | |
3757 | 3811 | | |
| 3812 | + | |
| 3813 | + | |
| 3814 | + | |
| 3815 | + | |
| 3816 | + | |
| 3817 | + | |
| 3818 | + | |
| 3819 | + | |
| 3820 | + | |
| 3821 | + | |
| 3822 | + | |
| 3823 | + | |
| 3824 | + | |
| 3825 | + | |
| 3826 | + | |
| 3827 | + | |
| 3828 | + | |
| 3829 | + | |
| 3830 | + | |
| 3831 | + | |
| 3832 | + | |
| 3833 | + | |
| 3834 | + | |
| 3835 | + | |
3758 | 3836 | | |
3759 | 3837 | | |
3760 | 3838 | | |
| |||
0 commit comments