UseA2AAgentTool lets an LLM agent delegate a task to a registered remote A2A agent and receive its result. Unlike an in-process subagent, the remote agent can run in another system or framework. section 10.2.2 section 10.5
The tool subclasses AsyncBaseTool and stores a dictionary of A2AAgentSpec objects in _a2a_agents_registry, keyed by agent name. Its exposed tool name is from_scratch__use_a2a_agent; its description directs the LLM agent to the catalog of available peers. section 10.2.2
A tool call selects a peer and either starts or resumes its task:
- name identifies a registered agent; the parameter schema limits it to the registry’s names. section 10.2.2
- task contains the instruction for a new task, or the requested additional input when resuming one. section 10.2.2
- task_id is optional. When supplied, it identifies the paused remote task to resume rather than starting a new one. section 10.2.2
The asynchronous __call__() validates the tool-call arguments, looks up the selected specification, and exchanges the task with the remote A2A server. The implementation creates an httpx.AsyncClient using the specification’s headers and timeout, and returns the result as a ToolCallResult. section 10.2.2 section 10.4.2
Listing 10.6 Implementing UseA2AAgentTool: __call__()
# llm_agents_from_scratch/a2a/client/tools.py
… #A
import httpx
from a2a.client import ClientConfig, create_client
from a2a.helpers import new_text_message
from a2a.types import Role as A2ARole
from a2a.types import SendMessageRequest, StreamResponse
class UseA2AAgentTool(AsyncBaseTool):
… #B
async def __call__(
self, tool_call: ToolCall, *args: Any, **kwargs: Any,
) -> ToolCallResult:
"""Dispatch a task to the named A2A peer and return its result.""" #C
… #D
agent_name: str = tool_call.arguments["name"]
task_instruction: str = tool_call.arguments["task"]
task_id = tool_call.arguments.get("task_id")
spec = self._a2a_agents_registry[agent_name]
async with httpx.AsyncClient(
headers=spec.headers, timeout=spec.timeout,
) as httpx_client:
client = None
try:
client = await create_client( #E
agent=spec.agent_card,
client_config=ClientConfig(
streaming=False, httpx_client=httpx_client,
),
)
message = new_text_message(
text=task_instruction, task_id=task_id, role=A2ARole.ROLE_USER,
)
request = SendMessageRequest(message=message) #F
response: StreamResponse | None = None
async for chunk in client.send_message(request): #G
response = chunk
except Exception as e:
return ToolCallResult(
tool_call_id=tool_call.id_, error=True,
content=json.dumps({…},), #H
)
finally:
… #I
return a2a_response_to_tool_call_result( #J
response, agent_name, tool_call.id_,
)Inspect the dispatch method and its A2A client setup. section 10.2.2
LLMAgent holds the A2A agent registry, while TaskHandler uses it to create the tool and a catalog for the LLM. Remote dispatch occurs during tool-call execution inside run_step(). section 10.2.3
Resuming a hailstone task
A coordinator sends a hailstone-sequence request to a CrewAI peer. The peer asks for a positive starting integer; the tool result tells the coordinator to call the same agent again with the supplied task_id and the requested information in task. The completed result is 4, 2, 1. section 10.2.3
The client-side tool supports the input-required workflow but does not stream progress to the LLM agent: it blocks and packages the result in a ToolCallResult. The integration also does not use context_id for multi-turn context sharing. section 10.4.2
