Skip to content

feat(agent-sdk): add decision model core types, payload inspector, and single-call backends - #4154

Closed
gspencergoog wants to merge 5 commits into
feat/decision-catalogsfrom
feat/decision-core-backends
Closed

gspencergoog wants to merge 5 commits into
feat/decision-catalogsfrom
feat/decision-core-backends

Conversation

@gspencergoog

@gspencergoog gspencergoog commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds the core data models, payload inspector, catalog graph, template registry, shape-keyed plan cache, and backend adapters for a2ui.inference_formats.experimental.decision in a2ui-agent-sdk. HTTP backends (JevHttpBackend and StepZeroLogprobBackend) depend on httpx through the optional a2ui-agent-sdk[decision] extra so the default SDK install adds no new runtime dependencies.

Reviewer Focus

  • python/a2ui_agent/pyproject.toml and python/a2ui_agent/src/a2ui/inference_formats/experimental/decision/backends.py: check that httpx>=0.27.0 is declared under [project.optional-dependencies] decision (and [dependency-groups] dev for tests), the top-level httpx import is guarded, DeterministicMockBackend works without httpx, and HTTP backend constructors and factories raise ImportError pointing to pip install 'a2ui-agent-sdk[decision]'.
  • python/a2ui_agent/src/a2ui/inference_formats/experimental/decision/models.py: inspect the public dataclasses (DecisionQuestion, DecisionBatch, DecisionAnswer, ActionSpec, Calibration, SynthesisConfig, LayoutPlan, PlannedBlock with its optional id_prefix, SynthesisOutput, DecisionBackendError).
  • python/a2ui_agent/src/a2ui/inference_formats/experimental/decision/backends.py: check DecisionBackend (answer(batch) only), JevHttpBackend (pinned jev-1.14.0 for /v1/systemone and gemini-decision-1 for /v1beta/decisions, 30s HTTP timeout, server-reported last_call_latency_ms), StepZeroLogprobBackend, and calibration_profiles.json.
  • python/a2ui_agent/src/a2ui/inference_formats/experimental/decision/plan_cache.py: review the LRU PlanCache keyed by (surface_id, shape_signature, actions_sig, mutable_paths, exclude, layout_brief) for zero-backend-call repeat renders.
  • python/a2ui_agent/src/a2ui/inference_formats/experimental/decision/payload_inspector.py and semantic_types.py: check JSON Pointer extraction, value-shape classification, sensitive-key detection, collection homogeneity analysis, and grouped-array detection. An array whose elements are small wrapper objects around a nested array of objects (for example menuSections[i].items) is indexed as one pointer per section with groupParent, groupIndex, and groupLabelPointer hints, while flat arrays and rich records that merely contain a sub-array are left alone.
  • python/a2ui_agent/src/a2ui/inference_formats/experimental/decision/template_registry.py: inspect template candidate filtering, pointer binding rules, and synthesized template promotion.

Changes

  • Add core decision types in models.py, including structured ActionSpec declarations, PlanReason and FallbackSource enums, BackendCapabilities, Calibration, and PlannedBlock.id_prefix so several blocks of one kind (grouped collections) get distinct component ids.
  • Add DecisionBackend adapters in backends.py (JevHttpBackend supporting TypeSafe Jev /v1/systemone and the Google Gemini Decisions API /v1beta/decisions, StepZeroLogprobBackend, and DeterministicMockBackend) and ship calibration_profiles.json for jev/jev-1.14.0 and gemini/gemini-decision-1.
  • Declare httpx>=0.27.0 as an optional [decision] extra in python/a2ui_agent/pyproject.toml (plus [dependency-groups] dev), guard the httpx import in backends.py, and check _require_httpx() in HTTP backend constructors and factories.
  • Extend the isolated SDK install check in .github/workflows/python_ci.yml to verify a2ui-agent-sdk does not pull in httpx, DeterministicMockBackend() works without it, and JevHttpBackend(...) raises an ImportError with the install hint.
  • Add plan_cache.py (PlanCache, PlanCacheKey, CachedPlan) to cache synthesized layout plans and component blueprints by payload shape signature.
  • Add payload_inspector.py and semantic_types.py to classify JSON leaf pointers, collection shapes, grouped section arrays, and mutable field candidates without leaking raw user strings. humanize_key keeps acronyms (CPU, URL), and string values carrying an ISO currency suffix or an hours unit classify as currency or duration.
  • Add catalog_graph.py (including declared_functions() for catalog-gated formatting), bindings.py, and template_registry.py to index catalog components, A2UI v1.0 data-path bindings, and registered surface templates.
  • Export public symbols from a2ui.inference_formats.experimental.decision and add unit suites under python/a2ui_agent/tests/decision/, including test_http_backends_require_the_decision_extra.

Impact & Risks

  • Additive module hierarchy under a2ui.inference_formats.experimental.decision in python/a2ui_agent, alongside the other experimental formats (elemental, atom). Existing inference formats (express, direct_json) and the default a2ui-agent-sdk dependency set are unaffected.
  • JevHttpBackend and StepZeroLogprobBackend raise ImportError when httpx is not installed and DecisionBackendError when credentials, endpoints, or local models are missing instead of substituting mock answers.

