launcher.go

Overview

The launcher.go file defines the foundational interfaces and configuration structures for running ADK (Agent Development Kit) applications. It provides abstractions for command-line application launchers, supporting both monolithic and composable modes of operation. The file introduces two main launcher interfaces — Launcher and SubLauncher — to facilitate flexible execution patterns, including modular subcommands (or sub-launchers) that represent different operational modes (e.g., console or web modes).

Additionally, it defines the Config struct that encapsulates core services required for agent execution, such as session management, artifact storage, memory, and agent loading. This configuration object acts as a dependency injection container, enabling launchers and sublaunchers to operate with the necessary platform services.

The file serves as a key integration point between the command-line interface layer and the lower-level agent runtime components, bridging user input parsing with the invocation of agent workflows and services.


Types and Interfaces

Launcher Interface

type Launcher interface {
	Execute(ctx context.Context, config *Config, args []string) error
	CommandLineSyntax() string
}

Description

Launcher is the primary interface representing an ADK application launcher. It is responsible for parsing command-line arguments and executing the launcher logic accordingly.

Methods


SubLauncher Interface

type SubLauncher interface {
	Keyword() string
	Parse(args []string) ([]string, error)
	CommandLineSyntax() string
	SimpleDescription() string
	Run(ctx context.Context, config *Config) error
}

Description

SubLauncher represents a modular launcher that can be composed into a parent launcher. Each sublauncher corresponds to a distinct mode or command, enabling extensible CLI behavior. For example, sublaunchers might handle different interaction modes like "console" or "web".

Methods


Config Struct

type Config struct {
	SessionService  session.Service
	ArtifactService artifact.Service
	MemoryService   memory.Service
	AgentLoader     agent.Loader
	A2AOptions      []a2asrv.RequestHandlerOption
}

Description

Config holds the key service dependencies and options required by launchers and sublaunchers to run ADK agents and sessions.

Fields


Important Implementation Details


Interactions with Other System Components


Example Usage

func main() {
    ctx := context.Background()

    // Setup configuration with required services
    config := &launcher.Config{
        SessionService:  mySessionService,
        ArtifactService: myArtifactService,
        MemoryService:   myMemoryService,
        AgentLoader:     myAgentLoader,
        A2AOptions:      []a2asrv.RequestHandlerOption{},
    }

    // Instantiate a concrete launcher implementing Launcher interface
    var l launcher.Launcher = NewUniversalLauncher()

    // Execute launcher with command-line args
    if err := l.Execute(ctx, config, os.Args[1:]); err != nil {
        log.Fatalf("Launcher failed: %v", err)
    }
}

Diagram: Launcher Structure and Relationships

classDiagram
class Launcher {
+Execute()
+CommandLineSyntax()
}
class SubLauncher {
+Keyword()
+Parse()
+CommandLineSyntax()
+SimpleDescription()
+Run()
}
class Config {
+SessionService
+ArtifactService
+MemoryService
+AgentLoader
+A2AOptions
}
Launcher <|.. SubLauncher : can contain
Launcher o-- Config : uses
SubLauncher o-- Config : uses

This diagram illustrates the main interfaces and configuration struct within launcher.go. The Launcher interface can contain or compose multiple SubLauncher instances, each representing a distinct command or operational mode. Both launcher types depend on the Config struct, which provides references to essential services for agent execution.