build_ask_tool(agent, *, tool_name='ask', tool_description=None, response_schema=None)
Build the single conversational MCP tool that fronts agent.ask().
The tool takes a required message and an optional context string — mirroring :meth:Agent.as_tool's objective / context shape. When response_schema is an object schema, it is advertised as the tool's outputSchema so MCP clients receive validated structuredContent (see :mod:autogen.beta.mcp.executor).
Source code in autogen/beta/mcp/info.py
| def build_ask_tool(
agent: Agent,
*,
tool_name: str = "ask",
tool_description: str | None = None,
response_schema: "ResponseProto[Any] | None" = None,
) -> MCPTool:
"""Build the single conversational MCP tool that fronts ``agent.ask()``.
The tool takes a required ``message`` and an optional ``context`` string —
mirroring :meth:`Agent.as_tool`'s ``objective`` / ``context`` shape. When
``response_schema`` is an object schema, it is advertised as the tool's
``outputSchema`` so MCP clients receive validated ``structuredContent``
(see :mod:`autogen.beta.mcp.executor`).
"""
input_schema: dict[str, Any] = {
"type": "object",
"properties": {
"message": {
"type": "string",
"description": "The message or task to send to the agent.",
},
"context": {
"type": "string",
"description": "Optional additional context to prepend to the message.",
},
},
"required": ["message"],
}
kwargs: dict[str, Any] = {
"name": tool_name,
"description": tool_description or f"Send a message to the '{agent.name}' AG2 agent and receive its reply.",
"inputSchema": input_schema,
}
output_schema = object_output_schema(response_schema)
if output_schema is not None:
kwargs["outputSchema"] = output_schema
return MCPTool(**kwargs)
|