Skip to content

extract_context_update

autogen.beta.a2a.mappers.messages.extract_context_update #

extract_context_update(msg)

Extract the ag2.context_update payload from Message.metadata.

Returns an empty dict when nothing is set — callers can .update a real context.variables with the result unconditionally.

Source code in autogen/beta/a2a/mappers/messages.py
def extract_context_update(msg: Message) -> dict[str, Any]:
    """Extract the ``ag2.context_update`` payload from ``Message.metadata``.

    Returns an empty dict when nothing is set — callers can ``.update``
    a real ``context.variables`` with the result unconditionally.
    """
    if not msg.HasField("metadata"):
        return {}
    metadata = struct_to_dict(msg.metadata)
    payload = metadata.get(CONTEXT_UPDATE_METADATA_KEY)
    if isinstance(payload, dict):
        return payload
    return {}