A2AAgentSpec¶
A2AAgentSpec — specification for a registered A2A peer agent.
A2AAgentSpec
¶
Bases: BaseModel
Specification for a registered A2A peer agent.
Each A2AAgentSpec entry registers a remote A2A-compliant peer under
name, derived directly from agent_card.name — there is no
separate local alias, since the card is remote/peer-controlled data
like the rest of the spec's inputs. name serves as the registry key
on the coordinator and as the enum value UseA2AAgentTool presents
to the LLM for dispatch. Discovery (fetching the peer's AgentCard)
is eager, at spec construction — the spec holds a fully resolved card,
not a lazy reference to one.
The spec is pure data: it never constructs or holds a live SDK
Client. Connecting to the peer is UseA2AAgentTool's job, done
fresh on each dispatch from this spec's url/headers/
agent_card.
url is likewise derived from the card rather than passed
independently: it should match
agent_card.supported_interfaces[0].url, not the URL from_url
fetched the card from — the two can legitimately differ (that's the
reason supported_interfaces exists as a separate list rather than
a single top-level field). A card declaring more than one interface is
a real possibility the protocol allows for, but this spec doesn't
attempt to disambiguate between them — it always takes the first. Our
own server (LLMAgentA2AExecutor) only ever publishes one, so
this is a deliberate simplification, not an oversight.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Registry key for this A2A agent, taken from
|
url |
str
|
Base URL of the remote A2A peer. Should match
|
headers |
dict[str, str] | None
|
Optional HTTP headers (e.g. auth) sent on requests to
this peer, both for card resolution and for dispatch, mirroring
|
agent_card |
AgentCard
|
The peer's resolved |
timeout |
float | None
|
Seconds |
Source code in src/llm_agents_from_scratch/a2a/client/spec.py
19 20 21 22 23 24 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 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 | |
from_agent_card
classmethod
¶
Builds a spec from an AgentCard already in hand.
Sync — covers cached cards, self-built cards, and test fixtures, with no network access performed here.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_card
|
AgentCard
|
The peer's already-resolved |
required |
headers
|
dict[str, str] | None
|
Optional HTTP headers sent on requests to this peer. |
None
|
timeout
|
float | None
|
Seconds |
60.0
|
Returns:
| Name | Type | Description |
|---|---|---|
A2AAgentSpec |
A2AAgentSpec
|
The constructed spec. |
Raises:
| Type | Description |
|---|---|
A2AAgentCardMissingInterfaceError
|
If |
Source code in src/llm_agents_from_scratch/a2a/client/spec.py
from_url
async
classmethod
¶
Fetches the peer's AgentCard from url, then builds a spec.
Async — resolves the card over the wire via A2ACardResolver
before delegating to from_agent_card. An unreachable peer
raises the underlying httpx error to the caller. url here
is only the card-resolution endpoint — the constructed spec's own
url comes from the fetched card's supported_interfaces
instead, which can legitimately differ.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
Base URL to resolve the peer's well-known |
required |
headers
|
dict[str, str] | None
|
Optional HTTP headers sent on requests to this peer. |
None
|
agent_card_path
|
str | None
|
Optional override for the well-known agent
card path. |
None
|
timeout
|
float | None
|
Timeout in seconds, applied both to this card
resolution and, via the returned spec, to every future
|
60.0
|
Returns:
| Name | Type | Description |
|---|---|---|
A2AAgentSpec |
A2AAgentSpec
|
The constructed spec. |
Raises:
| Type | Description |
|---|---|
A2AAgentCardMissingInterfaceError
|
If the fetched card
declares no |
Source code in src/llm_agents_from_scratch/a2a/client/spec.py
catalog
¶
Returns XML structured string for cataloging this A2A agent.
Nests the peer's declared AgentSkills (its agent_card.skills)
as an <a2a_skills> block, giving the coordinator finer-grained
routing signal than the top-level description alone. Omitted
entirely when the peer declares no skills.