Skip to content

armgit / ax

Public Imported from GitHub
0

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

Go

Use default config if --config is not set (#235)

Jaana Doganb77e373bf968
diff --git a/cmd/ax/exec.go b/cmd/ax/exec.go
index 4d54620..5e8c707 100644
--- a/cmd/ax/exec.go
+++ b/cmd/ax/exec.go
@@ -24,7 +24,6 @@ import (
"syscall"
"github.com/google/ax/cmd/ax/internal"
- "github.com/google/ax/internal/config"
"github.com/google/ax/internal/controller"
"github.com/google/ax/proto"
"github.com/google/uuid"
@@ -89,6 +88,18 @@ func runExec(cmd *cobra.Command, args []string) error {
cancel()
}()
+ if execServerAddr == "" {
+ cfg, err := newConfig(cmd, execConfigFile)
+ if err != nil {
+ return err
+ }
+ c, err := newControllerFromConfig(ctx, cfg)
+ if err != nil {
+ return fmt.Errorf("error creating controller: %w", err)
+ }
+ execController = c
+ }
+
return execLoop(ctx, execConversationID, execAgentID, execInput, execLastSeq)
}
@@ -218,19 +229,6 @@ func runAutoExec(ctx context.Context, d *internal.Display, req *proto.ExecReques
}
func runExecHeadless(ctx context.Context, d *internal.Display, req *proto.ExecRequest) (*proto.ConfirmationContent, error) {
- if execController == nil {
- cfg, err := config.LoadFromFile(execConfigFile)
- if err != nil {
- return nil, fmt.Errorf("error loading config file '%s': %w", execConfigFile, err)
- }
-
- c, err := newControllerFromConfig(ctx, cfg)
- if err != nil {
- return nil, fmt.Errorf("error creating controller: %w", err)
- }
- execController = c
- }
-
var confirmation *proto.ConfirmationContent
var lastSeq int32
outputHandler := controller.ExecHandler(func(resp *proto.ExecResponse) error {
diff --git a/cmd/ax/main.go b/cmd/ax/main.go
index 1de3f16..c574332 100644
--- a/cmd/ax/main.go
+++ b/cmd/ax/main.go
@@ -18,9 +18,11 @@
package main
import (
+ "errors"
"fmt"
"os"
+ "github.com/google/ax/internal/config"
"github.com/spf13/cobra"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
@@ -58,3 +60,14 @@ func connect(server string) (*grpc.ClientConn, error) {
}
return conn, nil
}
+
+func newConfig(cmd *cobra.Command, configFile string) (*config.Config, error) {
+ cfg, err := config.LoadFromFile(configFile)
+ if errors.Is(err, os.ErrNotExist) && !cmd.Flags().Changed("config") {
+ return config.DefaultConfig(), nil
+ }
+ if err != nil {
+ return nil, fmt.Errorf("error loading config file '%s': %w", configFile, err)
+ }
+ return cfg, nil
+}
diff --git a/cmd/ax/serve.go b/cmd/ax/serve.go
index 5859bf1..9ff39ef 100644
--- a/cmd/ax/serve.go
+++ b/cmd/ax/serve.go
@@ -16,7 +16,6 @@ package main
import (
"context"
- "errors"
"fmt"
"log"
"os"
@@ -53,7 +52,7 @@ func init() {
func runServe(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
- cfg, err := newConfig(cmd)
+ cfg, err := newConfig(cmd, serveConfigFile)
if err != nil {
return err
}
@@ -90,16 +89,6 @@ func runServe(cmd *cobra.Command, args []string) error {
return nil
}
-func newConfig(cmd *cobra.Command) (*config.Config, error) {
- cfg, err := config.LoadFromFile(serveConfigFile)
- if errors.Is(err, os.ErrNotExist) && !cmd.Flags().Changed("config") {
- return config.DefaultConfig(), nil
- }
- if err != nil {
- return nil, fmt.Errorf("error loading config file '%s': %w", serveConfigFile, err)
- }
- return cfg, nil
-}
func newControllerFromConfig(ctx context.Context, cfg *config.Config) (*controller.Controller, error) {
// Create event log builder
diff --git a/cmd/ax/trace.go b/cmd/ax/trace.go
index 83c92c4..8725747 100644
--- a/cmd/ax/trace.go
+++ b/cmd/ax/trace.go
@@ -52,8 +52,13 @@ func init() {
}
func runTrace(cmd *cobra.Command, args []string) error {
+ cfg, err := newConfig(cmd, traceConfigFile)
+ if err != nil {
+ return err
+ }
+
// Load trace data
- data, err := loadTraceData(cmd.Context(), conversationID)
+ data, err := loadTraceData(cmd.Context(), cfg, conversationID)
if err != nil {
return fmt.Errorf("error loading trace data: %w", err)
}
@@ -112,11 +117,8 @@ type TraceData struct {
Execs []ExecTrace `json:"execs"`
}
-func loadTraceData(ctx context.Context, convID string) (*TraceData, error) {
- // The trace command uses the config provided by --config flag
- configPath := traceConfigFile
-
- events, rootExecID, err := fetchEventsByConversation(ctx, configPath, convID)
+func loadTraceData(ctx context.Context, cfg *config.Config, convID string) (*TraceData, error) {
+ events, rootExecID, err := fetchEventsByConversation(ctx, cfg, convID)
if err != nil {
return nil, err
}
@@ -129,12 +131,7 @@ func loadTraceData(ctx context.Context, convID string) (*TraceData, error) {
return data, nil
}
-func fetchEventsByConversation(ctx context.Context, configPath string, convID string) ([]*proto.ExecutionEvent, string, error) {
- cfg, err := config.LoadFromFile(configPath)
- if err != nil {
- return nil, "", fmt.Errorf("error loading config: %w", err)
- }
-
+func fetchEventsByConversation(ctx context.Context, cfg *config.Config, convID string) ([]*proto.ExecutionEvent, string, error) {
evLog, err := executor.OpenSQLiteEventLog(cfg.EventLog.SQLiteConfig.Filename)
if err != nil {
return nil, "", fmt.Errorf("could not open sqlite eventlog: %w", err)