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
| Goal | Public interface | Scope |
|---|---|---|
| Add a new LLM syntax or wire notation | InferenceFormatFactory, InferenceFormat, PromptGenerator, Parser, ResponseStream | TypeScript, Python, Dart |
| Prune or rewrite a catalog before prompting/validation | CatalogTransformer on CatalogConfig | TypeScript, Python, Dart |
| Load catalogs from a database, service, or registry | CatalogProvider | TypeScript, Python, Dart |
| Define server-side composite components | @macro, MacroExpander | Python |
| Validate and commit messages from a custom loop | RendererState.commit, validate_payload | Python (RendererState + validatePayload in TS and Dart) |
| Inspect component properties dynamically | a2ui.utils.experimental.CatalogSchemaInspector (@experimental, transitioning to CatalogModel) | Python |
| Handle renderer-to-agent RPC and client actions | RendererToAgentMessageProcessor, RendererFunctionCalls | TypeScript, 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';from a2ui.agent import ( A2uiGenerator, A2uiRequestProcessor, CatalogProvider, CatalogTransformer, InferenceFormat, InferenceFormatFactory, MacroExpander, Parser, PromptGenerator, RendererState, ResponseStream, macro,)import 'package:a2ui_agent/a2ui_agent.dart';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());from collections.abc import Sequence
from a2ui.agent import ( A2uiRequestProcessor, InferenceFormat, InferenceFormatFactory, Parser, PromptGenerator,)from a2ui.core import CatalogApifrom a2ui.core.basic_catalog import BasicCatalogfrom a2ui.core.schema import AgentToRendererMessage, ProtocolVersion
class CustomParser(Parser): """Subclass Parser and implement its six abstract members."""
def __init__(self, catalogs: Sequence[CatalogApi]) -> None: self._catalogs = list(catalogs)
@property def catalogs(self) -> list[CatalogApi]: return list(self._catalogs)
def has_format_content(self, response: str) -> bool: raise NotImplementedError()
def wrap(self, content: str) -> str: raise NotImplementedError()
def unwrap(self, response: str) -> str: raise NotImplementedError()
def compile(self, block: str) -> list[AgentToRendererMessage]: raise NotImplementedError()
def decompile(self, messages: Sequence[AgentToRendererMessage]) -> str: raise NotImplementedError()
class CustomPromptGenerator(PromptGenerator): def __init__(self, catalogs: Sequence[CatalogApi]) -> None: self._catalogs = list(catalogs)
@property def catalogs(self) -> list[CatalogApi]: return list(self._catalogs)
def generate_base_rules(self) -> str: return "Wrap UI payloads inside <my-ui>...</my-ui>."
def generate_catalog_instructions( self, include_schema: bool = True, catalog: CatalogApi | None = None, ) -> str: del include_schema targets = [catalog] if catalog is not None else self._catalogs return "\n".join(f"Catalog: {c.catalog_id}" for c in targets)
def generate_examples(self) -> str: return ""
class CustomFormat(InferenceFormat): def __init__(self, catalogs: Sequence[CatalogApi]) -> None: self._catalogs = list(catalogs) self._prompt = CustomPromptGenerator(self._catalogs)
@property def prompt_generator(self) -> PromptGenerator: return self._prompt
def create_parser(self) -> Parser: return CustomParser(self._catalogs)
class CustomFormatFactory(InferenceFormatFactory): def create_format( self, catalogs: Sequence[CatalogApi], examples: Sequence[Sequence[AgentToRendererMessage]] | None = None, ) -> InferenceFormat: del examples return CustomFormat(catalogs)
catalogs: list[CatalogApi] = [BasicCatalog(ProtocolVersion.V1_0)]processor = A2uiRequestProcessor(catalogs, format_factory=CustomFormatFactory())import 'package:a2ui_agent/a2ui_agent.dart';import 'package:a2ui_core/a2ui_core.dart';
class CustomPromptGenerator extends PromptGenerator { CustomPromptGenerator(this.catalogs);
@override final List<CatalogApi> catalogs;
@override String generateBaseRules() => 'Wrap UI payloads inside <my-ui>...</my-ui>.';
@override String generateCatalogInstructions({CatalogApi? catalog}) { final targets = catalog != null ? [catalog] : catalogs; return targets.map((c) => 'Catalog: ${c.id}').join('\n'); }
@override String generateExamples() => '';}
class CustomFormat implements InferenceFormat { CustomFormat(this.catalogs) : promptGenerator = CustomPromptGenerator(catalogs);
final List<CatalogApi> catalogs;
@override final PromptGenerator promptGenerator;
@override Parser createParser() => throw UnimplementedError('Return your Parser');}
class CustomFormatFactory implements InferenceFormatFactory { const CustomFormatFactory();
@override InferenceFormat createFormat( List<CatalogApi> catalogs, { List<List<AgentToRendererMessage>> examples = const [], }) => CustomFormat(catalogs);}
// Wire the factory into A2uiRequestProcessor:// final processor = A2uiRequestProcessor(// catalogs,// formatFactory: const 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-sdkby feedingprocessor.prompt_snippetinto your model call and passing streamed text chunks intoprocessor.open_stream()orprocessor.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
AgentToRendererMessagepayloads throughRendererState.commitorvalidate_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 BasicCatalogfrom 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 BasicCatalogfrom a2ui.core.schema import ProtocolVersionfrom 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:
- Depend only on
a2ui-coreanda2ui-agent-sdkinpyproject.toml, keeping core logic free of agent framework, transport, and LLM client dependencies. - 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, anda2ui.utils.experimentalfor opt-in experimental schema inspection). Never deep-import internal submodules, even those without a leading underscore. - Enforce the boundary in CI with Ruff’s
[tool.ruff.lint.flake8-tidy-imports.banned-api](banning internala2ui.*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",]