Skip to content

Commit 84bd1d0

Browse files
authored
feat(NGUI-446): added list of all available fields for table and set-of-cards into agent output (#232)
1 parent dc2e187 commit 84bd1d0

File tree

20 files changed

+1399
-81
lines changed

20 files changed

+1399
-81
lines changed

docs/guide/architecture.md

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
# Architecture
22

3-
This guide shows how to use *NextGen UI Agent* in your application.
3+
This guide shows how to use *NextGen UI Agent* in your AI application, how it plays with other building blocks of it.
4+
5+
## What is *UI Agent*
46

57
In short, *UI Agent* takes `User Prompt` and [`Structured Data`](input_data/index.md) relevant to this prompt as an input,
68
and generates UI component to visualize that piece of data to the user. We call it [`Data UI Block`](data_ui_blocks/index.md).
7-
[AI (LLM) is used](llm.md) in this step to understand the `User Prompt` and [input data structure](./input_data/structure.md),
8-
and select the best dynamic UI component and displayed data values.
99

10-
Stricter configuration can be used when tighter control of UI components applied to the input data is necessary, for
10+
UI Agent uses [AI (LLM)](llm.md) in this step to understand the `User Prompt` and [input data structure](./input_data/structure.md),
11+
and select the best dynamic UI component and displayed data values.
12+
As UI component generation is an AI narrow task, small LLMs (3B, 8B, Mini/Flash/Flash-Lite series) are typically able to provide
13+
good results for this task, which saves LLM price. They also provide better processing time, which is important for good user experience.
14+
We provide [LLM evaluation tool](https://github.com/RedHat-UX/next-gen-ui-agent/tree/main/tests/ai_eval_components) as part of this project,
15+
results from some [eval runs are available](https://github.com/RedHat-UX/next-gen-ui-agent/tree/main/tests/ai_eval_components/results).
16+
We expect to provide small LLMs finetuned for UI generation task in the future.
17+
18+
*UI Agent* can process structured Input Data in different formats. Extensible [input data transformation framework](./input_data/transformation.md)
19+
is used, with OOTB transformers provided for the most common formats like `JSON`, `YAML`, `CSV` and `fixed width columns table`.
20+
21+
Stricter configuration can be defined when tighter control of the UI components applied to the input data is necessary, for
1122
details see [Component Selection and Configuration docs](./data_ui_blocks/index.md#selection-and-configuration-process).
1223

1324
In the future, this agent will also maintain `UI state` and view layouts to keep UI and flows consistent, handle personalized
@@ -16,11 +27,12 @@ values formating, and many other features. Stay tuned ;-)
1627
Example of the generated `Data UI Block`:
1728
![Example of the Data UI Block](../img/data_ui_block_card.png "Example of the Data UI Block")
1829

19-
*UI Agent* also suports [*Hand Build Components*](data_ui_blocks/hand_build_components.md) for pieces of data where UI component exists already, or where
20-
it is needed to provide special visualization or use features on top of AI generated UI components.
30+
*UI Agent* also suports [*Hand Build Components*](data_ui_blocks/hand_build_components.md) for pieces of data where UI component exists
31+
already, or where it is needed to provide special visualization or use features on top of AI generated UI components.
2132

33+
## How to use *UI Agent*
2234

23-
Your application, called *Controlling assistant*, has to provide other building blocks and their orchestration to implement complete solution.
35+
Your AI application, called *Controlling assistant*, has to provide other building blocks and their orchestration to implement complete solution.
2436

2537
Example of the *Controlling assistant* architecture:
2638
![Example of the Controlling assistant architecture](../img/architecture_assistant_flow.jpg "Example of the Controlling assistant architecture")
@@ -29,7 +41,7 @@ Example of the *Controlling assistant* architecture:
2941
It can do it directly, for example using `LLM Tools Calling`/`MCP`, or it can call *Data providing agent* in case
3042
of Multi-Agent architecture. It can even generate that data itself in process of Reasoning or user's intent detection and processing.
3143
*Controlling assistant* can load more pieces of data for one conversation turn, and send them all to the *UI Agent* to generate
32-
more `AI UI Blocks` to be shown to the user in the assistant's GUI.
44+
more `Data UI Blocks` to be shown to the user in the assistant's GUI.
3345

3446
*Controlling assistant* can also generate *Natural language response* based on this data and deliver it to the user through GUI or Voice user interface.
3547
To follow vision of the *NextGen UI*, this natural language response should not repeat visualized data, but rather provide
@@ -43,6 +55,20 @@ Example mockup of the *Controlling assistant* GUI:
4355
They can be rendered using pluggable GUI component system renderers, and integrated into the GUI of the *Controlling assistant*.
4456
We provide renderers for several UI component systems, either Server-Side or Client-Side, see [Binding into UI](renderer/index.md).
4557

46-
*UI Agent* can be integrated into *Controlling Assistant* developed using multiple AI frameworks or AI protocols, see [Binding into AI application](ai_apps_binding/index.md).
58+
Output of the *UI Agent* does not contain the `Data UI Block` rendering only, but also [structured UI component configuration](../spec/output.md).
59+
It can be used to implement advanced UI features, like live data updates from backend, manual selection of visualized table columns etc.
60+
61+
## How to integrate *UI Agent*
62+
63+
*UI Agent* can be integrated into *Controlling Assistant* developed using multiple AI frameworks or AI protocols,
64+
see [Binding into AI application](ai_apps_binding/index.md). You can also refer ["Choose your framework"](../installation.md) guide.
65+
66+
The first approach how to integrate *UI Agent* into the *Controlling assistant* is to use assistant's LLM to choose and execute the
67+
UI Agent. This approach makes sense if you want your assistant to act like `Orchestrator` - to decide about the UI component generation.
68+
For example to select which backend data loaded during the processing needs to be visualized in UI, or whether UI has to be generated at all.
69+
This approach cost you more in terms of the main LLM processing price (tokens) and time, but gives you more flexibility.
4770

48-
You can also refer ["Choose your framework"](../installation.md).
71+
Alternative approach is to invoke *UI Agent* directly as part of your assistant logic, at the specific moment of the processing flow,
72+
after gathering structured backend data for the response.
73+
This approach is a bit more reliable, helps to reduce main LLM processing price (tokens) and time (you can even generate UI in
74+
parallel with *Natural language response* generation), but is a bit less flexible.

docs/guide/configuration.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ The Next Gen UI Agent can be configured in two ways: `programmatically` using Py
1010

1111
[UI Component system](renderer/index.md) for rendering (default: `"json"`)
1212

13+
1314
### `data_transformer` [`str`, optional]
1415

1516
Optional name of the [Input Data Transformer](input_data/transformation.md) used by the UI Agent.
@@ -20,17 +21,27 @@ Can be overriden [per data type](#data_transformer-str-optional_1). Defaults to
2021

2122
Whether to allow unsupported/Tech Preview [Dynamic UI components](data_ui_blocks/dynamic_components.md) to be selected by LLM (default: `False`)
2223

24+
2325
### `component_selection_strategy` [`str`, optional]
2426

2527
Strategy for LLM powered component selection and configuration step:
2628

2729
- `one_llm_call`: Uses single LLM call for component selection and configuration - default
2830
- `two_llm_calls`: Uses two LLM calls - first selects component type, second configures it - *experimental feature!*
2931

32+
3033
### `input_data_json_wrapping` [`bool`, optional]
3134

3235
Whether to perform [automatic `InputData` JSON wrapping](input_data/structure.md#automatic-json-wrapping) if JSON structure is not good for LLM processing (default: `True`)
3336

37+
38+
### `generate_all_fields` [`bool`, optional]
39+
40+
If `True`, the agent will generate all possible view Fields for the UI component into its output configuration `UIBlockComponentMetadata.fields_all`.
41+
It can be used in UI component to give user a chance to manually select/update which fields are shown.
42+
If `False` then all fields aren't generated. Can be overriden for individual `data_types`. (default: `False`)
43+
44+
3445
### `data_types` [`dict[str, AgentConfigDataType]`, optional]
3546

3647
Configurations for [`InputData.type`s](input_data/index.md#inputdata-object-fields), like:
@@ -44,6 +55,13 @@ Key is `InputData.type` to configure, value is configuration object for that dat
4455

4556
Optional name of the [Input Data Transformer](input_data/transformation.md) to be used for this data type instead of [Agent's default one](#data_transformer-str-optional).
4657

58+
#### `generate_all_fields` [`bool`, optional]
59+
60+
If `True`, the agent will generate all possible view Fields for the UI component into its output configuration `UIBlockComponentMetadata.fields_all`.
61+
It can be used in UI component to give user a chance to manually select/update which fields are shown.
62+
If `False` then all fields aren't generated, if not defined then [agent's default setting](#generate_all_fields-bool-optional) is used.
63+
All fields are supported only for `table` and `set-of-cards` components.
64+
4765

4866
#### `components` [`list[AgentConfigComponent]`, optional]
4967

docs/guide/data_ui_blocks/dynamic_components.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ Value can be simple text or number etc. List (array) of values is supported as w
7373

7474
Layout for this set of cards has to be provided by frontend application.
7575

76+
If enabled in the *UI Agent* configuration, [agent's output can contain list of all fields available in the input data](../../spec/output.md), so you can
77+
provide user with the ability to manually select what is shown after this UI component is generated.
78+
7679
### Table
7780

7881
[![Status](https://img.shields.io/badge/Status-Tech%20Preview-orange)](https://github.com/RedHat-UX/next-gen-ui-agent)
@@ -85,3 +88,6 @@ Table is UI block that displays:
8588
* Table with AI selected Columns with AI generated names, and rows of values gathered from agent's input data.
8689

8790
Individual cell value can be simple text or number etc. List (array) of values is supported as well.
91+
92+
If enabled in the *UI Agent* configuration, [agent's output can contain list of all fields available in the input data](../../spec/output.md), so you can
93+
provide user with the ability to manually select which columns are shown after this UI component is generated.

docs/guide/renderer/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ We provide renderers for several UI component systems:
1818
* Client-Side
1919
* [PatternFly NPM](patternfly_npm.md) - produces [PatternFly](https://www.patternfly.org/) React components
2020

21+
22+
Besides rendering itself, output of the *UI Agent* also contain [structured UI component configuration](../../spec/output.md). It can be
23+
used for advanced UI features, like live data updates from backend, manual selection of visualized fields etc.

docs/spec/output.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{%
2+
include-markdown "../../spec/output/README.md"
3+
%}

libs/next_gen_ui_agent/agent.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import Optional
44

55
from next_gen_ui_agent.agent_config import parse_config_yaml
6+
from next_gen_ui_agent.all_fields_collector import generate_all_fields
67
from next_gen_ui_agent.component_selection_llm_onestep import (
78
OnestepLLMCallComponentSelectionStrategy,
89
)
@@ -39,6 +40,7 @@
3940
AgentConfig,
4041
InputData,
4142
InputDataInternal,
43+
UIBlockComponentMetadata,
4244
UIBlockConfiguration,
4345
UIBlockRendering,
4446
UIComponentMetadata,
@@ -227,14 +229,32 @@ def construct_UIBlockConfiguration(
227229
It should be returned from AI framework/protocol binding so *Controlling Assistant* can send it back later when it needs to refresh component for the new data.
228230
"""
229231

232+
block_component_metadata = UIBlockComponentMetadata(
233+
**component_metadata.model_dump(),
234+
)
235+
230236
# put sanitized data paths to the UIBlockConfiguration
231-
if component_metadata.fields:
232-
for field in component_metadata.fields:
237+
if block_component_metadata.fields:
238+
for field in block_component_metadata.fields:
233239
field.data_path = sanitize_data_path(field.data_path) # type: ignore
234240
field.id = generate_field_id(field.data_path)
235241

242+
data_type = input_data.get("type")
243+
generate_for_data_type = (
244+
data_type
245+
and self.config.data_types
246+
and self.config.data_types.get(data_type)
247+
and self.config.data_types.get(data_type).generate_all_fields # type: ignore
248+
)
249+
if (
250+
self.config.generate_all_fields and generate_for_data_type is not False
251+
) or generate_for_data_type is True:
252+
block_component_metadata.fields_all = generate_all_fields(
253+
component_metadata
254+
)
255+
236256
return UIBlockConfiguration(
237-
component_metadata=component_metadata,
257+
component_metadata=block_component_metadata,
238258
data_type=input_data.get("type"),
239259
input_data_transformer_name=component_metadata.input_data_transformer_name,
240260
json_wrapping_field_name=component_metadata.json_wrapping_field_name,

0 commit comments

Comments
 (0)