main.go

Overview

The main.go file serves as the entry point for launching a multi-agent application designed to answer questions about time and weather in a city, generate images, and audit large language model (LLM) interactions. It configures and initializes LLM-based agents, session and artifact services, and establishes an agent loader that manages multiple agents. The file also sets up a launcher that integrates these components into a runnable command-line executable.

This file orchestrates the integration of agents built on the Gemini LLM model with various tools, manages user authentication for agent-to-agent (A2A) communication, and handles the lifecycle and storage of artifacts generated during agent execution.


Main Components

1. saveReportfunc

func saveReportfunc(ctx agent.CallbackContext, llmResponse *model.LLMResponse, llmResponseError error) (*model.LLMResponse, error)

2. AuthInterceptor Struct and Methods

type AuthInterceptor struct {
	a2asrv.PassthroughCallInterceptor
}
func (a *AuthInterceptor) Before(ctx context.Context, callCtx *a2asrv.CallContext, req *a2asrv.Request) (context.Context, error)

3. main Function

func main()

Important Implementation Details


Interactions with Other System Components


Visual Diagram: Flowchart of Main Function and Key Interactions

flowchart TD
A[Start main] --> B[Load GOOGLE_API_KEY]
B --> C[Create Gemini LLM Model]
C --> D[Create In-Memory Session Service]
D --> E[Create Root LLM Agent]
E --> F[Add Google Search Tool]
F --> G[Attach saveReportfunc Callback]
G --> H[Create LLM Auditor Agent]
H --> I[Create Image Generator Agent]
I --> J[Create MultiLoader with Agents]
J --> K[Create In-Memory Artifact Service]
K --> L[Configure Launcher with Services & AuthInterceptor]
L --> M[Execute Launcher]
M --> N{Execution Success?}
N -- Yes --> O[Run Application]
N -- No --> P[Log Error & Show Usage]

Summary of Functions and Structures

Name

Type

Description

saveReportfunc

Function

Callback to save LLM response parts as artifacts after model call.

AuthInterceptor

Struct

Call interceptor injecting a static user identity into A2A calls.

AuthInterceptor.Before

Method

Sets authenticated user in call context before A2A request.

main

Function

Initializes services, agents, loaders, and launches the application.


Usage Notes


References to Related Topics