Skip to content

armgit / ax

Public Imported from GitHub
0

Agent Executor (AX) is Google's open agentic orchestration runtime

Go

Introduce yaml based config

JBDb5b5912ac483
diff --git a/README.md b/README.md
index 0d33215..c957f77 100644
--- a/README.md
+++ b/README.md
@@ -190,22 +190,40 @@ Options:
#### Run Controller Server
```bash
-gar serve [--addr <address>] [--eventlog-dir <dir>]
+gar serve [--config <path>]
```
-Starts the controller as a gRPC server, exposing the GARService API for remote session management and agent registration.
+Starts the controller as a gRPC server using a YAML configuration file.
Options:
-- `--addr`: Server address to listen on (default: ":8494")
-- `--eventlog-dir`: Directory for event log files (default: "eventlog")
+- `--config`: Path to YAML configuration file (default: "gar.yaml")
+
+The configuration file specifies:
+- Server address and port
+- Event log directory
+- Controller settings (max steps, health check interval)
+- Gemini planner settings (optional)
+
+Example configuration file (`gar.yaml`):
+```yaml
+server:
+ address: ":8494"
+
+eventlog:
+ dir: "eventlog"
+
+controller:
+ max_steps: 100
+ health_check_interval: 30s
+```
Example:
```bash
-# Start server on default port
+# Start server with default config (gar.yaml)
gar serve
-# Start server on custom port
-gar serve --addr :8080
+# Start server with custom config
+gar serve --config my-config.yaml
```
Once running, clients can connect to the server to:
@@ -213,6 +231,43 @@ Once running, clients can connect to the server to:
- Query session status and list sessions
- Register and unregister agents dynamically
+### Gemini-Powered Agent Selection
+
+GAR uses Google's Gemini models by default for intelligent agent selection. Instead of simple round-robin routing, Gemini analyzes the conversation context and agent capabilities to choose the best agent for each task.
+
+**Setup:**
+
+1. Get an API key from [Google AI Studio](https://aistudio.google.com/app/apikey)
+2. Set the environment variable:
+ ```bash
+ export GEMINI_API_KEY="your-api-key-here"
+ ```
+3. Start the server:
+ ```bash
+ gar serve
+ ```
+
+**How it works:**
+- Each registered agent becomes a "tool" that Gemini can call
+- Gemini reviews conversation history and agent descriptions
+- Gemini selects the most appropriate agent for each step
+- Agent metadata helps Gemini make better routing decisions
+
+**Environment Variables:**
+- `GEMINI_API_KEY`: Your Google AI API key (required)
+- `GAR_GEMINI_MODEL`: Model name (optional, defaults to "gemini-flash-latest")
+
+**Example agent registration with metadata:**
+```bash
+gar register \
+ --server localhost:8494 \
+ --agent-id math-agent \
+ --name "Math Agent" \
+ --description "Specialized in mathematical calculations and problem solving"
+```
+
+When a user asks "What is 25 * 4?", Gemini will automatically route to the math-agent instead of a generic agent.
+
### Checkpoints
Checkpoints provide a mechanism to save and resume session state at specific points. Every content event (both `CONTENT_IN` and `CONTENT_OUT`) automatically creates a checkpoint with a unique UUID.
diff --git a/cmd/gar/main.go b/cmd/gar/main.go
index 9011ad3..171a4c6 100644
--- a/cmd/gar/main.go
+++ b/cmd/gar/main.go
@@ -16,6 +16,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
+ "github.com/google/gar/internal/config"
"github.com/google/gar/internal/controller"
"github.com/google/gar/internal/eventlog"
"github.com/google/gar/internal/server"
@@ -26,14 +27,13 @@ import (
var (
command string
sessionID string
- eventLogDir string
input string
checkpointID string
agentID string
agentName string
agentDescription string
agentAddr string
- serveAddr string
+ configFile string // YAML config file path for serve command
serverAddr string // gRPC controller server address
)
@@ -62,8 +62,7 @@ func main() {
registerCmd.StringVar(&serverAddr, "server", "", "gRPC controller server address (e.g., localhost:8494)")
// Serve command flags
- serveCmd.StringVar(&serveAddr, "addr", ":8494", "Server address to listen on")
- serveCmd.StringVar(&eventLogDir, "eventlog-dir", "eventlog", "Event log directory")
+ serveCmd.StringVar(&configFile, "config", "gar.yaml", "Path to YAML configuration file")
if len(os.Args) < 2 {
printUsage()
@@ -105,15 +104,6 @@ func main() {
}
}
-func eventLogFactory(sessionID, eventLogDir string) controller.EventLogFactory {
- return func(sessionID string) (eventlog.EventLog, error) {
- return eventlog.NewFileEventLog(eventlog.FileConfig{
- SessionID: sessionID,
- Dir: eventLogDir,
- })
- }
-}
-
// connectToServer creates a gRPC client connection to the controller server.
func connectToServer() (proto.GARServiceClient, *grpc.ClientConn, error) {
conn, err := grpc.NewClient(serverAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
@@ -295,9 +285,27 @@ func runRegister() {
}
func runServe() {
- fmt.Printf("Starting GAR server at %s...\n", serveAddr)
+ // Load configuration from YAML file
+ cfg, err := config.LoadFromFile(configFile)
+ if err != nil {
+ fmt.Printf("Error loading config file '%s': %v\n", configFile, err)
+ fmt.Println("\nTip: Create a config file with 'gar serve --help' to see an example")
+ os.Exit(1)
+ }
- c, err := newController()
+ // Validate configuration
+ if err := cfg.Validate(); err != nil {
+ fmt.Printf("Invalid configuration: %v\n", err)
+ os.Exit(1)
+ }
+
+ fmt.Printf("Starting GAR server at %s...\n", cfg.Server.Address)
+ fmt.Printf("Event log directory: %s\n", cfg.EventLog.Dir)
+ fmt.Printf("Max steps: %d\n", cfg.Controller.MaxSteps)
+ fmt.Printf("Health check interval: %s\n", cfg.Controller.HealthCheckInterval)
+
+ // Create controller with config
+ c, err := newControllerFromConfig(cfg)
if err != nil {
fmt.Printf("Error creating controller: %v\n", err)
os.Exit(1)
@@ -318,18 +326,32 @@ func runServe() {
}()
// Start serving
- if err := srv.Serve(serveAddr); err != nil {
+ if err := srv.Serve(cfg.Server.Address); err != nil {
fmt.Printf("Error serving: %v\n", err)
os.Exit(1)
}
}
-func newController() (*controller.Controller, error) {
- c, err := controller.New(controller.Config{
- EventLogFactory: eventLogFactory(sessionID, eventLogDir),
- MaxSteps: 100,
- HealthCheckInterval: 30 * time.Second,
- })
+func newControllerFromConfig(cfg *config.Config) (*controller.Controller, error) {
+ // Create event log factory
+ eventLogFactory := func(sessionID string) (eventlog.EventLog, error) {
+ return eventlog.NewFileEventLog(eventlog.FileConfig{
+ SessionID: sessionID,
+ Dir: cfg.EventLog.Dir,
+ })
+ }
+
+ // Build controller config
+ // The controller will create a default Gemini planner if PlanFunc is nil
+ // Gemini config can be customized via environment variables (GEMINI_API_KEY, GAR_GEMINI_MODEL)
+ controllerConfig := controller.Config{
+ EventLogFactory: eventLogFactory,
+ MaxSteps: cfg.Controller.MaxSteps,
+ HealthCheckInterval: cfg.Controller.HealthCheckInterval,
+ }
+
+ // Create controller
+ c, err := controller.New(controllerConfig)
if err != nil {
return nil, err
}
diff --git a/gar.yaml b/gar.yaml
new file mode 100644
index 0000000..d3b3c88
--- /dev/null
+++ b/gar.yaml
@@ -0,0 +1,46 @@
+# GAR Server Configuration
+# This file configures the GAR (Google Agent Runtime) server.
+
+# Server configuration
+server:
+ # Address to listen on (host:port)
+ address: ":8494"
+
+# Event log configuration
+eventlog:
+ # Directory where event logs are stored
+ dir: "eventlog"
+
+# Controller configuration
+controller:
+ # Maximum number of steps per session
+ max_steps: 1000
+
+ # Health check interval for agents (e.g., "30s", "1m")
+ health_check_interval: 30s
+
+# Gemini planner configuration (optional)
+# The Gemini planner uses Google's Gemini models for intelligent agent selection.
+# API key must be set via GEMINI_API_KEY environment variable (required).
+# Model name can be set via GAR_GEMINI_MODEL environment variable (optional).
+#
+# gemini_planner:
+# Set GEMINI_API_KEY for authentication.
+#
+# # Model name (e.g., "gemini-2.5-flash")
+# model: "gemini-flash-latest"
+#
+# # Temperature for generation (0.0 to 1.0)
+# temperature: 0.7
+#
+# # Maximum output tokens
+# max_tokens: 8192
+#
+# # Request timeout (e.g., "30s", "1m")
+# timeout: 60s
+#
+# # Number of recent messages to include in context
+# context_window: 30
+#
+# # Custom system prompt for the planner (optional)
+# system_prompt: ""
diff --git a/go.mod b/go.mod
index 8227c1f..0ee63d2 100644
--- a/go.mod
+++ b/go.mod
@@ -41,4 +41,5 @@ require (
google.golang.org/api v0.186.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20251029180050-ab9386a59fda // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20251222181119-0a764e51fe1b // indirect
+ gopkg.in/yaml.v3 v3.0.1 // indirect
)
diff --git a/go.sum b/go.sum
index 12c4af5..d8430d0 100644
--- a/go.sum
+++ b/go.sum
@@ -164,6 +164,7 @@ google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBN
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
diff --git a/internal/config/config.go b/internal/config/config.go
new file mode 100644
index 0000000..56ee010
--- /dev/null
+++ b/internal/config/config.go
@@ -0,0 +1,104 @@
+// Package config provides configuration structures for GAR server.
+package config
+
+import (
+ "fmt"
+ "os"
+ "time"
+
+ "gopkg.in/yaml.v3"
+)
+
+// Config represents the main configuration for GAR server.
+type Config struct {
+ Server ServerConfig `yaml:"server"`
+ EventLog EventLogConfig `yaml:"eventlog"`
+ Controller ControllerConfig `yaml:"controller"`
+ GeminiPlanner GeminiPlannerConfig `yaml:"gemini_planner,omitempty"`
+}
+
+// ServerConfig configures the gRPC server.
+type ServerConfig struct {
+ Address string `yaml:"address"` // Server address to listen on (e.g., ":8494")
+}
+
+// EventLogConfig configures the event log storage.
+type EventLogConfig struct {
+ Dir string `yaml:"dir"` // Directory for event log files
+}
+
+// ControllerConfig configures the controller behavior.
+type ControllerConfig struct {
+ MaxSteps int `yaml:"max_steps"` // Maximum steps per session
+ HealthCheckInterval time.Duration `yaml:"health_check_interval"` // Health check interval for agents
+}
+
+// GeminiPlannerConfig configures the Gemini-based planner.
+// Note: API key is not configurable here for security reasons.
+// Set GEMINI_API_KEY environment variable instead.
+type GeminiPlannerConfig struct {
+ Model string `yaml:"model,omitempty"` // Model name
+ Temperature float32 `yaml:"temperature,omitempty"`
+ MaxTokens int32 `yaml:"max_tokens,omitempty"`
+ Timeout time.Duration `yaml:"timeout,omitempty"`
+ ContextWindow int `yaml:"context_window,omitempty"`
+ SystemPrompt string `yaml:"system_prompt,omitempty"`
+}
+
+// LoadFromFile loads configuration from a YAML file.
+func LoadFromFile(path string) (*Config, error) {
+ data, err := os.ReadFile(path)
+ if err != nil {
+ return nil, fmt.Errorf("failed to read config file: %w", err)
+ }
+
+ var cfg Config
+ if err := yaml.Unmarshal(data, &cfg); err != nil {
+ return nil, fmt.Errorf("failed to parse config file: %w", err)
+ }
+
+ // Set defaults
+ cfg.setDefaults()
+
+ return &cfg, nil
+}
+
+// setDefaults sets default values for optional fields.
+func (c *Config) setDefaults() {
+ // Server defaults
+ if c.Server.Address == "" {
+ c.Server.Address = ":8494"
+ }
+
+ // EventLog defaults
+ if c.EventLog.Dir == "" {
+ c.EventLog.Dir = "eventlog"
+ }
+
+ // Controller defaults
+ if c.Controller.MaxSteps == 0 {
+ c.Controller.MaxSteps = 100
+ }
+ if c.Controller.HealthCheckInterval == 0 {
+ c.Controller.HealthCheckInterval = 30 * time.Second
+ }
+
+ // Gemini planner defaults are handled in the controller package
+}
+
+// Validate validates the configuration.
+func (c *Config) Validate() error {
+ if c.Server.Address == "" {
+ return fmt.Errorf("server.address is required")
+ }
+ if c.EventLog.Dir == "" {
+ return fmt.Errorf("eventlog.dir is required")
+ }
+ if c.Controller.MaxSteps <= 0 {
+ return fmt.Errorf("controller.max_steps must be positive")
+ }
+ if c.Controller.HealthCheckInterval <= 0 {
+ return fmt.Errorf("controller.health_check_interval must be positive")
+ }
+ return nil
+}
diff --git a/internal/controller/gemini_planner.go b/internal/controller/gemini_planner.go
index 75a5cf7..16c85de 100644
--- a/internal/controller/gemini_planner.go
+++ b/internal/controller/gemini_planner.go
@@ -14,13 +14,13 @@ import (
// GeminiPlannerConfig configures the Gemini-based planner.
type GeminiPlannerConfig struct {
- APIKey string // Google AI API key (if empty, uses GEMINI_API_KEY env var)
- Model string // Model name (default: "gemini-2.0-flash-exp")
+ APIKey string // Google AI API key (for programmatic use only; if empty, uses GEMINI_API_KEY env var - recommended)
+ Model string // Model name (default: "gemini-flash-latest", can override with GAR_GEMINI_MODEL env var)
Temperature float32 // Temperature for generation (default: 0.7)
MaxTokens int32 // Max output tokens (default: 8192)
- Timeout time.Duration // Request timeout (default: 30s)
+ Timeout time.Duration // Request timeout (default: 60s)
SystemPrompt string // Custom system prompt (optional)
- ContextWindow int // Number of recent messages to include (default: 20)
+ ContextWindow int // Number of recent messages to include (default: 30)
}
// NewGeminiPlanFunc creates a planning function that uses Gemini for intelligent agent selection.