UseA2AAgentTool¶
UseA2AAgentTool — dispatches a task to a named A2A peer agent.
UseA2AAgentTool
¶
Bases: AsyncBaseTool
Async tool that dispatches a task to a registered A2A peer agent.
Each A2A peer registered with the coordinator is callable via this
single tool — mirrors UseSubAgentTool's shape (one generic
dispatch tool over a registry, name constrained to an enum), for
the same reason: A2A peers are homogeneous (every one takes a text
instruction and returns an artifact), unlike MCP tools which are
heterogeneous and so get one tool each.
The clean diff from UseSubAgentTool: an optional task_id to
resume a remote task a peer previously parked in
TASK_STATE_INPUT_REQUIRED. There is no local state tracking
pending peer tasks — the coordinator holds the task id (echoed back
via A2A_INPUT_REQUIRED_TEMPLATE) and passes it back explicitly,
keeping this tool stateless over the registry just like
UseSubAgentTool is.
Stateless over the SDK client too: A2AAgentSpec never holds a
live client, so this tool calls create_client() fresh on every
dispatch and always closes it before returning.
All exceptions — connection errors, an unknown task_id, etc. —
are caught and returned as ToolCallResult(error=True) so the
coordinator can re-plan rather than crash. An explicit
TASK_STATE_FAILED/TASK_STATE_CANCELED/TASK_STATE_REJECTED
result from the peer is mapped into the same error JSON shape.
No streaming, no push notifications: dispatch is always
ClientConfig(streaming=False), one ToolCallResult per call.
This isn't A2A-specific — run_step's tool-calling loop is
synchronous request/response with no event bus a tool could push
incremental updates through mid-turn, so real streaming would need
a framework-level change, not one scoped to this tool. Push
notifications are out of scope for a different reason: they target
tasks that outlive a single request/response cycle, and nothing in
this framework's task model persists state to receive a callback
after the dispatching run has already finished. This is a
client-side-only limitation — the server side
(LLMAgentA2AExecutor) isn't constrained the same way, since the
SDK's AgentExecutor/EventQueue pattern is decoupled from
this loop.
Attributes:
| Name | Type | Description |
|---|---|---|
a2a_agents_registry |
dict[str, A2AAgentSpec]
|
Registered A2A peers, keyed by name. |
Source code in src/llm_agents_from_scratch/a2a/client/tools.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | |
parameters_json_schema
property
¶
JSON schema for tool parameters.
The name field is constrained to an enum of registered A2A
peer names so the LLM can only dispatch to peers that exist.
task_id is optional — set it only to resume a remote task a
peer previously parked in TASK_STATE_INPUT_REQUIRED.
__init__
¶
Initialise with a registry of A2A peer agents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a2a_agents_registry
|
dict[str, A2AAgentSpec]
|
A2A peers to register, keyed by name. |
required |
Source code in src/llm_agents_from_scratch/a2a/client/tools.py
__call__
async
¶
Dispatch a task to the named A2A peer and return its result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_call
|
ToolCall
|
The tool call to execute. |
required |
*args
|
Any
|
Additional positional arguments. |
()
|
**kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
ToolCallResult |
ToolCallResult
|
The peer's result content on success, an
|
Source code in src/llm_agents_from_scratch/a2a/client/tools.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | |