StreamingLLMAgentA2AExecutor¶
StreamingLLMAgentA2AExecutor — streaming variant of LLMAgentA2AExecutor.
StreamingLLMAgentA2AExecutor
¶
Bases: AgentExecutor
Bridges inbound A2A tasks to an LLMAgent, streaming updates.
Drives LLMAgent.run_supervised() directly instead of run():
SupervisedTaskHandler has no background task at all — execution
is entirely caller-driven via get_next_step()/run_step()
(built for Ch8's HITL use case, structurally identical to what
streaming needs). This executor calls that loop itself, publishing
a TaskStatusUpdateEvent after each step instead of prompting a
human — the same substitution LLMAgentA2AExecutor makes for the
non-streaming case, just at per-step instead of whole-run
granularity.
Two updates are published per step, not one: get_next_step()
makes its own LLM call to decide routing (except on the very first
step) — real, awaitable work in its own right, not just
bookkeeping — so its result (the planned instruction) is published
before run_step() executes it, and that step's result is
published after.
Because there's no separate background task, cancellation here is
simpler than LLMAgentA2AExecutor's: the SDK's own producer loop
already runs this executor's execute() as its own task, so
cancelling that task interrupts whatever step is currently
in-flight directly — there's no orphaned worker left running
underneath, unlike LLMAgentA2AExecutor.cancel()'s need to
separately cancel TaskHandler.background_task.
Attributes:
| Name | Type | Description |
|---|---|---|
agent |
LLMAgent
|
The agent this executor serves. |
_task_handlers |
dict[str, SupervisedTaskHandler]
|
In-flight runs, keyed by task_id. |
Source code in src/llm_agents_from_scratch/a2a/server/streaming_executor.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 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 | |
__init__
¶
Initialise with the agent to serve.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent
|
LLMAgent
|
The agent to bridge inbound A2A tasks to. |
required |
Source code in src/llm_agents_from_scratch/a2a/server/streaming_executor.py
execute
async
¶
Runs the agent step by step, publishing an update per step.
Only Exception is caught below, deliberately not
BaseException: asyncio.CancelledError (raised here when
the SDK cancels the producer task running this coroutine, per
cancel() below) must propagate uncaught. The SDK's own
producer loop wrapping this call has its own
except CancelledError that closes the event queue and lets
the producer task actually terminate. Catching and returning
normally here instead would make execute() look like it
finished successfully, leaving that producer task running —
parked awaiting a request that will never come.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
RequestContext
|
The request context containing the task instruction. |
required |
event_queue
|
EventQueue
|
The queue to publish task status/artifact events to. |
required |
Source code in src/llm_agents_from_scratch/a2a/server/streaming_executor.py
cancel
async
¶
Cancels the agent run backing an in-flight task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
RequestContext
|
The request context naming the task to cancel. |
required |
event_queue
|
EventQueue
|
The queue to publish the cancellation status update to. |
required |
Raises:
| Type | Description |
|---|---|
TaskNotFoundError
|
If |
Source code in src/llm_agents_from_scratch/a2a/server/streaming_executor.py
build_streaming_agent_card
¶
build_streaming_agent_card(
name,
description,
url,
version="0.1.0",
skills=None,
provider=None,
documentation_url=None,
security_schemes=None,
security_requirements=None,
signatures=None,
icon_url=None,
)
Builds an AgentCard for serving a StreamingLLMAgentA2AExecutor.
Mirrors executor.build_agent_card() exactly, except
capabilities is AgentCapabilities(streaming=True) — this
executor genuinely publishes incremental status updates per step,
unlike the non-streaming LLMAgentA2AExecutor. As with
build_agent_card(), every field describing executor behavior
is fixed rather than exposed as a parameter (supported_interfaces,
the default I/O modes, capabilities); pure descriptive metadata
that claims nothing about behavior stays overridable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The agent's name, shown to peers. |
required |
description
|
str
|
The agent's description, shown to peers. |
required |
url
|
str
|
The deployment URL this agent will be served at.
Must be supplied by the caller — nothing in this framework
can infer where a |
required |
version
|
str
|
The agent's version string. Defaults to
|
'0.1.0'
|
skills
|
list[AgentSkill] | None
|
The agent's declared skills. Defaults to an empty list. |
None
|
provider
|
AgentProvider | None
|
The agent's provider organisation. Defaults to unset. |
None
|
documentation_url
|
str | None
|
URL to the agent's documentation. Defaults to unset. |
None
|
security_schemes
|
dict[str, SecurityScheme] | None
|
Named security schemes the agent supports. Defaults to none. |
None
|
security_requirements
|
list[SecurityRequirement] | None
|
Security requirements callers must satisfy. Defaults to none. |
None
|
signatures
|
list[AgentCardSignature] | None
|
Cryptographic signatures over the card. Defaults to none. |
None
|
icon_url
|
str | None
|
URL to an icon representing the agent. Defaults to unset. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
AgentCard |
AgentCard
|
The constructed card, with a single
|
Source code in src/llm_agents_from_scratch/a2a/server/streaming_executor.py
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 | |