REST API and Web Launchers
The REST API and Web Launchers module provides the infrastructure for running and exposing AI agents via HTTP-based interfaces. It implements REST API servers, HTTP routing, and web-based launchers that allow users and clients to interact with agents over the network. This includes handling HTTP requests, routing them to appropriate controllers, serving an embedded web UI, and supporting the Agent-To-Agent (A2A) protocol for distributed multi-agent communication.
Core Concepts and Purpose
This module exists to bridge the internal AI agent framework with external clients, providing programmatic and user-friendly access through:
REST APIs: Offering standard HTTP endpoints for managing sessions, invoking agents, handling artifacts, and retrieving debug information.
Web UI Launcher: Serving an embedded web application to enable browser-based interaction with the agents.
Web Server Launcher: Running the underlying HTTP server that hosts REST endpoints and optionally the web UI or A2A interfaces.
API and A2A Sublaunchers: Modular components that extend the web server with specific functionalities (REST API, A2A server, Web UI).
It solves the problem of exposing agent capabilities in an accessible manner that supports synchronous and streaming interactions, session state management, artifact handling, and remote multi-agent protocols.
Module Structure and Key Components
1. REST API Controllers
The REST API controllers implement HTTP handlers that expose agent-related functionality via JSON-based APIs. They process incoming HTTP requests, invoke the underlying agent logic, and return structured JSON responses.
RuntimeAPIController (server/adkrest/controllers/runtime.go):
Handles core agent execution endpoints such as /run and /run_sse (server-sent events streaming). It takes session and user message inputs, validates session existence, runs the agent using arunner.Runnerinstance, and returns session events either as a batch or streamed incrementally.Key functionalities include:
Parsing and validating request bodies.
Managing streaming vs non-streaming agent runs.
Encoding session events into JSON responses.
SessionsAPIController (server/adkrest/controllers/sessions.go):
Manages session lifecycle APIs — creation, retrieval, listing, and deletion of user-agent interaction sessions.ArtifactsAPIController (server/adkrest/controllers/artifacts.go):
Provides endpoints for listing, loading (with versioning support), and deleting artifacts associated with sessions.AppsAPIController and DebugAPIController (server/adkrest/controllers/apps.go, debug.go):
Support listing loaded agents and retrieving debug/tracing info for sessions and events.
Each controller interacts directly with services such as the session.Service, artifact.Service, and the agent.Loader to perform its duties.
2. Router Setup
Routing is established using the gorilla/mux package and organized into modular subrouters, each corresponding to a controller group:
RuntimeAPIRouter (server/adkrest/internal/routers/runtime.go): Routes /run and /run_sse paths to
RuntimeAPIController.SessionsAPIRouter (server/adkrest/internal/routers/sessions.go): Routes session management endpoints.
ArtifactsAPIRouter (server/adkrest/internal/routers/artifacts.go): Routes artifact-related endpoints.
AppsAPIRouter and DebugAPIRouter for apps and debug APIs.
The main HTTP handler (server/adkrest/handler.go) composes these subrouters into a single mux.Router instance, registering all API routes under the /api/ path prefix.
This modular routing setup enables clean separation of concerns, easy extension, and consistent REST endpoint organization.
3. Web UI Launcher
Located in cmd/launcher/web/webui/webui.go, the Web UI Launcher serves an embedded Angular-based web application from the Go binary using the Go embed package.
The launcher mounts the UI at a configurable path prefix (default
/ui/).It serves static assets from embedded resources.
It dynamically generates runtime configuration JSON (/assets/config/runtime-config.json) to provide the frontend with the backend REST API URL.
It handles HTTP redirects from
/to the UI path.
This allows users to interact with agents visually through a browser without needing to deploy frontend assets separately.
4. Web Server Launcher
The Web Server Launcher (cmd/launcher/web/web.go) is a flexible HTTP server framework supporting pluggable sublaunchers:
It manages server lifecycle, command-line parsing, and HTTP routing setup.
Supports middleware such as logging.
Sublaunchers can register additional route handlers, parse their own flags, and print startup messages.
This launcher acts as a host for different web-based interfaces, including:
The API launcher
The Web UI launcher
The A2A launcher
It ensures that these components can run together in a single HTTP server process, sharing configuration and resources.
5. API and A2A Sublaunchers
The module defines sublaunchers extending the web server with specific protocols:
API Launcher (cmd/launcher/web/api/api.go):
Starts the REST API server under /api/ path, including CORS headers configured for the Web UI frontend. It wraps the REST API handler from server/adkrest and enables cross-origin requests.A2A Launcher (cmd/launcher/web/a2a/a2a.go):
Starts the Agent-To-Agent (A2A) server supporting JSON-RPC requests at /a2a/invoke.It advertises a static agent card describing the remote agent capabilities.
It uses the internal
runnerto execute agent invocations triggered by A2A clients.Enables distributed multi-agent communication beyond local REST API calls.
These sublaunchers integrate seamlessly with the Web Server Launcher and can run concurrently to provide comprehensive agent interaction options.
Interaction and Workflow Overview
At a high level, the module operates as follows:
HTTP Request Handling
Incoming HTTP requests are routed by the main mux.Router to the appropriate controller based on the URL path and HTTP method.Controller Processing
Controllers parse and validate request parameters and bodies. For agent runs, theRuntimeAPIControlleruses the agent.Loader to load the requested agent and therunner.Runnerto execute the agent logic with the given session context.Agent Execution
The runner coordinates invoking the agent, managing session state, calling tools and LLMs, and collecting resulting session events.Response Encoding
Session events and other data are serialized into JSON and returned to the client. Streaming responses use Server-Sent Events (SSE) to provide incremental updates.Web UI Serving
The embedded web UI is served as static files with runtime configuration, allowing browsers to interact with the REST API transparently.A2A Communication
The A2A launcher exposes JSON-RPC endpoints enabling remote agents to invoke or communicate with this agent instance, supporting distributed architectures.
Code Illustration: Running an Agent via REST API
The core agent execution flow in the RuntimeAPIController is represented by the RunHandler method:
func (c *RuntimeAPIController) RunHandler(rw http.ResponseWriter, req *http.Request) error {
runAgentRequest, err := decodeRequestBody(req)
if err != nil {
return err
}
sessionEvents, err := c.runAgent(req.Context(), runAgentRequest)
if err != nil {
return err
}
var events []models.Event
for _, event := range sessionEvents {
events = append(events, models.FromSessionEvent(*event))
}
EncodeJSONResponse(events, http.StatusOK, rw)
}
Here:
The request body is decoded into a structured
RunAgentRequest.The session is verified, and the agent is loaded.
The
runner.Runnerexecutes the agent logic with the new message.The resulting session events are transformed and encoded in JSON for the HTTP response.
Visual Diagram: REST API Request Flow
flowchart TD
Client[Client HTTP Request]
Router[HTTP Router]
Controller[RuntimeAPIController]
Validate[Validate Session]
LoadAgent[Load Agent]
Runner[Runner Execute Agent]
AgentLogic[Agent & Tool Invocation]
SessionService[Session Service]
ArtifactService[Artifact Service]
Response[JSON Response / SSE Stream]
Client --> Router --> Controller
Controller --> Validate --> LoadAgent --> Runner
Runner --> AgentLogic
AgentLogic --> SessionService
AgentLogic --> ArtifactService
Runner --> Response
Controller --> Response
Relationships to Other Topics
The REST API Controllers depend on the
agentpackage for core agent loading and execution, detailed in the AI Agent Framework.Session and artifact persistence interfaces used by controllers are implemented in the Session Management and Artifact Management topics.
The Web UI Launcher serves static assets and interacts with the REST API, linking the user interface with backend agent logic.
The A2A Sublauncher connects with the Remote Agent Communication (A2A) topic, enabling distributed multi-agent systems.
The web server launcher architecture supports modular sublaunchers, facilitating extensibility and customization.
This module is essential for exposing the capabilities of AI agents to external users and systems through standardized, scalable, and interactive HTTP interfaces.