feat(python): implement A2UI synchronous template expansion engine with version 0.1 validation - #2381
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the a2ui.template package, providing a robust server-side UI template engine for the A2UI Python Agent SDK. It includes support for static YAML-based templates, dynamic resolvers, and programmatic render functions, along with a synthetic catalog generation system for LLM integration. The review identified several critical issues, including potential runtime errors with asynchronous resolver execution, incomplete dataclass normalization, inefficient helper function definitions, missing circular reference detection, and overly simplistic parameter inference logic. These issues have been addressed to ensure robustness and compliance with the project's specification.
a201012 to
e51913e
Compare
|
Addressed reviewer feedback and synced with updated specification:
|
b7597fd to
3f100c4
Compare
3f1bfff to
50fbca1
Compare
…definition specification
50fbca1 to
282c386
Compare
f2e17c4 to
bbcf39c
Compare
…cursion, and max depth
bbcf39c to
d610be3
Compare
…th version 0.1 validation
…processor, and test_format
…tion/proposals/templates/schema
…at, and fix relative doc link
…alogs, and imports in templates
d610be3 to
9ba72fc
Compare
Summary
[Part 2 of 4 in Templates Stack - Depends on #2380]
This PR implements the A2UI Server-Side Template Engine in the Python Agent SDK under experimental inference formats (
agent_sdks/python/a2ui_agent/src/a2ui/inference_formats/experimental/template/).It provides synchronous template expansion, synthetic component catalog synthesis for LLM prompt generators, support for static YAML templates, dynamic data-binding resolvers, and programmatic Python render functions.
Architectural Highlights
a2ui.inference_formats.experimental.templateand decorated with@experimentalto communicate preview status.inference_formats/experimental/template/.TemplateProcessoroperates independently with zero hardcoded primitives or catalog fallbacks (base_catalog: Optional[CatalogSchema] = None). Primitives and catalog IDs are dynamically derived from the provided catalog or left empty for template-only generation.TemplateId,InstanceId,ComponentId,ParamPath), template evaluation (TemplateParams,TemplateNodeDict), wire-format outputs (A2UIComponent,A2UIComponentList,A2UIMessage), and catalog schemas (CatalogSchema,JSONSchemaDict)._resolve_param_path,_substitute_params,_validate_templates) with backward-compatible deprecation aliases.0.1): Validates that all ingested templates declareversion == "0.1"and serializes the version tag across dict and YAML outputs.resolver) query databases/APIs and inject sensitive data directly into presentation layouts, keeping confidential numbers out of prompt contexts.normalize_node()automatically recognizes dataclasses or any class implementing.to_dict(), enabling seamless future integration with fluent builders.{parent}_{slot}_{index}_{type}).ValueErroron circular template references and enforcesMAX_EXPANSION_DEPTH = 32.TemplateInferenceFormatbridges registered templates into system prompt instructions and parses LLM outputs synchronously.Testing & Verification
agent_sdks/python/a2ui_agent/tests/inference_formats/experimental/template/test_template_format.py.int,bool,dict)child,children)0.1success vs. unsupported version rejection)base_catalog=Nonebehavior and custom domain catalogsStack Context