A2uiRequest

class A2uiRequest(catalog: CatalogDefinition, renderToolName: String = AguiA2ui.RENDER_TOOL_NAME, guidelines: Boolean = true)

What a run has to carry for an agent to draw A2UI at all: the request side of the convention whose response side the rest of this module reads.

Upstream's agents do not offer to draw. Their adapters -- Strands, LangGraph, ADK, CrewAI, Mastra -- inject their generate_a2ui tool only when the run's forwardedProps carries injectA2UITool, and put the client's components in front of the model only when the run's context carries the schema entry catalogContext builds. Neither is in the AG-UI specification; both are what @ag-ui/a2ui-middleware adds to every request when it runs in front of the agent, and a client that talks to the agent without that middleware in front -- which is every client this repository is for -- has to add them itself. Without them the agent answers in text, with nothing in the stream to say why.

Three things, mirrored from the middleware's injectToolAndFlag and injectSchemaContext:

  • forwardedProps.injectA2UITool: true, or the render tool's name when it is not the default, which is the value the middleware forwards from its own configuration. Never false: an explicit false overrides an agent's server-side opt-in, and absence does not.

  • The schema Context entry, from catalogContext. The agents read the catalog id out of it and hand the rest to the model.

  • The render tool's usage guide, a second Context entry the middleware sends alongside the schema. The Python adapters put every context entry into the generating sub-agent's prompt, so an agent behind upstream's dojo sees this text, and an agent behind this client should see the same. Off with guidelines false.

What it does not do is declare the render_a2ui tool. The middleware adds it to tools because it answers the call itself; here, declaring a tool is what registering an executor does, and RenderA2UiTool's KDoc says when to. Strands drops the declaration by name and calls generate_a2ui instead, so an agent that never asks the client to answer loses nothing.

val request = A2uiRequest(catalog)
RunAgentParameters(context = request.context(), forwardedProps = request.forwardedProps())

Send it on every run. Both methods take what the caller already carries and add to it, replacing an entry of the same description or key rather than adding a second.

Parameters

catalog

the catalog this client draws -- the one its renderer holds.

renderToolName

the render tool's name, for an agent configured with a custom one.

guidelines

whether to send the usage guide.

Constructors

Link copied to clipboard
constructor(catalog: CatalogDefinition, renderToolName: String = AguiA2ui.RENDER_TOOL_NAME, guidelines: Boolean = true)

Functions

Link copied to clipboard
fun context(existing: List<Context> = emptyList()): List<Context>

existing with the schema entry, and the guidelines entry when on, replacing any of the same description.

Link copied to clipboard
fun forwardedProps(existing: JsonObject = JsonObject(emptyMap())): JsonObject

existing with injectA2UITool set, replacing any value already under that key.