Repository navigation
[Blazor] Add agentic generative UI state rendering - #68333
Conversation
9c64244 to
2d7502c
Compare
|
/azp run aspnetcore-ci |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
/azp run aspnetcore-components-e2e |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
/azp run aspnetcore-ci |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
2d7502c to
982e84e
Compare
982e84e to
8ccd67b
Compare
There was a problem hiding this comment.
Pull request overview
This PR extends Microsoft.AspNetCore.Components.AI with (1) protocol-neutral typed, observable agent state (UIAgent<TState> + AgentState<T>) via a new StateMapper extension point, and (2) a reusable “activity/progress” block mapping abstraction (ActivityContentBlock + ActivityHandler<TBlock>). It also adds an “Agentic Generative UI” dojo scenario (snapshot + JSON Patch deltas over real HTTP/SSE) and corresponding runtime + E2E coverage.
Changes:
- Add typed observable state to
UIAgentviaAgentState<T>,UIAgent<TState>, andStateMapperContextcontent filtering. - Add reusable activity snapshot/delta handling via
ActivityHandler<TBlock>andActivityContentBlock. - Add Agentic Generative UI dojo scenario + deterministic recordings + E2E test validating snapshot + delta progression over HTTP/SSE.
Show a summary per file
| File | Description |
|---|---|
| src/Components/AI/testassets/DojoClient/Program.cs | Registers keyed chat client for the new agentic scenario endpoint. |
| src/Components/AI/testassets/DojoClient/DojoScenarios.cs | Adds AgenticGenerativeUIEndpoint constant. |
| src/Components/AI/testassets/DojoClient/Components/Scenarios/AgenticGenerativeUI/PlanState.cs | Adds plan DTOs used by the scenario’s typed state. |
| src/Components/AI/testassets/DojoClient/Components/Scenarios/AgenticGenerativeUI/PlanProgressCard.razor.css | Styles the plan progress card UI. |
| src/Components/AI/testassets/DojoClient/Components/Scenarios/AgenticGenerativeUI/PlanProgressCard.razor | Renders plan progress and per-step state based on typed agent state. |
| src/Components/AI/testassets/DojoClient/Components/Scenarios/AgenticGenerativeUI/AgenticGenerativeUIScenario.razor.css | Scenario-specific layout and activity status styling. |
| src/Components/AI/testassets/DojoClient/Components/Scenarios/AgenticGenerativeUI/AgenticGenerativeUIScenario.razor | Implements the scenario, state mapping (snapshot/delta), and rerender subscription. |
| src/Components/AI/testassets/DojoClient/Components/Pages/Home.razor | Adds navigation link to the new scenario. |
| src/Components/AI/testassets/DojoClient/Components/_Imports.razor | Adds usings for AG-UI abstractions + scenario namespace. |
| src/Components/AI/testassets/DojoClient.E2E.Tests/Tests/AgenticGenerativeUIScenarioTests.cs | Adds dual-host Playwright test validating snapshot + 5 deltas + streaming summary. |
| src/Components/AI/testassets/DojoClient.E2E.Tests/ServiceOverrides/DojoModelOverrides.cs | Adds API-only recorded model override for the new scenario. |
| src/Components/AI/testassets/DojoClient.E2E.Tests/Baselines/AgenticGenerativeUI.recording.json | Adds deterministic recording for tool calls + checkpointed frames. |
| src/Components/AI/testassets/AGUIDojoApi/ScriptedChatClient.cs | Extends scripted model behavior to drive plan creation/step progression and final summary. |
| src/Components/AI/testassets/AGUIDojoApi/Program.cs | Maps the new /agentic_generative_ui dojo endpoint with tools + stream mapping. |
| src/Components/AI/testassets/AGUIDojoApi/ChatClientAgentFactory.cs | Adds agentic system prompt, tools, and AG-UI stream options mapping results to snapshot/delta. |
| src/Components/AI/testassets/AGUIDojoApi/AgenticGenerativeUI/PlanStepStatus.cs | Adds status enum serialized as pending/completed. |
| src/Components/AI/testassets/AGUIDojoApi/AgenticGenerativeUI/PlanStep.cs | Adds plan step DTO for API-side snapshot. |
| src/Components/AI/testassets/AGUIDojoApi/AgenticGenerativeUI/Plan.cs | Adds plan DTO containing steps. |
| src/Components/AI/testassets/AGUIDojoApi/AgenticGenerativeUI/JsonPatchOperation.cs | Adds JSON Patch operation DTO used for deltas. |
| src/Components/AI/testassets/AGUIDojoApi/AgenticGenerativeUI/AgenticPlanningTools.cs | Implements create_plan snapshot and update_plan_step delta tool results. |
| src/Components/AI/test/Pipeline/StateMapperTests.cs | Adds tests for state extraction, filtering, and raw update handling. |
| src/Components/AI/test/Pipeline/ActivityHandlerTests.cs | Adds tests for snapshot/delta/update/completion activity lifecycle behavior. |
| src/Components/AI/test/Engine/AgentStateTests.cs | Adds tests for AgentState initialization + notifications + unsubscribe during callback. |
| src/Components/AI/src/PublicAPI.Unshipped.txt | Declares the new public API surface area. |
| src/Components/AI/src/Pipeline/UIAgentOptions.cs | Adds StateMapper option for state mapping/filtering. |
| src/Components/AI/src/Pipeline/StateMapperContext.cs | Introduces context for mapping state and filtering handled AIContent. |
| src/Components/AI/src/Pipeline/ActivityHandler.cs | Adds generic base handler for mapping activity snapshots/deltas into mutable blocks. |
| src/Components/AI/src/Engine/UIAgentOfT.cs | Adds UIAgent<TState> with typed observable State and mapper integration. |
| src/Components/AI/src/Engine/UIAgent.cs | Integrates state mapping/filtering into streaming update processing. |
| src/Components/AI/src/Engine/AgentState.cs | Adds observable typed state container with change subscriptions. |
| src/Components/AI/src/Blocks/ActivityContentBlock.cs | Adds public activity/progress block surface (type + payload). |
Review details
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
- Files reviewed: 31/31 changed files
- Comments generated: 3
- Review effort level: Lite
8ccd67b to
e5891af
Compare
e5891af to
fbf110e
Compare
fbf110e to
95fc816
Compare
Rationale: let provider-neutral Components.AI applications react to structured model state snapshots and deltas without coupling the runtime to AG-UI or rendering protocol events as chat content. Implementation: add UIAgent<TState>, observable AgentState<T>, state-mapper filtering in the existing streaming loop, and reusable activity blocks whose payload updates notify existing renderers. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 323b0ef8-7905-4041-8388-a08586c0bd34
Rationale: demonstrate canonical Agentic Generative UI across the real DojoClient to AGUIDojoApi HTTP/SSE boundary by rendering structured plan state independently of conversational text. Implementation: add the /agentic_generative_ui endpoint and keyed AGUIChatClient, map create_plan results to snapshots and update_plan_step results to JSON Patch deltas, and render a progress board that reacts to each typed state update. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 323b0ef8-7905-4041-8388-a08586c0bd34
Rationale: lock down typed state replacement, content filtering, activity notifications, and the canonical Agentic Generative UI progression without replacing DojoClient's real AG-UI transport. Implementation: add focused runtime tests for observable state, state mapping, and activity deltas plus dual-host browser assertions that gate every plan step and final response independently. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 323b0ef8-7905-4041-8388-a08586c0bd34
Rationale: keep deterministic Agentic Generative UI browser coverage independent of live model credentials while exercising the real AG-UI HTTP/SSE boundary. Implementation: record the create_plan snapshot, five sequential update_plan_step deltas, accumulated tool results, and independently gated final summary. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 323b0ef8-7905-4041-8388-a08586c0bd34
Co-authored-by: Copilot <[email protected]>
Keep fully handled updates in assistant response aggregation while continuing to suppress them from block rendering. Add regression coverage for a metadata-bearing state update followed by an unidentified text continuation. Co-authored-by: Copilot <[email protected]> Copilot-Session: baddc46b-b86e-4be5-add2-1a7b3cac8195
913754f to
092e9dd
Compare
Co-authored-by: Copilot <[email protected]> Copilot-Session: baddc46b-b86e-4be5-add2-1a7b3cac8195
|
Dojo scenario is missing suggestions (e.g. "simple plan"/"complex plan") with proper customization, it can be a part of #68372, #68441, #68436. The initial (1st render) suggestions got added in 00e1554. Also collapsible entries with status (create_plan, update_plan_step etc) are missing. Should be resolved in #68416. dojo-generative-UI.mp4 |
30207dc to
3592d4d
Compare
Overview
This is position 7 in the native Components.AI stack tracked by #68340 and depends on #68330. Relative only to parent
javiercn-components-ai-06-tool-generative-ui(cf1d845394a3dc815941446e78c79dfc49ce4a89), the stack-relative diff adds protocol-neutral typed observable state to Components.AI and uses it to implement the canonical Agentic Generative UI plan scenario; AG-UI types remain confined to test assets, and the browser still reaches a separate API host throughAGUI.Client0.0.5 over HTTP/SSE. Handwritten runtime/browser coverage and the deterministic model recording remain separate from product and dojo commits.Design
The product contract adds a typed agent whose state is replaced atomically and observed independently of rendered chat blocks:
UIAgentOptions.StateMapperis the extension point, whileStateMapperContext.Update,UnhandledContents,MarkHandled, andSetStateseparate two concerns: extracting structured state and deciding whichAIContentshould continue into block rendering. This boundary was chosen instead of adding AG-UI event types to the shipping assembly; anyIChatClientprovider can map its own raw representation or content shape.Progress-like content is the other public equivalence class.
ActivityContentBlockcarries an application-definedActivityTypeandJsonElementpayload, while one generic handler owns the common snapshot/update/completion lifecycle:Snapshot creation, in-place delta notification, completion, and unrelated-activity pass-through are implemented once; concrete activity protocols vary only in
TryCreateBlockandTryUpdateBlock.Implementation
The mapper runs at the existing streaming boundary. The filtered update reaches both conversation history and the block pipeline, so handled state content is not sent back to the model on the next turn. Fully filtered state-only updates do not create empty assistant history messages:
The dojo server exposes two tool-result classes through one endpoint:
create_planbecomes a full snapshot, and everyupdate_plan_stepresult becomes an RFC 6902 delta. The five step updates are equivalent instances of the same path rather than five bespoke behaviors.The Blazor scenario maps the two event classes into one
PlanState. Snapshots replace the whole plan; deltas clone the current plan before applying validreplaceoperations, so assigning the returned instance reliably notifies observers and rerenders the board.The E2E model replacement is applied only to
AGUIDojoApi;DojoClientreceives only the API URL and continues to construct its keyedAGUIChatClient. This proves the transport instead of short-circuiting it in-process.Outcome
The 16 runtime tests are compressed into three behavior classes: observable state semantics (5), state extraction/filtering including mixed and raw updates (6), and activity snapshot/delta/completion/isolation (5). The single browser test loops over all five equivalent deltas, independently gates the final summary, and checks progress, current/completed styling, running/done state, and input enablement.
Review guidance: Read
UIAgent.ApplyStateMapper,StateMapperContextfiltering,UIAgent<TState>assignment,ApplyPlanDelta, and the API-only replay registration closely. The plan DTOs, repeated step markup, CSS, and generated recording are representative data/presentation and can be skimmed.Acceptance criteria:
create_plansnapshot renders one five-step board at0/5, with the first pending step current.update_plan_stepdelta completes exactly one additional step and advances progress by 20%, reaching5/5without duplicating the activity.AGUIChatClient→ HTTP/SSE → AGUIDojoApi; only the API model is replayed.DojoClient.E2E.TestsbuildAgenticGenerativeUIScenarioTests