Skip to main content

Module 29: Introduction to UI Integration

Theory​

Why UI Integration Matters​

While agents can be run from the command line or via an API, their full potential is unlocked when they are integrated into a user interface. A UI makes your agent accessible to non-technical users and enables rich, interactive experiences.

The UI Integration Landscape​

The ADK is flexible and supports several approaches for UI integration, each suited for different use cases:

ApproachBest ForKey Features
AG-UI ProtocolModern web apps (React/Next.js)Pre-built components, official support
Native ADK APICustom frameworks (Vue, Angular)Full control, no dependencies
Direct PythonData apps (Streamlit)In-process, no HTTP overhead
Messaging PlatformsTeam bots (Slack, Teams)Native platform UX
Event-DrivenHigh-scale, async workflowsDecoupled, scalable (Pub/Sub)

Understanding the AG-UI Protocol​

AG-UI (Agent-Generative UI) is an open protocol for agent-user interaction, developed through an official partnership between the Google ADK and CopilotKit teams. It provides a standardized, event-based way for AI agents to communicate with web UIs.

The Stack:

+---------------------------------+
| Frontend (React/Next.js) |
| - @copilotkit/react-core (SDK) |
| - <CopilotChat> (UI Component) |
+---------------------------------+
| (WebSocket/SSE)
+---------------------------------+
| Backend (Python/FastAPI) |
| - ag_ui_adk (Protocol Adapter) |
| - Your ADK Agent |
+---------------------------------+

By using the AG-UI protocol and the associated libraries, you can quickly build a production-ready chat interface with minimal front-end code, as the pre-built components handle the complexities of state management and streaming.

Key Takeaways​

  • Integrating an agent with a UI makes it accessible to a wider audience and enables richer interactions.
  • The ADK supports multiple UI integration strategies, including the official AG-UI Protocol, the native ADK API, direct Python integration, and messaging platforms.
  • The AG-UI Protocol, developed in partnership with CopilotKit, is the recommended approach for modern web applications, providing pre-built components for frameworks like React and Next.js.
  • For other frameworks or custom needs, you can use the ADK's native API server (adk api_server) and its /run_sse endpoint to build your own client.
  • Benefits of Higher-Level Frameworks: For complex, production-ready applications, higher-level frameworks like the AG-UI Protocol and CopilotKit offer significant benefits over the native ADK API. They reduce boilerplate code by providing pre-built UI components that automatically handle stream parsing, state management, and tool interactions. They also offer more advanced tool integration and are the officially supported, standardized path for building modern web UIs with the ADK.
  • Session ID Persistence: Generating a new sessionId on every page load, as done in the simple lab, would cause a loss of conversational memory in a real application. The agent would forget the message history and any state associated with the previous session. The correct solution is to persist the sessionId on the client-side using localStorage or a cookie, ensuring that the same session is used across page reloads.
  • Advantages of SSE for Chat: Server-Sent Events (SSE) are highly advantageous for chat applications because they enable low-latency streaming. The text generated by the LLM can be sent to the client in real-time as it's generated, providing a much more responsive user experience compared to a traditional request-response model where the user would have to wait for the entire response to be completed. SSE is also more efficient for this one-way streaming scenario than bidirectional protocols like WebSockets.