loom.ai.a2a

Pure A2A projection of a compiled agent.

Holds the card projection and the event projection, both derived from the compiled AgentPlan alone (R-005). Neither imports an A2A SDK nor a web framework, so importing this package on a base installation succeeds and the redaction guarantee (FR-038, SC-009) is unit-testable. The transport server lives behind the ai-a2a extra and is not re-exported here.

class loom.ai.a2a.A2AEventProjector(*, task_id, context_id, max_steps)[source]

Bases: object

Projects one run’s agent events onto A2A streaming events.

A projector belongs to a single run: it holds the correlation ids of that run and the tool-call counter backing the opaque ordinal, so it is neither shared between runs nor safe to reuse across them.

Parameters:
  • task_id (str) – Id of the A2A task the run is served as.

  • context_id (str) – Id of the A2A context the task belongs to.

  • max_steps (int) – Iteration ceiling of the run, published as the denominator of the ordinal.

Example:

projector = A2AEventProjector(task_id=task, context_id=ctx, max_steps=12)
for event in events:
    frames = projector.project(event)
project(event)[source]

Project one agent event onto the A2A events it maps to.

Parameters:

event (TextDeltaEvent | ToolCallEvent | ToolResultEvent | ErrorEvent | FinalEvent) – Agent event to project.

Returns:

The projected A2A events, in emission order; final is the only member producing more than one.

Raises:

KeyError – When the event is not one of the five contract members — widening the union without widening this map is a contract break, not a silent pass-through.

Return type:

tuple[Mapping[str, object], …]

loom.ai.a2a.agent_url(base_url, name, *, prefix=DEFAULT_A2A_PREFIX)[source]

Build the public endpoint of one agent.

Parameters:
  • base_url (str) – Public base URL of the deployment; a trailing slash is a typo and is ignored rather than producing a different endpoint.

  • name (str) – Agent name.

  • prefix (str) – Path prefix the A2A surface is mounted under.

Returns:

The absolute URL clients send A2A requests to.

Return type:

str

Example:

agent_url("https://api.example.com", "market")  # .../a2a/market
loom.ai.a2a.build_agent_card(plan, config, *, mechanism, prefix=DEFAULT_A2A_PREFIX)[source]

Project a compiled agent into its public A2A agent card.

Only the agent’s identity, its endpoint, the modes actually served and the security scheme in use are published. Instructions, model binding, region, credentials, policies, metadata and capability wiring are never projected (FR-038, SC-009).

Parameters:
  • plan (AgentPlan) – Compiled agent to describe.

  • config (A2AConfig) – A2A exposure settings supplying the deployment’s base URL.

  • mechanism (str | None) – Authentication mechanism the endpoint enforces; None, or one with no A2A representation, publishes no security scheme.

  • prefix (str) – Path prefix the A2A surface is mounted under.

Returns:

The agent card, ready to be serialised as JSON.

Return type:

Mapping[str, object]

Example:

card = build_agent_card(plan, config, mechanism="jwt")
loom.ai.a2a.card_path(name, *, prefix=DEFAULT_A2A_PREFIX)[source]

Build the well-known path serving one agent’s card.

The path is per agent so the authentication exclusion registered for it matches the card alone and never the invocation surface (FR-041b).

Parameters:
  • name (str) – Agent name.

  • prefix (str) – Path prefix the A2A surface is mounted under.

Returns:

The path of the agent card, relative to the deployment root.

Return type:

str