Skip to content

Type to search the docs, or jump to:

How to Extend the A2UI Agent SDK

Extend the A2UI Agent SDK through public, framework-agnostic interfaces to add new inference formats, transform catalogs, load catalogs from custom backends, or publish standalone extension packages without importing private SDK internals.

Extension points at a glance

GoalPublic interfaceScope
Add a new LLM syntax or wire notationInferenceFormatFactory, InferenceFormat, PromptGenerator, Parser, ResponseStreamTypeScript, Python, Dart
Prune or rewrite a catalog before prompting/validationCatalogTransformer on CatalogConfigTypeScript, Python, Dart
Load catalogs from a database, service, or registryCatalogProviderTypeScript, Python, Dart
Define server-side composite components@macro, MacroExpanderPython
Validate and commit messages from a custom loopRendererState.commit, validate_payloadPython (RendererState + validatePayload in TS and Dart)
Inspect component properties dynamicallya2ui.utils.experimental.CatalogSchemaInspector (@experimental, transitioning to CatalogModel)Python
Handle renderer-to-agent RPC and client actionsRendererToAgentMessageProcessor, RendererFunctionCallsTypeScript, Python, Dart

Import from the single SDK entry point

Each Agent SDK exposes its core extension contracts from one public entry point so third-party packages avoid deep submodule imports.

import {
A2uiGenerator,
A2uiRequestProcessor,
type CatalogProvider,
type CatalogTransformer,
type InferenceFormat,
type InferenceFormatFactory,
Parser,
PromptGenerator,
RendererState,
} from '@a2ui/agent';

Implement a custom inference format

To teach an LLM a new syntax (for example, a domain-specific shorthand or structured DSL), implement PromptGenerator, Parser, InferenceFormat, and InferenceFormatFactory. Pass your factory to A2uiGenerator or A2uiRequestProcessor, or pass the InferenceFormat your factory creates to SkillGenerator so generated skills reuse the same prompt hooks.

import {
A2uiRequestProcessor,
type AgentToRendererMessage,
type CatalogApi,
type InferenceFormat,
type InferenceFormatFactory,
Parser,
PromptGenerator,
} from '@a2ui/agent';
// Implement Parser (compile, decompile, wrap, unwrap, etc.) for your syntax.
declare class CustomParser extends Parser {}
declare const catalogs: CatalogApi[];
class CustomPromptGenerator extends PromptGenerator {
constructor(catalogs: CatalogApi[]) {
super(catalogs);
}
generateBaseRules(): string {
return 'Wrap UI payloads inside <my-ui>...</my-ui>.';
}
protected renderCatalogInstructions(catalog: CatalogApi): string {
return `Catalog: ${catalog.id}`;
}
protected renderExamples(_catalog: CatalogApi): string {
return '';
}
}
class CustomFormatFactory implements InferenceFormatFactory {
createFormat(
catalogs: CatalogApi[],
_examples?: Record<string, AgentToRendererMessage[] | string>,
): InferenceFormat {
return {
promptGenerator: new CustomPromptGenerator(catalogs),
createParser: () => new CustomParser(catalogs),
};
}
}
const processor = new A2uiRequestProcessor(catalogs, undefined, new CustomFormatFactory());

Transform catalogs and define macros

Use CatalogTransformer on CatalogConfig when you need to rewrite or prune a catalog at runtime before prompting and validation (such as ComponentPruningTransformer or FunctionPruningTransformer). The transformed catalog is computed once per CatalogConfig and reused across requests.

For server-side composite components authored with @macro and expanded with MacroExpander, see Using Macros.

Model providers and agent frameworks

The A2UI Agent SDK stays intentionally agnostic to LLM client libraries, network transports, and credentials:

  • Standard LLM providers (Gemini, OpenAI, Anthropic, local models, or framework runtimes such as ADK and LangGraph) integrate outside a2ui-agent-sdk by feeding processor.prompt_snippet into your model call and passing streamed text chunks into processor.open_stream() or processor.parse_response(). See How to Integrate A2UI into an Agent.
  • Specialized model extensions (such as custom planner or decision-model packages) define narrow async callable protocols in their own extension packages and validate emitted AgentToRendererMessage payloads through RendererState.commit or validate_payload.

Validate and commit messages from a custom loop

If your extension synthesizes A2UI messages directly instead of parsing LLM text, use RendererState.commit to validate and commit batches atomically to a RendererState, or validate_payload for stateless validation:

from a2ui.agent import (
RendererState,
to_message_dicts,
to_message_models,
validate_payload,
)
from a2ui.core.basic_catalog import BasicCatalog
from a2ui.core.schema import ProtocolVersion
catalogs = [BasicCatalog(ProtocolVersion.V1_0)]
state = RendererState(catalogs)
candidate_messages = list(
to_message_models([
{
"version": "1.0",
"createSurface": {
"surfaceId": "status_1",
"catalogId": catalogs[0].catalog_id,
},
},
{
"version": "1.0",
"updateComponents": {
"surfaceId": "status_1",
"components": [
{"id": "root", "component": "Text", "text": "Ready"},
],
},
},
])
)
state.commit(candidate_messages)
wire_payload = to_message_dicts(candidate_messages)

For stateless validation without mutating a session’s RendererState, call validate_payload(catalogs, candidate_messages).

Inspect catalog schemas dynamically

Extensions that generate UI generically across arbitrary catalogs can inspect components, child slots, actions, and bindable properties with CatalogSchemaInspector (@experimental in a2ui.utils.experimental, scheduled to be superseded by canonical CatalogModel in a2ui-core):

from a2ui.core.basic_catalog import BasicCatalog
from a2ui.core.schema import ProtocolVersion
from a2ui.utils.experimental import CatalogSchemaInspector, resolve_default_catalog_id
catalogs = [BasicCatalog(ProtocolVersion.V1_0)]
inspectors = CatalogSchemaInspector.for_catalogs(catalogs)
default_cid = resolve_default_catalog_id(catalogs)
assert default_cid is not None
inspector = inspectors[default_cid]
for prop in inspector.component_property_infos("Button"):
print(f"Button.{prop.name}: kind={prop.kind}, required={prop.required}")

Package a standalone Python extension

To ship a reusable third-party extension package:

  1. Depend only on a2ui-core and a2ui-agent-sdk in pyproject.toml, keeping core logic free of agent framework, transport, and LLM client dependencies.
  2. Import only from top-level public facade modules (a2ui.agent, a2ui.constants, a2ui.core, a2ui.core.basic_catalog, a2ui.core.schema, a2ui.builder.v1_0, and a2ui.utils.experimental for opt-in experimental schema inspection). Never deep-import internal submodules, even those without a leading underscore.
  3. Enforce the boundary in CI with Ruff’s [tool.ruff.lint.flake8-tidy-imports.banned-api] (banning internal a2ui.* submodules and any agent framework or transport imports in your core package).
[project]
name = "acme-a2ui-charts"
version = "0.1.0"
dependencies = [
"a2ui-core>=0.8.0,<0.9.0",
"a2ui-agent-sdk>=0.14.0,<0.15.0",
]