Skip to content

feat: Add a A2uiValidator to validate loaded examples#557

Open
nan-yu wants to merge 2 commits intogoogle:mainfrom
nan-yu:a2ui-validator
Open

feat: Add a A2uiValidator to validate loaded examples#557
nan-yu wants to merge 2 commits intogoogle:mainfrom
nan-yu:a2ui-validator

Conversation

@nan-yu
Copy link
Collaborator

@nan-yu nan-yu commented Jan 27, 2026

Description

This pull request significantly enhances the A2UI agent's capabilities by introducing a robust schema validation and management system. It allows for the programmatic loading and validation of A2UI messages and examples against their respective schemas, ensuring data integrity and consistency. The changes also streamline the packaging of A2UI schemas within the Python distribution, making the agent more self-contained and easier to deploy.

Highlights

  • A2uiValidator Implementation: Introduced a new A2uiValidator class to perform schema validation on A2UI messages, ensuring loaded examples conform to the defined A2UI schema versions (0.8 and 0.9+).
  • Schema Management System: Developed an A2uiSchemaManager to centralize the loading, resolution, and management of A2UI schemas, including basic, custom, and inline catalogs, and to generate system prompts for LLMs based on these schemas.
  • Build Process Integration: Integrated a Hatchling build hook (pack_specs_hook.py) and updated pyproject.toml to automatically package A2UI schema definition files into the Python distribution, making them accessible at runtime.
  • Modular Schema Loading: Created an abstract A2uiSchemaLoader with FileSystemLoader and PackageLoader implementations to support flexible loading of schema files from various sources.
  • Comprehensive Testing: Added extensive unit and integration tests for the new schema management and validation components, covering catalog properties, example loading, component pruning, schema resolution, and validation logic for different A2UI versions.
Changelog
  • a2a_agents/python/a2ui_agent/.gitignore
    • Added a new entry to ignore generated JSON asset files.
  • a2a_agents/python/a2ui_agent/pack_specs_hook.py
    • Added a new Hatchling build hook to dynamically load constants and copy A2UI schema definition files into the Python package's assets directory during the build process.
  • a2a_agents/python/a2ui_agent/pyproject.toml
    • Updated build system requirements to include 'jsonschema'.
    • Configured Hatchling to include 'src/a2ui/assets/**' as artifacts for both wheel and sdist builds.
    • Registered 'pack_specs_hook.py' as a custom build hook.
  • a2a_agents/python/a2ui_agent/src/a2ui/inference/init.py
    • Added an empty initialization file to define the 'inference' directory as a Python package.
  • a2a_agents/python/a2ui_agent/src/a2ui/inference/inference_strategy.py
    • Added a new abstract base class InferenceStrategy to define an interface for generating system prompts.
  • a2a_agents/python/a2ui_agent/src/a2ui/inference/schema/init.py
    • Added an empty initialization file to define the 'schema' directory as a Python package.
  • a2a_agents/python/a2ui_agent/src/a2ui/inference/schema/catalog.py
    • Added a new A2uiCatalog dataclass to represent and manage A2UI component catalogs and their associated schemas.
    • Implemented methods for pruning components, rendering schemas for LLM instructions, loading examples, and resolving schema references.
  • a2a_agents/python/a2ui_agent/src/a2ui/inference/schema/constants.py
    • Added a new file to define various constants related to A2UI schema versions and asset paths, including a utility to find the repository root.
  • a2a_agents/python/a2ui_agent/src/a2ui/inference/schema/loader.py
    • Added an abstract A2uiSchemaLoader and concrete FileSystemLoader and PackageLoader implementations for loading JSON schema files.
  • a2a_agents/python/a2ui_agent/src/a2ui/inference/schema/manager.py
    • Added a new A2uiSchemaManager class that implements InferenceStrategy to manage A2UI schemas, determine effective catalogs, and generate system prompts.
    • Refactored schema loading logic to use the new A2uiSchemaLoader implementations and handle fallback mechanisms.
  • a2a_agents/python/a2ui_agent/src/a2ui/inference/schema/validator.py
    • Added a new A2uiValidator class to validate A2UI messages against their respective JSON schemas, supporting both v0.8 and v0.9+ versions.
    • Included helper functions for injecting properties and wrapping schemas for validation.
  • a2a_agents/python/a2ui_agent/src/a2ui/inference/template/manager.py
    • Added a new A2uiTemplateManager class that implements InferenceStrategy, with a placeholder for future implementation.
  • a2a_agents/python/a2ui_agent/tests/inference/test_catalog.py
    • Added new unit tests for the A2uiCatalog class, covering catalog ID, example loading, component pruning, and LLM instruction rendering.
  • a2a_agents/python/a2ui_agent/tests/inference/test_resolve_catalog_schema.py
    • Added new unit tests for the A2uiCatalog.resolve_schema static method, verifying correct resolution of schema references.
  • a2a_agents/python/a2ui_agent/tests/inference/test_schema_manager.py
    • Added new unit tests for the A2uiSchemaManager class, covering initialization, schema loading fallbacks, custom catalogs, and system prompt generation.
  • a2a_agents/python/a2ui_agent/tests/inference/test_validator.py
    • Added new unit tests for the A2uiValidator class, covering validation for A2UI schema versions 0.8 and 0.9+, including custom components and various validation scenarios.
  • a2a_agents/python/a2ui_agent/tests/integration/verify_load_real.py
    • Added a new integration test to verify the successful loading and validation of real A2UI messages using the new schema manager and validator for both v0.8 and v0.9.
  • a2a_agents/python/a2ui_agent/uv.lock
    • Updated dependency lock file to reflect changes in exceptiongroup, google-adk, google-genai, packaging, pycparser, and sqlalchemy versions.
Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/python_a2ui_agent_build_and_test.yml

Copy link
Contributor

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

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 schema bundling and validation capabilities, which is a significant feature enhancement. The changes include a new build hook for packaging schema files, a robust A2uiSchemaManager for handling schema loading and bundling, and an A2uiValidator class. The addition of comprehensive unit and integration tests is commendable and ensures the reliability of the new functionality. I've identified a critical issue related to a missing import that would lead to a runtime error, a high-severity issue concerning error silencing that could complicate debugging, and a couple of medium-severity suggestions for code cleanup and correctness. Overall, this is a well-structured contribution.

@nan-yu nan-yu force-pushed the a2ui-validator branch 5 times, most recently from 283be8d to c42f84f Compare January 28, 2026 18:36
@nan-yu nan-yu force-pushed the a2ui-validator branch 2 times, most recently from 7464284 to 8f7adb5 Compare February 11, 2026 22:15
@nan-yu nan-yu changed the title feat: Introduce schema bundling in A2uiSchemaManager and add a validator feat: Add a A2uiValidator to validate loaded examples Feb 11, 2026
- Add a base InferenceStrategy class
- Add PackSpecsBuildHook to copy JSON schemas into the package during
  build time.
- Update pyproject.toml to include assets and configure the build hook.
- Implement A2uiSchemaManager for robust schema loading, pruning, and
  prompt generation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants