Skip to content

feat(inference_format): A2UI Atom Inference Format#2056

Merged
gspencergoog merged 22 commits into
a2ui-project:mainfrom
gspencergoog:atom_format
Jul 24, 2026
Merged

feat(inference_format): A2UI Atom Inference Format#2056
gspencergoog merged 22 commits into
a2ui-project:mainfrom
gspencergoog:atom_format

Conversation

@gspencergoog

@gspencergoog gspencergoog commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Overview

This PR introduces the Atom Inference Format for A2UI—a compact, Lisp-inspired symbolic S-expression representation for generating A2UI v1.0 surface declarations—along with the complete 52-run iterative optimization suite and framework.

The Atom format eliminates verbose node identifiers, explicit JSON schema scaffolding, and line-by-line variable declarations (var = Component(...)), compiling directly into valid A2UI v1.0 JSON payloads via a catalog-agnostic compiler (AtomCompiler).


Format Example: Standard A2UI v1.0 JSON vs A2UI Atom

Standard A2UI v1.0 JSON

{
  "version": "v1.0",
  "createSurface": {
    "surfaceId": "main",
    "catalogId": "basic",
    "components": [
      {
        "id": "root",
        "component": "Card",
        "child": "col_1"
      },
      {
        "id": "col_1",
        "component": "Column",
        "children": ["title_1", "desc_1", "btn_1"]
      },
      {
        "id": "title_1",
        "component": "Text",
        "text": "Order Confirmed!",
        "variant": "h2"
      },
      {
        "id": "desc_1",
        "component": "Text",
        "text": "Your package #12345 will arrive tomorrow."
      },
      {
        "id": "btn_1",
        "component": "Button",
        "label": "Track Order",
        "onClick": {
          "name": "trackPackage",
          "context": {
            "orderId": "12345"
          }
        }
      }
    ]
  }
}

Equivalent A2UI Atom S-Expression

<a2ui>
(Card
  (Column
    (Text "Order Confirmed!" :variant "h2")
    "Your package #12345 will arrive tomorrow."
    (Button "Track Order" :onClick (Event "trackPackage" :orderId "12345"))))
</a2ui>

Benchmark Results & Key Metrics (Atom vs Raw JSON & Express)

Evaluated across representative UI dataset prompts on google/gemini-3.5-flash:

Metric Raw A2UI JSON (transport) Express Format (express) Atom Format (Run 52 Milestone) Atom Gain vs Raw JSON Atom Gain vs Express
Algorithmic Schema Accuracy 100.0% 100.0% 100.0% 0.0% 0.0%
Model-Graded Quality Score 100.0% 100.0% 100.0% 0.0% 0.0%
Code Output Tokens (Median) 882 tok 310 tok 282 tok -68.0% 🚀 -9.0%
Input System Prompt & Catalog Tokens 10,482 tok 5,936 tok 4,452 tok -57.5% 🚀 -25.0%
Reasoning Tokens (Median) 2,929 tok 2,235 tok 3,890 tok +32.8% +74.0% 😢
Composite Score ($S_{\text{opt}}$) +0.570 +0.570 +0.661 +0.091 Gain +0.091 Gain

Highlights of Optimizations Included

Across 52 automated serial optimization runs:

  1. Dynamic Positional Child Resolution (Run 43): Automatically unwraps single-child and multi-child containment slots in AtomCompiler._compile_component.
  2. Inline String Child Auto-Wrapping (Run 46): Whitespace-stripping and text component auto-wrapping for primitive string children inside list item containers (_auto_wrap_text_child).
  3. Dynamic Event Action Alias Resolution (Run 47): Handled explicit :context S-expression maps and parameterless event context maps (context: {} omission, Run 33).
  4. AST Container Slot Property Resolution (Run 35): Accelerated non-reasoning emission throughput by -22.2% (5.83s vs 7.50s).
  5. System Prompt & Rule Streamlining (Run 40): Reduced prompt overhead while maintaining 100% catalog agnosticism.

Testing & Verification

  • Pytest Conformance Suite: 772 passed (100% pass rate).
  • Catalog Agnosticism Verification: test_fuzzed_synthetic_catalog_agnosticism passed (100% compliant).
  • History Archiving: All 52 run artifact directories (patch.diff, report.md, run_meta.json, results.json) archived under eval/iterative/history/ and indexed in history_summary.md.

gemini-code-assist[bot]

This comment was marked as resolved.

@gspencergoog gspencergoog changed the title [Draft] feat(inference_format): A2UI Atom Inference Format Optimization & 52-Run Iteration Benchmark [Draft] feat(inference_format): A2UI Atom Inference Format Optimization Jul 21, 2026
@gspencergoog gspencergoog changed the title [Draft] feat(inference_format): A2UI Atom Inference Format Optimization [Draft] feat(inference_format): A2UI Atom Inference Format Jul 21, 2026
…ormat

Add the experimental A2UI Atom inference format, providing an S-expression (Lisp-style parenthesized AST) model-optimized format for declarative UI generation.

Key highlights:
- Implement AtomCompiler, AtomDecompiler, AtomParser, AtomPromptGenerator, and AtomFormat under a2ui.inference_formats.experimental.atom.
- Parent container pre-emission enabling top-down layout streaming.
- Positional child unwrapping and catalog-agnostic relative path resolution.
- Compact rule prompts with <a2ui> and </a2ui> sentinel tags.
- Achieves -68.0% non-reasoning token reduction vs raw A2UI JSON and -52.9% TTFC emission latency reduction vs Express.
- Complete proposal technical specification (specification/proposals/atom/a2ui_atom.md) and examples.
- Comprehensive test coverage (test_atom_format.py, test_prompt_examples.py, test_specification_roundtrip.py) with 773 passing unit tests.
- 52 automated optimization runs archived in eval/iterative/history/ with metadata-based evaluation scoring.
gspencergoog and others added 15 commits July 21, 2026 17:04
…lities

- Split monolithic optimize_format.py into dedicated submodules under eval/iterative/utils/ (runner, reporter, archiver, format_tools).
- Add single-command CLI utilities: --compile, --parse, --decompile, and --archive.
- Add Quick-Command Cheatsheet and anti-pattern guardrails to agent_instructions.md.
- Document design architecture in eval/iterative/PLAN_ITERATION_IMPROVEMENTS.md.
- Add unit tests in eval/tests/test_utils.py.
…% coverage

- Add test cases for Atom format prompt generator, catalog wrapper, parser, and compiler edge cases.
- Add test cases for Elemental format compiler, decompiler, expression parser, and prompt generator.
- Add test cases for Express format compiler, decompiler, schema helper, and prompt generator.
- Add test cases for Transport format parser methods and complete tag verification.
- Achieve >= 90% code coverage across all modules under a2ui.inference_formats.
…transport formats

- Replace loose assertIn assertions with exact equality assertions for elemental actions.
- Replace tautological streaming chunk assertions with exact ResponsePart verification for transport format.
- Add negative key assertions for express _set_nested_path edge cases.
…chema wrapper

- Remove hardcoded component list fallbacks in CatalogSchemaHelperWrapper to enforce explicit catalog configuration.
- Restrict exception handling in CatalogSchemaHelperWrapper.__init__ to avoid masking catalog initialization errors.
- Update unit tests to reflect explicit catalog requirement.
…n parser and decompiler

- Use json.loads in SExprParser._parse_atom to safely unescape Unicode and emoji string literals without UTF-8 byte corruption.
- Implement strict positional token scanner in SExprParser._tokenize for gap validation and unclosed string auto-healing.
- Flatten child node resolution in AtomDecompiler for linear runtime root identification.
- Add unit tests for SExprParser Unicode and multiline string parsing.
…odule and update eval strategy docstrings

- Extract CatalogSchemaHelper into shared a2ui.schema.schema_helper module.
- Update AtomFormat prompt generator and compiler schema wrappers to import CatalogSchemaHelper from a2ui.schema.
- Document atom strategy in eval _get_strategy docstring.
…eservation and hyphenated paths

- Preserve exact string values in _clean_data_value to prevent bracket stripping and integer type coercion of string data.
- Update KEYWORD_VAL, KEYWORD, and PATH regexes to support hyphens in path names and keywords.
- Cache AtomFormat._parser instance.
…a.__init__ to prevent build hook failure

- Remove eager schema_helper import from a2ui.schema.__init__ to prevent hatchling build hook ModuleNotFoundError during isolated package build setup.
- Add safe Catalog import fallback in schema_helper.
…ict mypy compliance

- Add explicit type annotations for instance dictionaries in CatalogSchemaHelper.
- Annotate _find_enum helper function and return types to satisfy mypy strict type checks.
…cross Atom modules

- Add dedicated README.md for Atom S-expression inference format package.
- Document Inference Formats section in main python SDK README.md.
- Add comprehensive Google-style docstrings across AtomFormat, AtomParser, AtomCompiler, AtomDecompiler, and AtomPromptGenerator.
@gspencergoog
gspencergoog marked this pull request as ready for review July 21, 2026 21:29
@gspencergoog gspencergoog changed the title [Draft] feat(inference_format): A2UI Atom Inference Format feat(inference_format): A2UI Atom Inference Format Jul 21, 2026
gspencergoog and others added 5 commits July 21, 2026 21:42
…m format

- Document comment notation, attribute assignment shorthand, primitive auto-wrapping, and map/list initializers in (data ...).
- Detail supported validation, logic, and formatting functions.
- Update action event and RPC function call syntax.
- Align compilation example and JSON payload with standard basic catalog schema output.
(ListComponent :items $/items :template (template item (ChildComponent :title $/item/name))))
</a2ui>

11. Strict Catalog Adherence & Conciseness:

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.

Wow, I'm shocked how relatively simple the prompt is to get quite good inference performance!!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, me too, but it does require a lot of reasoning: that's the downfall of this one, I think.

@gspencergoog
gspencergoog enabled auto-merge (squash) July 24, 2026 16:48
@gspencergoog
gspencergoog merged commit e8def04 into a2ui-project:main Jul 24, 2026
25 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in A2UI Jul 24, 2026
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