This repository contains a full-stack weather assistant built around Microsoft Agents and AG-UI streaming:
- A .NET 10 API that hosts a chat agent and exposes it over an AG-UI endpoint.
- A Next.js 16 web UI that streams assistant output and renders tool results as structured weather cards.
The purpose of this codebase is to serve as an "ideal target state" reference implementation for autonomous coding agent experiments in Agents.Code.
weather/api: .NET solution with API host and console client.weather/ui: Next.js frontend with AG-UI event translation and custom rendering components.weather/docker-compose.development.yaml: local multi-container orchestration for API + UI.
At runtime, chat requests move through four stages:
- The browser submits a message to
POST /api/chatin the Next.js app. - The Next.js route converts UI messages to AG-UI request format and forwards them to
POST /chaton the API. - The .NET agent streams AG-UI events while producing text and invoking tools.
- The Next.js route maps incoming AG-UI events back into AI SDK UI stream events, which are rendered incrementally in the chat interface.
When the agent calls weather tooling, structured tool output is passed through the stream and rendered as componentized weather cards and 7-day forecast blocks.
Microsoft.Agents.AIMicrosoft.Agents.AI.AGUIMicrosoft.Agents.AI.Hosting.AGUI.AspNetCoreOllamaSharp
The frontend is an App Router Next.js app that combines AI SDK chat state with AG-UI event translation.
- Uses
useChat<ChatMessage>from@ai-sdk/react. - Renders each message part by type:
- Text parts -> animated
MessageResponse. - Tool part
tool-GetWeatherForecast->WeatherRendererwith structured output.
- Text parts -> animated
src/app/api/chat/route.ts is the protocol bridge between AI SDK UI streams and AG-UI SSE.
Main responsibilities:
- Validate inbound POST body with Zod (
schema.ts). - Convert UI message model to AG-UI
RunAgentInputpayload. - Forward request to backend
${BACKEND_URL}/chatwithAccept: text/event-stream. - Parse SSE data lines into AG-UI events.
- Map AG-UI event types into AI SDK writer events.
Event mapping implemented:
RUN_STARTED->startRUN_FINISHED->finishTOOL_CALL_START->tool-input-startTOOL_CALL_ARGS->tool-input-deltaTOOL_CALL_RESULT->tool-output-availableTEXT_MESSAGE_START->text-startTEXT_MESSAGE_CONTENT->text-deltaTEXT_MESSAGE_END->text-endRUN_ERROR->error
Weather rendering is schema-driven using @json-render.
Core pieces:
src/lib/weather-catalog.ts- Defines typed component catalog and prop schemas.
src/components/weather/registry.tsx- Binds catalog components to concrete React implementations.
src/lib/weather-spec.ts- Converts
WeatherResultinto JSON spec tree (Container->WeatherCard+ForecastGrid-> multipleForecastDay).
- Converts
src/components/weather/weather-renderer.tsx- Creates spec and renders through
JSONUIProvider+Renderer.
- Creates spec and renders through
src/components/weather/weather-components.tsx- Implements presentational cards and condition icons.
This gives clean separation between:
- Data shape from tool output.
- Declarative UI spec generation.
- Actual visual component rendering.
Two protocol boundaries are central:
- UI <-> Next route (
/api/chat)- Validated with Zod (
schema.ts). - Accepts role + text-part messages.
- Validated with Zod (
- Next route <-> API AG-UI endpoint (
/chat)- Uses AG-UI event schema and SSE frames.
- Tool outputs can be structured JSON payloads.
Tool output contract used by UI:
- Weather output shape includes location, current metrics, and forecast array.
- Forecast day values are rendered directly into compact forecast cards.
