a2a

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 26, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package a2a exposes baifo's agents over the A2A (Agent-to-Agent) protocol so the TUI (and, later, remote clients) can converse with any agent without going through the in-process Facade.

Layout follows Magec's convention:

/api/a2a/<agent_id>                          -> JSON-RPC handler
/api/a2a/<agent_id>/.well-known/agent-card.json
/api/a2a/.well-known/agent-card.json?agent=ID  (global discovery)

One handler is registered per agent; the routing layer lives in ServeA2A so the parent mux only needs a single Handle("/api/a2a/").

Index

Constants

View Source
const PathPrefix = "/api/a2a/"

PathPrefix is the URL prefix every A2A endpoint sits under. Kept public so the TUI client and the main mux can refer to a single constant.

Variables

This section is empty.

Functions

func AgentIDFromContext

func AgentIDFromContext(ctx context.Context) string

AgentIDFromContext returns the agent id the handler stamped on the request context, or empty when called outside an A2A request flow.

func BuildRequestHandler

func BuildRequestHandler(entry AgentEntry, sessionSvc session.Service, memorySvc memory.Service) a2asrv.RequestHandler

BuildRequestHandler constructs an a2asrv.RequestHandler for a single agent. Exported so callers that do not need the HTTP/JSON-RPC layer (notably the TUI, which talks to the same handler in-process) can reuse the exact same executor wiring used by Rebuild.

Types

type AgentEntry

type AgentEntry struct {
	// ID is the slug used in the URL (e.g. "root", "code-reviewer",
	// "dyn_abc12345"). Must be unique per Handler.
	ID string

	// Name and Description are surfaced in the Agent Card. Free-form.
	Name        string
	Description string

	// Agent is the live ADK agent. The executor will use it as the
	// running root for every incoming task.
	Agent agent.Agent

	// Streaming selects the run's streaming mode. True (the default
	// for most providers) runs in SSE; false is for OpenAI-compatible
	// endpoints that do not implement Server-Sent Events. Resolved by
	// the caller from the agent's provider config.
	Streaming bool
}

AgentEntry is the minimal description Handler needs to register one agent. The caller (internal/server) constructs these from the App's concrete state; this package does not import internal/app to avoid a cycle.

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler routes /api/a2a/* requests to the right per-agent JSON-RPC handler and serves Agent Card discovery endpoints. It is safe to call Rebuild while serving: handlers and cards are swapped under a write lock and existing in-flight requests keep their reference.

func NewHandler

func NewHandler(publicURL string, requireAuth bool) *Handler

NewHandler returns a Handler bound to the given public URL. The URL is embedded in every Agent Card so external callers know where to reach each agent; pass the loopback URL when the server is local. Set requireAuth to true when the server enforces bearer authentication so Rebuild can annotate each card with the matching security scheme. The token value is never passed here and never written into any card.

func (*Handler) AgentIDs

func (h *Handler) AgentIDs() []string

AgentIDs returns the slugs currently registered. Useful for the server's health endpoint and for tests.

func (*Handler) Rebuild

func (h *Handler) Rebuild(entries []AgentEntry, sessionSvc session.Service, memorySvc memory.Service)

Rebuild swaps the live set of agents. Every entry produces one JSON-RPC handler (via BuildRequestHandler + a2asrv.NewJSONRPCHandler) and one Agent Card. Pass the shared sessionSvc and memorySvc so every executor goes through the same persistence layer.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP routes an incoming request based on its path: well-known discovery vs JSON-RPC invocation. Plug this into the parent mux as Handle("/api/a2a/", h).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL