a2ui_agent library
The A2UI agent SDK: capability negotiation, prompting and response parsing for agents that generate A2UI.
Implements protocols v0.9 and v1.0 in two inference formats: direct JSON and Express, both of which can be read as they stream. The protocol version is the one the active catalogs target, which the agent negotiates with each renderer.
Classes
- A2uiFunctionResponse
-
The answer to a function call made across the wire, in either direction:
the body of
agentFunctionResponseandrendererFunctionResponse. - A2uiFunctionResponseError
- Why a function call failed, as reported in an A2uiFunctionResponse.
- A2uiGenerator
- The long-lived entry point to the agent SDK.
- A2uiPart
- A2UI messages compiled from one payload block of an LLM response, ready to deliver to a renderer.
- A2uiRequestProcessor
- The per-request facade: the catalogs negotiated with one renderer, the prompt snippet describing them, and parsing of the LLM's response.
- ActionMessage
- Carries a user-initiated action to the agent.
- AgentFunction
-
A catalog function whose handler runs on the agent over
callAgentFunction. - AgentFunctionContext
- Invocation metadata passed to an AgentFunctionHandler.
- AgentFunctionResponseMessage
- Answers a CallAgentFunctionMessage the renderer sent. Defined from v1.0 only.
-
AnswerErrorPart<
T extends ComponentApi> - A block the answer rejected, where the model wrote it.
-
AnswerPart<
T extends ComponentApi> - A part of a StreamedAnswer: its text, a surface it created, or a block it rejected.
-
AnswerSurfacePart<
T extends ComponentApi> - A surface the answer created, where the model wrote it.
-
AnswerTextPart<
T extends ComponentApi> - Text the model wrote between two surfaces, or before or after them.
- CallAgentFunctionMessage
- Asks the agent to run a function on the renderer's behalf. Defined from v1.0 only.
- CallRendererFunctionMessage
- Asks the renderer to run a function on the agent's behalf. Defined from v1.0 only.
- CatalogConfig
-
A catalog the agent supports, registered with an
A2uiGenerator, and the transformers applied to it. - CatalogProvider
- Turns a catalog document into a catalog an agent can register.
- CatalogTransformer
- A rule applied to a catalog before the catalog reaches a prompt or a validator.
- ComponentPruningTransformer
- Keeps only the components named in allowedComponents.
- DirectJsonContinuingResponseStream
- Reads one streamed direct JSON response, reading past a rejected block.
- DirectJsonFormat
- The direct JSON format bound to the catalogs of one request.
- DirectJsonFormatFactory
-
The direct JSON format: A2UI messages written as JSON inside
<a2ui-json>tags, which can be read while the response streams. - DirectJsonParser
-
Reads A2UI messages written as JSON inside
<a2ui-json>tags, from a complete response or as it streams. - DirectJsonPromptGenerator
-
Renders the system prompt snippet teaching a model to write A2UI messages
as JSON inside
<a2ui-json>tags. - DirectJsonResponseStream
- Reads one streamed direct JSON response.
- ErrorMessage
- Carries a renderer-side error to the agent.
- ErrorPart
- A block that a response stream rejected and read past, in place of the block.
- ExpressCompiler
- Compiles Express blocks into A2UI messages of the protocol version the catalogs target.
- ExpressContinuingResponseStream
- Reads one streamed Express response, reading past a rejected block.
- ExpressDecompiler
- Writes messages of the protocol version the catalogs target in Express notation: the inverse of the compiler.
- ExpressFormat
- The Express format bound to the catalogs of one request.
- ExpressFormatFactory
-
The Express format: a compact DSL enclosed in
<a2ui>tags, compiled into A2UI messages after the response is complete. - ExpressParser
- Reads Express blocks from an LLM response and compiles them into messages of the protocol version the catalogs target.
- ExpressPromptGenerator
- Renders the system prompt snippet teaching a model to write Express for catalogs.
- ExpressResponseStream
- Reads one streamed Express response chunk by chunk.
- FileSystemCatalogProvider
- Loads a catalog from a JSON document on the file system.
- FunctionPruningTransformer
- Keeps only the functions named in allowedFunctions.
- InferenceFormat
- One inference format bound to the catalogs of one request: the prompt that teaches the LLM the format, and the parser that reads what the LLM wrote.
- InferenceFormatFactory
- Selects the notation the LLM writes A2UI payloads in.
- InMemoryCatalogProvider
- Loads a catalog from a decoded JSON document.
- Parser
- Reads an LLM response written in one inference format.
- ProcessResult
- What RendererToAgentMessageProcessor.processMessage did with a message.
- PromptGenerator
- Renders the system prompt snippet teaching an LLM one inference format.
- RawA2uiPart
- The content of one payload block of an LLM response, without its sentinel tags, before it is compiled.
- RawResponsePart
- A slice of an LLM response before its payloads are compiled: TextPart or RawA2uiPart.
- RendererFunctionCalls
-
Builds outbound
callRendererFunctionmessages, correlates them with incomingrendererFunctionResponsemessages byfunctionCallId, and manages per-call timeouts and disposal. - RendererFunctionResponseMessage
- Answers a CallRendererFunctionMessage the agent sent. Defined from v1.0 only.
- RendererState
- The agent's mirror of the surfaces a renderer holds.
- RendererToAgentMessage
- Base class for the messages a renderer sends an agent.
- RendererToAgentMessageProcessor
- Processes the v1.0 messages a renderer sends an agent.
- ResponsePart
- A slice of a parsed LLM response: TextPart or A2uiPart.
-
ResponseReader<
P extends StreamPart> - Reads one streamed LLM response, chunk by chunk.
-
StreamedAnswer<
T extends ComponentApi> - One model answer, read as it streams, for an app that is both the agent and the renderer.
- StreamPart
- A slice of a streamed LLM response: a ResponsePart, or an ErrorPart in place of a block the stream rejected.
- TextPart
- Conversational text from an LLM response, for display to the user.
Enums
- RpcErrorCode
-
Why a function call across the wire failed, in the form both directions
of the protocol's
error.codecarry.
Extensions
- A2uiErrorPartialResults on A2uiError
- The parts a response stream made ready before it threw an error.
Constants
- a2uiClientCapabilitiesKey → const String
- Transport metadata key for v0.9 and v0.9.1 client capabilities.
- a2uiRendererCapabilitiesKey → const String
- Transport metadata key for v1.0 and later renderer capabilities.
-
defaultExpressProgressiveKeys
→ const Set<
String> -
Default property keys whose open string literals are healed progressively
while streaming an
<a2ui>Express block. - defaultRendererCallTimeout → const Duration
-
Default timeout for outbound
callRendererFunctioninvocations (30s).
Functions
-
agentCallableFunctions(
List< CatalogApi> catalogs) → List<String> -
The functions of
catalogsthe agent may ask the renderer to run withcallRendererFunction: those whoseallowedCallersadmits the agent, and which need no user activation, which a call from the agent never has. -
readRendererCapabilities(
Map< String, Object?> ? metadata, [A2uiProtocolVersion version = A2uiProtocolVersion.v1_0]) → A2uiRendererCapabilities? -
Reads and validates renderer capabilities for
versionfrom transportmetadata. -
resolveCatalogs(
List< CatalogConfig> catalogs, A2uiRendererCapabilities? rendererCapabilities, {bool acceptsInlineCatalogs = false}) → List<CatalogApi> - Negotiates the catalogs the agent registered against the capabilities a renderer declared, and returns the catalogs active for the session.
-
validatePayload(
List< CatalogApi> catalogs, Iterable<AgentToRendererMessage> payload) → void -
Checks
payloadthe way a renderer holdingcatalogswould.
Typedefs
-
AgentFunctionHandler
= FutureOr<
Object?> Function(Map<String, dynamic> args, AgentFunctionContext context) - A sync or async handler that executes an AgentFunction on the agent.
-
ContinuingResponseStream
= ResponseReader<
StreamPart> - A stream that reads past a rejected block, returning an ErrorPart in its place.
-
RendererMessageCallback<
T extends RendererToAgentMessage> = FutureOr< void> Function(T message) - A callback that receives one kind of message a renderer sent, such as an ActionMessage. It may return a Future, which is awaited.
-
ResponseStream
= ResponseReader<
ResponsePart> - A stream that ends at the first rejected block, and so returns only ResponseParts.
Exceptions / Errors
- A2uiRpcError
- A function call across the wire that failed, in either direction.