Skip to content

feat(python,docs): add a2ui.agent facade, inference_formats re-exports, and extending-the-sdk guide - #4543

Closed
gspencergoog wants to merge 1 commit into
a2ui-project:feat/modular-agent-seamsfrom
gspencergoog:feat/agent-facade-and-transformers
Closed

gspencergoog wants to merge 1 commit into
a2ui-project:feat/modular-agent-seamsfrom
gspencergoog:feat/agent-facade-and-transformers

Conversation

@gspencergoog

@gspencergoog gspencergoog commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Add the unified a2ui.agent facade and a2ui.inference_formats ABC re-exports (InferenceFormat, InferenceFormatFactory) to a2ui-agent-sdk. Also add docs/site/src/content/docs/guides/extending-the-sdk.mdx showing how to extend the Agent SDK through public interfaces.

Reviewer Focus

  • python/a2ui_agent/src/a2ui/agent.py: Single top-level facade for agent coordination, formats, transformers, macros, validation, skills, and RPC. Matches @a2ui/agent in TypeScript and package:a2ui_agent/a2ui_agent.dart in Dart.
  • python/a2ui_agent/src/a2ui/inference_formats/__init__.py: Re-exports InferenceFormat and InferenceFormatFactory alongside the built-in format implementations.
  • docs/site/src/content/docs/guides/extending-the-sdk.mdx: Developer guide covering custom inference formats, CatalogTransformer, @macro / MacroExpander, RendererState.commit / validate_payload, CatalogSchemaInspector, and standalone extension packaging.

Changes

  • Added python/a2ui_agent/src/a2ui/agent.py exporting 44 public SDK contracts in __all__.
  • Re-exported InferenceFormat and InferenceFormatFactory from python/a2ui_agent/src/a2ui/inference_formats/__init__.py.
  • Added docs/site/src/content/docs/guides/extending-the-sdk.mdx, registered it in docs/site/astro.config.mjs, and linked to it from docs/site/src/content/docs/guides/agent-integration.mdx and docs/site/src/content/docs/concepts/inference-formats.mdx.
  • Added unit tests in python/a2ui_agent/tests/test_agent_facade.py and updated python/a2ui_agent/CHANGELOG.md.

Impact & Risks

Testing

  1. Run unit tests:
    uv run pytest python/a2ui_agent/tests/test_agent_facade.py python/a2ui_agent/tests/test_macro_lowering.py python/a2ui_agent/tests/processor/
  2. Run type checking:
    uv run mypy python/a2ui_agent/src/a2ui/agent.py python/a2ui_agent/src/a2ui/inference_formats/__init__.py
  3. Check formatting:
    uv run pyink --check python/a2ui_agent/src/a2ui/agent.py python/a2ui_agent/tests/test_agent_facade.py and prettier --check docs/site/src/content/docs/guides/extending-the-sdk.mdx

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a unified a2ui.agent public facade for the Python Agent SDK, adds composable A2uiTransformer support to A2uiRequestProcessor and A2uiGenerator, and updates MacroExpander to subclass the new transformer. It also includes comprehensive documentation and tests for extending the SDK. The review feedback highlights critical issues to address: copying transport_state.surface_catalogs before mutating it to avoid runtime errors or side effects, resolving error handling and type mismatches in _TransformingResponseStream.close(), and properly importing and exporting to_message_models in a2ui/inference_formats/__init__.py to prevent an ImportError.

@gspencergoog gspencergoog changed the title feat(agent): add a2ui.agent facade, A2uiTransformer composition, and extension guide feat(python,docs): add a2ui.agent facade, inference_formats re-exports, and extending-the-sdk guide Dec 2, 2026
@gspencergoog
gspencergoog requested review from jacobsimionato and removed request for jacobsimionato December 2, 2026 21:30
@gspencergoog
gspencergoog marked this pull request as draft December 2, 2026 21:33
…s, and extending-the-sdk guide

