a2ui-project / a2ui-project/a2ui
Modularize SchemaManager class into Catalog-focused components
- 主要語言
- TypeScript
- 星號
- 16.4k
- 分支
- 1.3k
- 平均合併
- 3 天 15 小時
- 30 天內合併 PR
- 134
描述
## Overview
Currently, `A2uiSchemaManager` in `agent_sdks/python/a2ui_agent/src/a2ui/schema/manager.py` combines multiple responsibilities:
1. Loading and holding raw schema dictionaries and component catalog files.
2. Negotiating client capabilities (`supportedCatalogIds` and `inlineCatalogs`).
3. Performing component, message, and schema reachability pruning.
4. Loading and validating catalog example payloads.
5. Assembling and rendering system prompt instructions for LLMs.
We want to move away from a stateful schema manager as the primary representation of catalogs in A2UI Python SDKs, favoring the pure `Catalog` data object in `agent_sdks/python/a2ui_core/src/a2ui/core/catalog/catalog.py`.
## Proposed Component Breakdown
To improve modularity and testability, `A2uiSchemaManager` will be split into single-responsibility classes:
* **`CatalogRepository`**: Manages specification-version schemas (`server_to_client.json`, `common_types.json`) and registered pristine `Catalog` instances.
* **`CatalogResolver`**: Negotiates client capabilities (`a2uiClientCapabilities`) to select matching discrete `Catalog` instances (well-known or inline) according to protocol specification.
* **`CatalogTransformer`**: Abstract interface and pipeline implementations (e.g. `PruningTransformer`, `ComponentAliasTransformer`) performing bidirectional schema and message transformations.
* **`ExampleManager`**: Loads example JSON files and validates them against catalog schemas.
* **`PromptGenerator`**: Formats `Catalog` data objects, workflow rules, and examples into system instruction text. Supports optional schema relaxation (`relax_strict_validation=True`) for LLM prompt rendering without mutating base catalog objects.
* **`A2uiValidator`**: Handles payload and example validation with initializer-level strictness settings (`strict=True\|False`).
* **`A2uiSchemaManager` (Backward Compatibility Facade)**: Retains existing API signatures for existing callers and tests by delegating internally to the new components.
## Sample Integration (`samples/agent/adk/restaurant_finder`)
In sample agents like `samples/agent/adk/restaurant_finder/agent.py`, initializing catalogs and generating prompts becomes clear and explicit:
```python
# 1. Initialize repository and helpers
repository = CatalogRepository(
version=version,
catalogs=[BasicCatalog.get_config(version=version)],
)
example_manager = ExampleManager({repository.default_catalog().catalog_id: f"examples/{version}"})
prompt_generator = PromptGenerator(relax_strict_validation=True)
# 2. Get target Catalog data object
catalog = repository.default_catalog()
# 3. Generate system prompt directly from Catalog data object
instruction = prompt_generator.generate_prompt(
catalog=catalog,
role_description=ROLE_DESCRIPTION,
ui_description=UI_DESCRIPTION,
examples=example_manager.load_examples(catalog, validate=True),
include_schema=True,
)
```
貢獻指南
研究方向
主要檔案是 agent_sdks/python/a2ui_agent/src/a2ui/schema/manager.py。檢視目前的 A2uiSchemaManager 類別,以及 agent_sdks/python/a2ui_core/src/a2ui/core/catalog/catalog.py 中的 Catalog 資料物件。了解提議的元件拆分方式,以及它們如何互動。samples/agent/adk/restaurant_finder/agent.py 中的範例整合展示了預期的用法。先檢查現有的測試,以了解目前的行為。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- backend-api-design
- Issue 類型
- 重構
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 冷清
- 描述清晰度
- 描述清楚
- 新手友好度
- 35/100