forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_a2ui_utils.py
More file actions
24 lines (18 loc) · 966 Bytes
/
Copy path_a2ui_utils.py
File metadata and controls
24 lines (18 loc) · 966 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""Shared validators for A2UI dynamic-schema agents.
The dynamic-schema flow has a secondary LLM produce a flat array of
components. The renderer rejects entries missing `id` or `component`
("Cannot create component root without a type" infinite-loop), so every
agent that builds an A2UI surface dynamically needs to sanitize the
LLM's output before forwarding it. These helpers are factored out so
each agent's tool body stays focused on the demo-specific bits
(catalog id, system prompt, data shape).
"""
from __future__ import annotations
def sanitize_a2ui_components(raw: list) -> list[dict]:
"""Drop entries that aren't dicts or are missing `id`/`component`."""
return [
c for c in raw if isinstance(c, dict) and c.get("id") and c.get("component")
]
def has_root_component(components: list[dict]) -> bool:
"""True iff `components` contains an entry with `id == "root"`."""
return any(c.get("id") == "root" for c in components)