Activate the A2UI extension if the client requested it.
Call this in your AgentExecutor to negotiate A2UI support. If the client's request includes the A2UI extension URI, it is activated and the function returns True.
| PARAMETER | DESCRIPTION |
context | TYPE: RequestContext |
| RETURNS | DESCRIPTION |
bool | True if the A2UI extension was activated, False otherwise. |
Source code in autogen/agents/experimental/a2ui/a2a_helpers.py
| @require_optional_import(["a2a"], "a2a")
def try_activate_a2ui_extension(context: RequestContext) -> bool:
"""Activate the A2UI extension if the client requested it.
Call this in your ``AgentExecutor`` to negotiate A2UI support.
If the client's request includes the A2UI extension URI, it is
activated and the function returns True.
Args:
context: The A2A request context.
Returns:
True if the A2UI extension was activated, False otherwise.
"""
if A2UI_EXTENSION_URI in context.requested_extensions:
# SDK 1.0 dropped `add_activated_extension`; we now signal activation
# implicitly by acknowledging the requested extension via metadata.
if context.metadata is None:
context.metadata = {}
activated = context.metadata.setdefault("activated_extensions", [])
if A2UI_EXTENSION_URI not in activated:
activated.append(A2UI_EXTENSION_URI)
return True
return False
|