Signed-off-by: Greg Spencer <gspencer@google.com>
@gspencergoog
gspencergoog force-pushed the feat/modular-agent-seams branch from 2dfff42 to bc5a623 Compare December 2, 2026 22:05
@gspencergoog
gspencergoog force-pushed the feat/agent-facade-and-transformers branch from aee32d9 to 2cbb544 Compare December 2, 2026 22:05
@gspencergoog
gspencergoog deleted the branch a2ui-project:feat/modular-agent-seams December 2, 2026 22:21
return 'Wrap UI payloads inside <my-ui>...</my-ui>.';
}
protected renderCatalogInstructions(catalog: CatalogApi): string {
return `Catalog: ${catalog.catalogId}`;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TypeScript and Dart custom PromptGenerator snippets fail to compile because CatalogApi exposes id (not catalogId) in both SDKs, and the Dart override adds a bool includeSchema = true parameter that Dart's base PromptGenerator.generateCatalogInstructions does not define or pass. All three tabs also reference undefined CustomParser, CustomFormat (Dart), and catalogs (TypeScript/Python) without stubs, and TypeScript imports RawResponsePart unused.

Additional details
  • TypeScript (typescript/core/web_core/src/catalog/types.ts declares readonly id: string):
    • Line 100: catalog.catalogId -> catalog.id
    • Line 89: remove unused type RawResponsePart (unless used in a CustomParser stub)
    • Lines 114 & 119: define catalogs and add a minimal CustomParser stub or comment
  • Dart (dart/a2ui_core/lib/src/core/catalog.dart declares final String id, and dart/a2ui_agent/lib/src/prompt/generator.dart declares generateCatalogInstructions({CatalogApi? catalog})):
       @override
    -  String generateCatalogInstructions({
    -    bool includeSchema = true,
    -    CatalogApi? catalog,
    -  }) {
    +  String generateCatalogInstructions({CatalogApi? catalog}) {
         final targets = catalog != null ? [catalog] : catalogs;
    -    return targets.map((c) => 'Catalog: ${c.catalogId}').join('\n');
    +    return targets.map((c) => 'Catalog: ${c.id}').join('\n');
       }
    • Line 218: add a minimal CustomFormat stub or placeholder comment (and show passing the factory to A2uiRequestProcessor).
  • Python (lines 169 & 182): define catalogs and either provide a minimal CustomParser stub or comment noting Parser's six abstract members (catalogs, has_format_content, wrap, unwrap, compile, decompile).

🤖 Agent-generated

version = "0.1.0"
dependencies = [
"a2ui-core>=0.7.0",
"a2ui-agent-sdk>0.12.1",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pinning a2ui-agent-sdk>0.12.1 resolves to the already-tagged 0.13.0 release, which does not include a2ui.agent, RendererState.commit, or a2ui.utils.experimental, so extensions copying this manifest will fail at import time with ModuleNotFoundError. In addition, a2ui-core>=0.7.0 on the previous line is looser than a2ui-agent-sdk's own a2ui-core>=0.8.0,<0.9.0 requirement.

Additional details

Tag python/a2ui-agent-sdk/v0.13.0 (90f4a8cc2c) predates a2ui/agent.py, and python/a2ui_agent/pyproject.toml already sets fallback-version = "0.13.0" and requires "a2ui-core>=0.8.0,<0.9.0".

Update both constraints to match the first release that ships a2ui.agent:

 dependencies = [
-    "a2ui-core>=0.7.0",
-    "a2ui-agent-sdk>0.12.1",
+    "a2ui-core>=0.8.0,<0.9.0",
+    "a2ui-agent-sdk>=0.14.0,<0.15.0",
 ]

🤖 Agent-generated

@@ -0,0 +1,323 @@
---
title: 'How to Extend the A2UI SDK'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because A2UI has separate Core, Agent, and Renderer SDKs—and this guide covers only the Agent SDK—calling it "How to Extend the A2UI SDK" (with slug guides/extending-the-sdk) can mislead client or renderer developers looking for Core or Renderer extension points. Let's scope the title and slug to How to Extend the A2UI Agent SDK (guides/extending-the-agent-sdk) before merge, add it to docs/site/llms.txt, and remove the stale "composable transformers" wording in the agent-integration.mdx link.

Additional details

Details to update together:

  • Title & slug: Rename title to 'How to Extend the A2UI Agent SDK' and slug to guides/extending-the-agent-sdk in docs/site/astro.config.mjs (lines 252–253), matching sibling guides (How to Integrate A2UI into a Client, How to Integrate A2UI into an Agent), and update the links in docs/site/src/content/docs/concepts/inference-formats.mdx:288 and docs/site/src/content/docs/guides/agent-integration.mdx:1703.
  • Stale link copy (agent-integration.mdx:1703): Replace composable transformers (dropped when converging on feat(python/agent): add TransformerPipeline, macro-safe streaming (#2865) #4533) with catalog transformers, catalog providers.
  • Agent discovery (docs/site/llms.txt): All 10 existing guides are listed under ## Integration Guides (lines 48–57); add - [How to Extend the A2UI Agent SDK](https://a2ui.org/guides/extending-the-agent-sdk/) ([Markdown](https://a2ui.org/guides/extending-the-agent-sdk.md)) after Using Macros.
Suggested change
title: 'How to Extend the A2UI SDK'
title: 'How to Extend the A2UI Agent SDK'

🤖 Agent-generated

</Tabs>

<Aside type="note" title="Do not override PromptGenerator.generate()">
`PromptGenerator.generate()` is final in Python and shared with `SkillGenerator`. Override

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shared callout below the three-language tabs mentions only Python's @final and snake_case hooks, which contradicts the TypeScript tab right above it (where subclasses implement renderCatalogInstructions and renderExamples and overriding generate() silently diverges from SkillGenerator) and omits Dart's @nonVirtual. Similarly, line 75 says SkillGenerator picks up prompt hooks automatically when passing the factory to A2uiGenerator or A2uiRequestProcessor, whereas callers pass the InferenceFormat created by the factory directly to SkillGenerator.

Additional details

Actual contracts across the three SDKs:

  • TypeScript (typescript/agents/a2ui_agent/src/prompt/generator.ts, skill/generator.ts): generate() is concrete (not final), while SkillGenerator calls generateBaseRules(), generateCatalogInstructions(c), and generateExamples(c)—so overriding generate() silently diverges from generated skills. Subclasses implement generateBaseRules(), renderCatalogInstructions(catalog), and renderExamples(catalog).
  • Python (python/a2ui_agent/src/a2ui/prompt/generator.py): generate() is @final; hooks are generate_base_rules(), generate_catalog_instructions(), and generate_examples().
  • Dart (dart/a2ui_agent/lib/src/prompt/generator.dart): generate() is @nonVirtual; hooks are generateBaseRules(), generateCatalogInstructions(), and generateExamples().
  • SkillGenerator wiring (line 75): Across all three SDKs, SkillGenerator takes an InferenceFormat instance directly (A2uiRequestProcessor._format is private in TS and Dart), so rephrase line 75 to: Pass your factory to A2uiGenerator or A2uiRequestProcessor, or pass the InferenceFormat your factory creates to SkillGenerator so generated skills reuse the same prompt hooks.

🤖 Agent-generated


## Transform catalogs and define macros

Use `CatalogTransformer` on `CatalogConfig` when you need a static per-catalog rewrite before prompting (such as `ComponentPruningTransformer` or `FunctionPruningTransformer`).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling this a "static" rewrite is misleading because CatalogConfig runs CatalogTransformer.transform() at runtime (lazily on first use and cached on the config), not at build or compile time. Describing it as a per-catalog rewrite applied before prompting and validation avoids making readers think it is an offline/build-time step (same for "statically" in the overview table on line 15).

Additional details

In python/a2ui_agent/src/a2ui/processor/catalog_config.py, CatalogConfig.transformed_catalog is a @cached_property that executes each configured CatalogTransformer sequentially at runtime on first use and reuses the result across requests.

Suggested change
Use `CatalogTransformer` on `CatalogConfig` when you need a static per-catalog rewrite before prompting (such as `ComponentPruningTransformer` or `FunctionPruningTransformer`).
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.

Also consider updating line 15 in the overview table from Prune or rewrite a single catalog statically to Prune or rewrite a catalog before prompting and validation.

🤖 Agent-generated

To ship a reusable third-party extension package (following the same architecture as `a2ui-agent-experimental`):

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.core`, `a2ui.core.basic_catalog`, `a2ui.core.schema`, `a2ui.builder.v1_0`). Never deep-import internal submodules, even those without a leading underscore.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This packaging checklist contradicts the guide itself and cites a nonexistent package: step 2's allowlist omits a2ui.utils.experimental even though line 295 right above imports from it (so step 3's custom ast test fails on the guide's own code), and lines 242 and 309 cite a2ui-agent-experimental and DecisionModel, which do not exist in the repo or on PyPI.

Additional details
  • Allowlist mismatch (line 312): Include a2ui.utils.experimental (for optional experimental schema inspection) and a2ui.constants (zero-dependency leaf constants), or simplify once internals are hidden behind _-prefixed subpackages under a2ui.agent.
  • Enforcing without custom ast scripts (line 313): Until internals are _-prefixed, a few lines of Ruff [tool.ruff.lint.flake8-tidy-imports.banned-api] is lighter for extension authors than maintaining a custom ast test.
  • Nonexistent package/symbol (lines 242 & 309): git grep finds zero matches for a2ui-agent-experimental or DecisionModel outside this file—keep both lines generic (e.g. "custom planner or decision-model packages" on line 242, and "To ship a reusable third-party extension package:" on line 309).

🤖 Agent-generated

## Unreleased

- Added the unified `a2ui.agent` public facade and re-exported `InferenceFormat`
and `InferenceFormatFactory` from `a2ui.inference_formats`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changelog entry is missing the PR link ([#4543](...)), breaking traceability in generated release notes and diverging from the other entries under ## Unreleased.

Additional details

Per .agents/skills/update-changelog/SKILL.md (Core Rule 6), every changelog entry should conclude with a clickable PR link.

Suggested change
and `InferenceFormatFactory` from `a2ui.inference_formats`.
and `InferenceFormatFactory` from `a2ui.inference_formats`
([#4543](https://github.com/a2ui-project/a2ui/pull/4543)).

🤖 Agent-generated

# See the License for the specific language governing permissions and
# limitations under the License.

"""Unified public facade for the A2UI Python Agent SDK.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's aim for one canonical way to import everything from a2ui-agent-sdk instead of maintaining parallel top-level paths alongside a2ui.agent. Structuring this as a package (a2ui/agent/__init__.py, matching a2ui.core, a2ui.a2a, and a2ui.adk) lets us move internals behind _-prefixed subpackages (with one-release DeprecationWarning shims on the legacy paths) so Pyright/Pylance, Ruff, and IDE auto-import enforce the single entry point automatically instead of asking every downstream author to write a custom ast test. Along the same lines, let's skip adding new exports to a2ui.inference_formats and fill the missing public exports on a2ui.agent so extensions don't have to reach past it.

Additional details

Concrete pieces to align around a single public surface:

  1. Use a package (src/a2ui/agent/__init__.py) + plan to hide internals behind _: Matches a2ui/core/, a2ui/a2a/, and a2ui/adk/. Moving implementations under a2ui/agent/_... in a follow-up (with DeprecationWarning shims like a2ui.core._compat / a2ui.inference_strategy) makes reportPrivateImportUsage / Ruff PLC2701 enforce the boundary for all users automatically. Separate intentional sub-facades stay explicit: a2ui.constants (zero-dependency leaf), a2ui.builder.v0_9/v1_0 (protocol-versioned), and opt-in experimental APIs (e.g. a2ui.agent.experimental).
  2. Don't widen a2ui.inference_formats/__init__.py: Avoid adding new public re-exports (InferenceFormat, InferenceFormatFactory) to a legacy path we want to consolidate away from—callers already have a2ui.inference_format for backwards compatibility and a2ui.agent going forward.
  3. Export the missing public Agent SDK symbols on a2ui.agent: Custom Parser.compile implementations and format extensions currently have to deep-import A2uiCompilationError, A2uiCompilationParseError, A2uiCompilationValidationError (a2ui.parser), DirectJsonResponseStream, DirectJsonDecompiler (a2ui.inference_formats.direct_json), and ExpressDecompiler (a2ui.inference_formats.express)—all of which are exported by @a2ui/agent (and ExpressResponseStream is already here). Also, to_message_dicts/to_message_models can be imported directly from a2ui.parser rather than through a2ui.inference_formats.

(Note: DirectJsonPromptGenerator/ExpressPromptGenerator were intentionally unexported in #3568, so keeping those out makes sense; sibling a2ui-a2a also currently imports BlockLexer, JSON_PAYLOAD_START_RE, read_json, and to_version_number, which is worth auditing before deprecating the legacy paths.)

🤖 Agent-generated

"to_message_models",
}
exported = set(agent.__all__)
assert expected.issubset(exported)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test checks only hasattr on a 20-symbol subset (omitting validate_payload, which the guide highlights) and deduplicates agent.__all__ via set(...), so duplicate or unsorted __all__ entries, leaked private (_-prefixed) names, or accidental a2ui.core pass-through re-exports would pass unnoticed.

Additional details

Strengthening the invariants catches facade regressions automatically:

assert agent.__all__ == sorted(set(agent.__all__))
assert all(not name.startswith("_") for name in agent.__all__)
public_attrs = {
    name for name in vars(agent) if not name.startswith("_") and name != "annotations"
}
assert public_attrs == set(agent.__all__)

You can also add "validate_payload" to expected and assert identity (is) against the defining submodules plus not getattr(getattr(agent, name), "__module__", "").startswith("a2ui.core") to guard against cross-package re-export leaks.

🤖 Agent-generated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants