API and A2A Sublaunchers

Purpose

The API and A2A Sublaunchers subtopic addresses the integration of two distinct but complementary communication protocols into the web server launcher framework: the REST API and the Agent-to-Agent (A2A) protocol. While the parent topic REST API and Web Launchers broadly implements REST API servers, HTTP routing, and embedded web UI launchers for agent interaction, this subtopic focuses specifically on the modular sublaunchers that enable the web server to serve these protocols independently or together.

This modularization allows the web server launcher to flexibly incorporate:

By separating these concerns into sublaunchers, the system can selectively activate or configure each protocol based on command-line arguments or deployment needs, improving maintainability and extensibility.

Functionality

REST API Sublauncher

The REST API sublauncher encapsulates the setup of the ADK REST API server at the /api/ URL path. Key functions include:

A snippet illustrating the router setup and CORS wrapping:

apiHandler := adkrest.NewHandler(config)
corsHandler := corsWithArgs(a.config.frontendAddress)(apiHandler)
router.Methods("GET", "POST", "DELETE", "OPTIONS").PathPrefix("/api/").Handler(
	http.StripPrefix("/api", corsHandler),
)

This setup ensures the REST API is accessible under /api/, with all requests checked for proper origin.

A2A Protocol Sublauncher

The A2A sublauncher integrates the Agent-to-Agent protocol server into the web server launcher, enabling remote agent communication and distributed agent invocation workflows. Key aspects:

Example code registering the agent card and JSON-RPC endpoint:

router.Handle(a2asrv.WellKnownAgentCardPath, a2asrv.NewStaticAgentCardHandler(agentCard))
router.Handle(apiPath, a2asrv.NewJSONRPCHandler(reqHandler))

Shared Characteristics

Both sublaunchers:

Integration with Parent Topic and Other Subtopics

The API and A2A sublaunchers extend the functionality of the parent topic REST API and Web Launchers by providing concrete implementations of sublaunchers that can be started alongside or separately from the embedded web UI launcher and routing setup subtopics.

This modular design enables the web server launcher to act as a unified entry point supporting multiple interaction paradigms (REST API, A2A, Web UI), each with isolated concerns but shared underlying agent execution logic.

sequenceDiagram
participant User
participant WebServerLauncher
participant APISublauncher
participant A2ASublauncher
participant Router
participant AgentRunner
participant Agent
User->>WebServerLauncher: Launch with flags (api, a2a, webui)
WebServerLauncher->>APISublauncher: Initialize REST API sublauncher
WebServerLauncher->>A2ASublauncher: Initialize A2A sublauncher
APISublauncher->>Router: Register /api/ routes with CORS
A2ASublauncher->>Router: Register /.well-known/agentcard and /a2a/invoke
User->>Router: HTTP REST Request (/api/...)
Router->>APISublauncher: Handle REST API request
APISublauncher->>AgentRunner: Execute agent logic
User->>Router: JSON-RPC Request (/a2a/invoke)
Router->>A2ASublauncher: Handle A2A JSON-RPC request
A2ASublauncher->>AgentRunner: Execute agent logic
AgentRunner->>Agent: Invoke agent with input
Agent-->>AgentRunner: Return response/events
AgentRunner-->>APISublauncher/A2ASublauncher: Return results
APISublauncher/A2ASublauncher-->>User: Return HTTP response

This sequence diagram illustrates the lifecycle from user request through the web server launcher to the sublaunchers and ultimately the agent execution, highlighting how the API and A2A sublaunchers integrate seamlessly with routing and agent execution layers.