Testing

  • Run uv run pytest python/a2ui_agent/tests/decision -q to check model invariants, backend adapters, optional httpx gating, calibration scaling, plan cache eviction, payload inspection (flat, nested, and grouped arrays), catalog indexing, and template matching.
  • Run uv run --isolated --no-project --with ./python/a2ui_core --with ./python/a2ui_agent python -c "import importlib.util, a2ui.inference_formats.experimental.decision as d; assert importlib.util.find_spec('httpx') is None; d.DeterministicMockBackend()" to verify the isolated install.
  • Run uv run --all-packages mypy python/a2ui_agent/src and uv run pyink --check python/a2ui_agent.

@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 the a2ui.inference_formats.decision module, providing a catalog-agnostic local decision-model A2UI synthesis framework. It includes various inference backends, data models, a payload inspector, semantic type classifiers, and a template registry, along with comprehensive unit tests. The review feedback highlights several robustness and compatibility improvements: ensuring custom model configurations are preserved for native Jev backends to support custom calibration, validating DecisionQuestion.id earlier in initialization to avoid misleading exceptions, using shutil.which to dynamically resolve the gcloud executable path for cross-platform compatibility, and using substring matching instead of endswith to robustly identify chat completion endpoints with query parameters.

@gspencergoog
gspencergoog force-pushed the feat/decision-core-backends branch from 2a1f897 to 07c5191 Compare November 13, 2026 22:50
@gspencergoog
gspencergoog marked this pull request as ready for review November 16, 2026 21:59
@gspencergoog
gspencergoog added this pull request to stack #4287 November 18, 2026 17:45
github-actions Bot added a commit that referenced this pull request Nov 18, 2026
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

🧹 Docs Site Preview Removed

The preview for PR #4154 has been cleaned up because the pull request is closed.

gspencergoog added a commit that referenced this pull request Nov 18, 2026
…d single-call backends

Squashed from the stacked branch history (backup: refs/backups/pre-squash-20261118/feat/decision-core-backends).

PR: #4154
@gspencergoog
gspencergoog force-pushed the feat/decision-core-backends branch from b483a8b to ae7e1d9 Compare November 18, 2026 17:49
github-actions Bot added a commit that referenced this pull request Nov 18, 2026
gspencergoog added a commit that referenced this pull request Nov 18, 2026
…d single-call backends

Squashed from the stacked branch history (backup: refs/backups/pre-squash-20261118/feat/decision-core-backends).

PR: #4154
@gspencergoog
gspencergoog force-pushed the feat/decision-core-backends branch from ae7e1d9 to be57289 Compare November 18, 2026 20:43
gspencergoog added a commit that referenced this pull request Nov 19, 2026
…d single-call backends

Squashed from the stacked branch history (backup: refs/backups/pre-squash-20261118/feat/decision-core-backends).

PR: #4154
@gspencergoog
gspencergoog force-pushed the feat/decision-core-backends branch from be57289 to 3817090 Compare November 19, 2026 02:23
github-actions Bot added a commit that referenced this pull request Nov 19, 2026
gspencergoog added a commit that referenced this pull request Nov 19, 2026
…d single-call backends

Squashed from the stacked branch history (backup: refs/backups/pre-squash-20261118/feat/decision-core-backends).

PR: #4154
@gspencergoog
gspencergoog force-pushed the feat/decision-core-backends branch from 3817090 to e9f8bae Compare November 19, 2026 04:21
…d single-call backends

Squashed from the stacked branch history (backup: refs/backups/pre-squash-20261118/feat/decision-core-backends).

PR: #4154
Move httpx>=0.27.0 out of a2ui-agent-sdk's unconditional dependencies into [project.optional-dependencies] decision (and [dependency-groups] dev for tests). Guard the httpx import in backends.py and fail with an actionable ImportError when constructing HTTP backends without the extra. Extend the isolated CI check to verify httpx is not installed by default.

Signed-off-by: Greg Spencer <gspencer@google.com>
…spection

Signed-off-by: Greg Spencer <gspencer@google.com>
…eflight, and error redaction

- Ignore RuntimeError when closing stale/foreign-loop httpx clients.

- Cancel sibling step-zero scoring tasks when one question fails.

- Coalesce concurrent ADC token refreshes per event loop.

- Expand URL sanitization regex to all schemes, guard urlsplit ValueError, and sanitize HTTP error details.

- Bound [^}]* prefix in _CODE_SYNTAX_RE to prevent quadratic backtracking.

Signed-off-by: Greg Spencer <gspencer@google.com>
@gspencergoog
gspencergoog force-pushed the feat/decision-core-backends branch from e9f8bae to 4d2c1e6 Compare November 24, 2026 18:01
github-actions Bot added a commit that referenced this pull request Nov 24, 2026
github-actions Bot added a commit that referenced this pull request Nov 24, 2026
@gspencergoog
gspencergoog marked this pull request as draft November 30, 2026 23:51
@gspencergoog

Copy link
Copy Markdown
Collaborator Author

Superseded by #4514 (ported into a2ui-agent-experimental and tools/decision_adapters on top of #4471-#4496 in stack #4501).

🤖 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.

1 participant