Skip to content

feat(adk): add generic tool and after-model UI callbacks - #4472

Closed
gspencergoog wants to merge 8 commits into
feat/modular-agent-seamsfrom
feat/modular-adk-ui-hooks
Closed

gspencergoog wants to merge 8 commits into
feat/modular-agent-seamsfrom
feat/modular-adk-ui-hooks

Conversation

@gspencergoog

@gspencergoog gspencergoog commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds generic, decision-agnostic ADK UI callbacks (make_tool_ui_callback in a2ui.adk and make_after_model_ui_callback in a2ui.adk.a2a), public callback type aliases (A2uiProcessorSource, ProducerErrorPolicy, SkipSummarizationPredicate), and an opt-in allowed_a2ui_tool_names allowlist on A2uiPartConverter and A2uiEventConverter. External extensions and user code can attach validated A2UI surfaces to ADK tool outputs or model responses without coupling a2ui-adk to experimental packages.

Reviewer Focus

  • python/a2ui_adk/src/a2ui/adk/tool_ui_callback.py: Untrusted A2UI_VALIDATED_JSON_KEY stripping before producer execution, WeakKeyDictionary per-RendererState surface ID reservation, serialization before state commit, and startup warning when a2ui_processor=None.
  • python/a2ui_adk/src/a2ui/adk/a2a/after_model_ui_callback.py: Filtering of partial/error/function-call/delimited responses, GenAI part conversion before committing to RendererState, and lazy export under a2ui.adk.
  • python/a2ui_adk/src/a2ui/adk/a2a/part_converter.py: Opt-in allowed_a2ui_tool_names gating alongside send_a2ui_json_to_client.

Changes

  • Added make_tool_ui_callback, ToolUiContext, ToolUiProducer, AfterToolCallbackFn, A2uiProcessorSource, ProducerErrorPolicy, and SkipSummarizationPredicate in python/a2ui_adk/src/a2ui/adk/tool_ui_callback.py and exported them from a2ui.adk.
  • Added make_after_model_ui_callback, AfterModelUiContext, AfterModelUiProducer, and AfterModelCallbackFn in python/a2ui_adk/src/a2ui/adk/a2a/after_model_ui_callback.py and lazily exported them from a2ui.adk.
  • Added allowed_a2ui_tool_names to A2uiPartConverter and A2uiEventConverter in python/a2ui_adk/src/a2ui/adk/a2a/part_converter.py and event_converter.py.
  • Bumped a2ui-adk's a2ui-agent-sdk dependency floor in python/a2ui_adk/pyproject.toml and updated python/a2ui_adk/CHANGELOG.md.
  • Added unit tests in python/a2ui_adk/tests/test_tool_ui_callback.py, python/a2ui_adk/tests/a2a/test_after_model_ui_callback.py, test_part_converter.py, test_event_converter.py, and test_lazy_a2a_exports.py.

Impact & Risks

  • Both callback factories are decorated with @experimental and accept a2ui_processor (matching SendA2uiToClientToolset, A2uiInstruction, and A2uiEventConverter).
  • Omitting a2ui_processor logs a warning at factory creation time because catalog and topology validation is skipped.
  • allowed_a2ui_tool_names defaults to None, preserving existing behavior for send_a2ui_json_to_client.

Testing

  • uv run pytest python/a2ui_adk/tests
  • uv run mypy python/a2ui_adk/src/a2ui/adk/
  • uv run ruff format --check python/a2ui_adk

@gspencergoog
gspencergoog added this pull request to stack #4475 December 1, 2026 00:11

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 introduces generic ADK callback hooks for appending and emitting validated A2UI surfaces, specifically adding make_tool_ui_callback for tool execution and make_after_model_ui_callback for completed model responses. It also adds an allowed_a2ui_tool_names allowlist to A2uiPartConverter and A2uiEventConverter to let verified domain tools emit A2UI parts. The feedback suggests enhancing JSON payload handling in part_converter.py by adding type checks for lists, and optimizing dictionary copying in tool_ui_callback.py when the target key is absent.

Comment on lines +117 to +119
json_data = response_dict.get(constants.A2UI_VALIDATED_JSON_KEY)
if json_data:
return [create_a2ui_part(message) for message in json_data]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

When handling JSON payloads that can be either a list of objects or a single object, use type checking (such as isinstance(..., list)) to safely handle both cases and avoid indexing errors.

Suggested change
json_data = response_dict.get(constants.A2UI_VALIDATED_JSON_KEY)
if json_data:
return [create_a2ui_part(message) for message in json_data]
json_data = response_dict.get(constants.A2UI_VALIDATED_JSON_KEY)
if isinstance(json_data, list):
return [create_a2ui_part(message) for message in json_data]
elif json_data is not None:
return [create_a2ui_part(json_data)]
References
  1. When handling JSON payloads that can be either a list of objects or a single object, use type checking (such as isinstance(..., list)) to safely handle both cases and avoid indexing errors.

Comment on lines +161 to +172
if isinstance(tool_response, MutableMapping):
had_key = A2UI_VALIDATED_JSON_KEY in tool_response
if had_key:
tool_response.pop(A2UI_VALIDATED_JSON_KEY, None)
return dict(tool_response), had_key
if isinstance(tool_response, Mapping):
if A2UI_VALIDATED_JSON_KEY in tool_response:
sanitized = {
k: v for k, v in tool_response.items() if k != A2UI_VALIDATED_JSON_KEY
}
return sanitized, True
return dict(tool_response), False

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Avoid copying the dictionary when A2UI_VALIDATED_JSON_KEY is not present in tool_response. Returning the original mapping directly avoids unnecessary dictionary copying overhead.

Suggested change
if isinstance(tool_response, MutableMapping):
had_key = A2UI_VALIDATED_JSON_KEY in tool_response
if had_key:
tool_response.pop(A2UI_VALIDATED_JSON_KEY, None)
return dict(tool_response), had_key
if isinstance(tool_response, Mapping):
if A2UI_VALIDATED_JSON_KEY in tool_response:
sanitized = {
k: v for k, v in tool_response.items() if k != A2UI_VALIDATED_JSON_KEY
}
return sanitized, True
return dict(tool_response), False
if isinstance(tool_response, MutableMapping):
had_key = A2UI_VALIDATED_JSON_KEY in tool_response
if had_key:
tool_response.pop(A2UI_VALIDATED_JSON_KEY, None)
return dict(tool_response), True
return tool_response, False
if isinstance(tool_response, Mapping):
if A2UI_VALIDATED_JSON_KEY in tool_response:
sanitized = {
k: v for k, v in tool_response.items() if k != A2UI_VALIDATED_JSON_KEY
}
return sanitized, True
return tool_response, False

gspencergoog added a commit that referenced this pull request Dec 1, 2026
Signed-off-by: Greg Spencer <gspencer@google.com>
@gspencergoog
gspencergoog removed this pull request from stack #4475 December 1, 2026 22:40
@gspencergoog

gspencergoog commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator Author

Closing per design review feedback to omit a2ui-adk hooks from this stack.

The remaining PRs continue directly on top of #4471: #4471 -> #4473 -> #4474 -> #4496.

🤖 Agent-generated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant