build_tool_result_message(results, *, history_events=(), tool_schemas=(), task_id, context_id=None, message_id=None, context_update=None, extra_metadata=None)
Build a Message carrying tool results back to the server.
Used on the second leg of a client-side tool round-trip — after the AG2 outer loop locally executed the tools the server requested. Continuation messages also carry the full history_events and tool_schemas so the stateless server can rebuild conversation state and tool definitions without any session memory.
Source code in autogen/beta/a2a/mappers/messages.py
| def build_tool_result_message(
results: Iterable[ToolResultEvent],
*,
history_events: Sequence[BaseEvent] = (),
tool_schemas: Sequence[FunctionToolSchema] = (),
task_id: str,
context_id: str | None = None,
message_id: str | None = None,
context_update: Mapping[str, Any] | None = None,
extra_metadata: Mapping[str, Any] | None = None,
) -> Message:
"""Build a ``Message`` carrying tool results back to the server.
Used on the second leg of a client-side tool round-trip — after the
AG2 outer loop locally executed the tools the server requested.
Continuation messages also carry the full ``history_events`` and
``tool_schemas`` so the stateless server can rebuild conversation
state and tool definitions without any session memory.
"""
parts: list[Part] = [data_part(results_to_payload(results), media_type=MIME_TOOL_RESULT)]
if tool_schemas:
parts.append(data_part(schemas_to_payload(tool_schemas), media_type=MIME_TOOL_SCHEMAS))
if history_events:
parts.append(data_part(events_to_payload(history_events), media_type=MIME_HISTORY))
return _build_message(
parts,
role=Role.ROLE_USER,
task_id=task_id,
context_id=context_id,
message_id=message_id,
advertise_extension=True,
context_update=context_update,
extra_metadata=extra_metadata,
)
|