Skip to content

armgit / ax

Public Imported from GitHub
0

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

Go

Demo and many other fixes (#331)

Jaana Doganaf899c803610
diff --git a/cmd/ax/exec.go b/cmd/ax/exec.go
index b1ea03b..df8523c 100644
--- a/cmd/ax/exec.go
+++ b/cmd/ax/exec.go
@@ -349,7 +349,7 @@ func promptUser(d *internal.Display, input string) (string, bool, error) {
d.DisplayInput(input)
if strings.ToLower(strings.TrimSpace(input)) == "q" {
- d.ShowResumption(execConversationID)
+ d.ShowResumption(execConversationID, execServerAddr)
return "", true, nil
}
return input, false, nil
diff --git a/cmd/ax/internal/display.go b/cmd/ax/internal/display.go
index e9ecdc3..189081e 100644
--- a/cmd/ax/internal/display.go
+++ b/cmd/ax/internal/display.go
@@ -120,7 +120,11 @@ func (d *Display) PromptForInput() (string, error) {
return userInput, nil
}
-func (d *Display) ShowResumption(id string) {
+func (d *Display) ShowResumption(id string, server string) {
fmt.Println(d.resumeStyle.Render("To resume the conversation,"))
- fmt.Println(d.resumeStyle.Render(fmt.Sprintf("ax exec --conversation %s", id)))
+ if server != "" {
+ fmt.Println(d.resumeStyle.Render(fmt.Sprintf("ax exec --conversation %s --server %s", id, server)))
+ } else {
+ fmt.Println(d.resumeStyle.Render(fmt.Sprintf("ax exec --conversation %s", id)))
+ }
}
diff --git a/cmd/ax/main.go b/cmd/ax/main.go
index aedef01..3d6348c 100644
--- a/cmd/ax/main.go
+++ b/cmd/ax/main.go
@@ -52,7 +52,9 @@ func init() {
}
func connect(server string) (*grpc.ClientConn, error) {
- conn, err := grpc.NewClient(server, grpc.WithTransportCredentials(insecure.NewCredentials()))
+ conn, err := grpc.NewClient(server,
+ grpc.WithTransportCredentials(insecure.NewCredentials()),
+ )
if err != nil {
return nil, fmt.Errorf("failed to connect to server: %w", err)
}
diff --git a/internal/controller/controller.go b/internal/controller/controller.go
index a645829..d9c66b9 100644
--- a/internal/controller/controller.go
+++ b/internal/controller/controller.go
@@ -21,9 +21,9 @@ import (
"fmt"
"maps"
"os"
- "sync"
"github.com/google/ax/internal/agent"
+ "github.com/google/ax/internal/config"
"github.com/google/ax/internal/controller/executor"
"github.com/google/ax/internal/experimental/testagent"
"github.com/google/ax/internal/gemini"
@@ -38,8 +38,6 @@ type ExecHandler func(resp *proto.ExecResponse) error
// Controller is the main controller that coordinates all components.
// It acts as a single-writer system for managing agentic loops.
type Controller struct {
- inFlightMu sync.Mutex
- inFlight map[string]struct{}
registry *Registry
eventLog executor.EventLog
plannerBuilder PlannerBuilder
@@ -55,31 +53,51 @@ type Config struct {
}
// New creates a new controller instance.
-func New(ctx context.Context, config Config) (*Controller, error) {
+func New(ctx context.Context, cfg Config) (*Controller, error) {
// Initialize agent registry
registry := NewRegistry()
// Determine plan function
// If no planner builder is provided, use the default Gemini planner.
- if config.PlannerBuilder == nil {
- config.PlannerBuilder = func(ctx context.Context, r *Registry) (agent.Agent, error) {
+ if cfg.PlannerBuilder == nil {
+ cfg.PlannerBuilder = func(ctx context.Context, r *Registry) (agent.Agent, error) {
return gemini.NewGeminiPlannerAgent(ctx, r, gemini.GeminiPlannerConfig{})
}
}
- if config.EventLogBuilder == nil {
+ if cfg.EventLogBuilder == nil {
return nil, fmt.Errorf("event log builder is required")
}
- eventLog, err := config.EventLogBuilder()
+ eventLog, err := cfg.EventLogBuilder()
if err != nil {
return nil, fmt.Errorf("failed to create event log: %w", err)
}
+ // For testing only! Remove this once the project is stable.
+ // TODO(jbd): Remove this before the release.
+ if os.Getenv("AX_TEST_AGENTS") == "1" {
+ if err := registry.RegisterLocal(config.LocalAgentConfig{
+ ID: "docker-build",
+ Name: "Docker build",
+ Agent: testagent.DockerBuild(),
+ Description: "Allows building OCI or Docker images from code. Provided with code, it automatically figures out how to build an image and pushes it to the registry.",
+ }); err != nil {
+ return nil, err
+ }
+ if err := registry.RegisterLocal(config.LocalAgentConfig{
+ ID: "kubernetes-deploy",
+ Name: "Production Kubernetes deploy",
+ Agent: testagent.KubernetesDeploy(),
+ Description: "Deploys the provided context to the production regions to Kubernetes clusters.",
+ }); err != nil {
+ return nil, err
+ }
+ }
+
return &Controller{
- inFlight: make(map[string]struct{}),
registry: registry,
eventLog: eventLog,
- plannerBuilder: config.PlannerBuilder,
+ plannerBuilder: cfg.PlannerBuilder,
}, nil
}
@@ -164,29 +182,17 @@ func (d *Controller) Exec(ctx context.Context, req *proto.ExecRequest, handler E
return fmt.Errorf("conversation_id is required")
}
- inFlight, cleanup := d.markInFlight(req.ConversationId)
- defer cleanup()
-
- if inFlight {
- return fmt.Errorf("conversation %q is already in flight", req.ConversationId)
- }
-
planner, err := d.plannerBuilder(ctx, d.registry)
if err != nil {
return fmt.Errorf("failed to create planner: %w", err)
}
+
registry := maps.Clone(d.registry.Map())
registry[plannerAgentID] = planner
// TODO(lhuan): consider remove this.
registry["gemini"] = gemini.NewGeminiAgent()
- // For testing only! Remove this once the project is stable.
- // TODO(jbd): Remove this before the release.
- if os.Getenv("AX_TEST_AGENTS") == "1" {
- maps.Copy(registry, testagent.Agents())
- }
-
if req.AgentId == "" {
req.AgentId = plannerAgentID
}
@@ -272,12 +278,6 @@ func (d *Controller) Delete(ctx context.Context, conversationID string) error {
if conversationID == "" {
return fmt.Errorf("conversation_id is required")
}
- inFlight, cleanup := d.markInFlight(conversationID)
- defer cleanup()
-
- if inFlight {
- return fmt.Errorf("conversation %q is in flight, cannot delete", conversationID)
- }
return d.eventLog.DeleteEvents(ctx, conversationID)
}
@@ -292,13 +292,6 @@ func (d *Controller) Fork(ctx context.Context, srcConversationID string, srcSeq
destConversationID = uuid.NewString()
}
- inFlight, cleanup := d.markInFlight(destConversationID)
- defer cleanup()
-
- if inFlight {
- return "", fmt.Errorf("conversation %q is already in flight", destConversationID)
- }
-
events, err := d.eventLog.Events(ctx, srcConversationID)
if err != nil {
return "", fmt.Errorf("failed to retrieve source events: %w", err)
@@ -362,20 +355,3 @@ func (d *Controller) Close() error {
}
return nil
}
-
-func (d *Controller) markInFlight(id string) (exists bool, cleanup func()) {
- d.inFlightMu.Lock()
- defer d.inFlightMu.Unlock()
-
- _, ok := d.inFlight[id]
- if ok {
- return true, func() {}
- }
- d.inFlight[id] = struct{}{}
-
- return false, func() {
- d.inFlightMu.Lock()
- delete(d.inFlight, id)
- d.inFlightMu.Unlock()
- }
-}
diff --git a/internal/experimental/testagent/agent.go b/internal/experimental/testagent/agent.go
index 35a7cd7..6027129 100644
--- a/internal/experimental/testagent/agent.go
+++ b/internal/experimental/testagent/agent.go
@@ -42,6 +42,14 @@ func Agents() map[string]agent.Agent {
}
}
+func DockerBuild() agent.Agent {
+ return &DockerBuilderAgent{}
+}
+
+func KubernetesDeploy() agent.Agent {
+ return &KubernetesDeployAgent{}
+}
+
type KubernetesDeployAgentConfig struct {
Regions []string `json:"regions"`
}
@@ -189,97 +197,86 @@ func (a *KubernetesDeployAgent) Connect(ctx context.Context, conversationID stri
}
regions := pendingRegions[conf.Id]
- if err := o(&proto.AgentOutputs{
- Messages: []*proto.Message{{
+ var history []*proto.Message
+ history = append(history, start.Messages...)
+
+ out := func(text string) error {
+ msg := &proto.Message{
Role: "assistant",
Content: &proto.Content{
Type: &proto.Content_Text{
Text: &proto.TextContent{
- Text: fmt.Sprintf("Picked %v region(s) for deployment.", strings.Join(regions, ",")),
+ Text: text,
},
},
},
- }},
- }); err != nil {
+ }
+ history = append(history, msg)
+ return o(&proto.AgentOutputs{
+ Messages: []*proto.Message{msg},
+ })
+ }
+
+ if err := out(fmt.Sprintf("Picked %v region(s) for deployment.", strings.Join(regions, ","))); err != nil {
return err
}
for _, region := range regions {
- if region != "us-central1" {
- _, err := exec.Exec(ctx, conversationID, "mirror-"+region, &proto.AgentStart{
- AgentId: "docker-mirror",
- Messages: []*proto.Message{
- {
- Role: "user",
- Content: &proto.Content{
- Type: &proto.Content_Text{
- Text: &proto.TextContent{
- Text: "Provide a mirror to the region if the image doesn't exist.",
- },
- },
- },
- },
- },
- })
- if err != nil {
- return err
- }
- }
- if err := o(&proto.AgentOutputs{
- Messages: []*proto.Message{{
- Role: "assistant",
- Content: &proto.Content{
- Type: &proto.Content_Text{
- Text: &proto.TextContent{
- Text: "* Deploying to " + region + ", this may take a while...",
- },
- },
- },
- }},
- }); err != nil {
+ if err := out(fmt.Sprintf("* Setting context to gke_acme-production_%s_cluster-1...", region)); err != nil {
return err
}
- if err := o(&proto.AgentOutputs{
- Messages: []*proto.Message{{
- Role: "assistant",
- Content: &proto.Content{
- Type: &proto.Content_Text{
- Text: &proto.TextContent{
- Text: "* kubectl apply -f deployment.yaml",
- },
- },
- },
- }},
- }); err != nil {
+
+ time.Sleep(500 * time.Millisecond)
+ if err := out("* Running: kubectl apply -f deployment.yaml\nnamespace/test-acme unchanged\nconfigmap/test-config created\ndeployment.apps/test-service created\nservice/test-service created"); err != nil {
return err
}
- time.Sleep(1500 * time.Millisecond)
- if err := o(&proto.AgentOutputs{
- Messages: []*proto.Message{{
- Role: "assistant",
- Content: &proto.Content{
- Type: &proto.Content_Text{
- Text: &proto.TextContent{
- Text: fmt.Sprintf("* Deployment complete. You can access the service at https://%v.test.services.acme.com", region),
- },
- },
- },
- }},
- }); err != nil {
+ time.Sleep(1000 * time.Millisecond)
+
+ for i := 0; i <= 3; i++ {
+ msg := fmt.Sprintf("* Waiting for deployment \"test-service\" rollout to finish: %d of 3 updated replicas are available...", i)
+ if i == 3 {
+ msg = "* deployment \"test-service\" successfully rolled out"
+ }
+ if err := out(msg); err != nil {
+ return err
+ }
+ time.Sleep(1000 * time.Millisecond)
+ }
+
+ if err := out(fmt.Sprintf("* Deployment complete. You can access the service at https://%v.test.services.acme.com", region)); err != nil {
return err
}
delete(pendingRegions, conf.Id)
}
+
+ history = append(history, &proto.Message{
+ Role: "user",
+ Content: &proto.Content{
+ Type: &proto.Content_Text{
+ Text: &proto.TextContent{
+ Text: "Summarize in one paragraph what we did.",
+ },
+ },
+ },
+ })
+ if _, err := exec.Exec(ctx, conversationID, "summarize", &proto.AgentStart{
+ AgentId: "gemini",
+ Messages: history,
+ }); err != nil {
+ return err
+ }
+
return nil
}
- if start.AgentConfig == nil {
- return fmt.Errorf("no config for id=%v", execID)
- }
var config KubernetesDeployAgentConfig
- if err := json.Unmarshal(start.AgentConfig, &config); err != nil {
- return err
+ if start.AgentConfig == nil {
+ config.Regions = []string{"us-central1", "us-east1", "us-west1"}
+ } else {
+ if err := json.Unmarshal(start.AgentConfig, &config); err != nil {
+ return err
+ }
}
if len(config.Regions) == 0 {
return fmt.Errorf("no regions specified")
@@ -294,7 +291,7 @@ func (a *KubernetesDeployAgent) Connect(ctx context.Context, conversationID stri
Type: &proto.Content_Confirmation{
Confirmation: &proto.ConfirmationContent{
Id: confID,
- Question: fmt.Sprintf("Picked %v region(s) to deploy, continue?", strings.Join(config.Regions, ",")),
+ Question: fmt.Sprintf("Picked %v region(s) to deploy, continue?", strings.Join(config.Regions, ", ")),
},
},
},
diff --git a/internal/experimental/testagent/docker.go b/internal/experimental/testagent/docker.go
index f329469..d3db031 100644
--- a/internal/experimental/testagent/docker.go
+++ b/internal/experimental/testagent/docker.go
@@ -16,6 +16,7 @@ package testagent
import (
"context"
+ "fmt"
"time"
"github.com/google/ax/internal/agent"
@@ -31,7 +32,7 @@ func (a *DockerBuilderAgent) Connect(ctx context.Context, conversationID string,
Content: &proto.Content{
Type: &proto.Content_Text{
Text: &proto.TextContent{
- Text: "Building the docker image now...",
+ Text: "Building the OCI image now...",
},
},
},
@@ -45,13 +46,61 @@ func (a *DockerBuilderAgent) Connect(ctx context.Context, conversationID string,
Content: &proto.Content{
Type: &proto.Content_Text{
Text: &proto.TextContent{
- Text: "* us-central1-docker.pkg.dev/acme/test/test:latest is built and is ready to push.",
+ Text: "* gcr.io/acme-test-images/test:latest is built and is ready to push.",
},
},
},
}},
})
+ fakeBlobs := []struct {
+ action string
+ sha string
+ }{
+ {"existing blob", "dd64bf2dd177757451a98fcdc999a339c35dee5d9872d8f4dc69c8f3c4dd0112"},
+ {"existing blob", "ebddc55facdc6b1f7e0f30816a5fc7cc62f38abdf76c0a8b0a0ce52085754795"},
+ {"existing blob", "fa8ae93e2b3a7478248483e942ff665efa7219c6cd72d7a03c775372076e98dc"},
+ {"existing blob", "d6b1b89eccacc15c2420b2776d72c1dae334a00805ed9af54bf2f71e4d536f28"},
+ {"existing blob", "b4e6f1bfce0a1fba2b5421041552f4a897aada9cd5680926580f9e2c6247a7ae"},
+ {"existing blob", "b839dfae01f66e15c6a8b63520557ed315bdfe036342fa7a0c537259f10d7a9a"},
+ {"existing blob", "7c12895b777bcaa8ccae0605b4de635b68fc32d60fa08f421dc3818bf55ee212"},
+ {"existing blob", "c172f21841dff4c8cf45cde46589c1c2616cefe7e819965e92e6d3475c428aa0"},
+ {"existing blob", "52630fc75a18675c530ed9eba5f55eca09b03e91bd5bc15307918bbc1a7e7296"},
+ {"existing blob", "b4242723c53fe4e094eb78569a2c15b6aafb8eb42aa9c3c2666130654a316ae2"},
+ {"existing blob", "2780920e5dbfbe103d03a583ed75345306e572ec5a48cb10361f046767d9f29a"},
+ {"existing blob", "3214acf345c0cc6bbdb56b698a41ccdefc624a09d6beb0d38b5de0b2303ecaf4"},
+ {"existing blob", "bdfd7f7e5bf6fc27e70b59101db21c3d8284d283884419dd5fe7020583bb79ca"},
+ {"existing blob", "250c06f7c38e52dc77e5c7586c3e40280dc7ff9bb9007c396e06d96736cf8542"},
+ {"existing blob", "45a0c806973c52dc77e5c7586c3e40280dc7ff9bb9007c396e06d96736cf8543"},
+ {"existing blob", "35b0c806973c52dc77e5c7586c3e40280dc7ff9bb9007c396e06d96736cf8544"},
+ {"existing blob", "25c0c806973c52dc77e5c7586c3e40280dc7ff9bb9007c396e06d96736cf8545"},
+ {"existing blob", "15d0c806973c52dc77e5c7586c3e40280dc7ff9bb9007c396e06d96736cf8546"},
+ {"existing blob", "a5e0c806973c52dc77e5c7586c3e40280dc7ff9bb9007c396e06d96736cf8547"},
+ {"existing blob", "b5f0c806973c52dc77e5c7586c3e40280dc7ff9bb9007c396e06d96736cf8548"},
+ {"existing blob", "c510c806973c52dc77e5c7586c3e40280dc7ff9bb9007c396e06d96736cf8549"},
+ {"existing blob", "d520c806973c52dc77e5c7586c3e40280dc7ff9bb9007c396e06d96736cf8540"},
+ {"existing blob", "e530c806973c52dc77e5c7586c3e40280dc7ff9bb9007c396e06d96736cf8541"},
+ {"existing blob", "f540c806973c52dc77e5c7586c3e40280dc7ff9bb9007c396e06d96736cf854a"},
+ {"pushed blob", "a317e2b795be724afc43a3105750093ad079326ee725d64289cf348b195cf11a"},
+ {"pushed blob", "65fb0778273d2c73bfd73e62557babca6989710cc76302b634487a84f69b33d4"},
+ }
+
+ for _, b := range fakeBlobs {
+ time.Sleep(100 * time.Millisecond)
+ o(&proto.AgentOutputs{
+ Messages: []*proto.Message{{
+ Role: "assistant",
+ Content: &proto.Content{
+ Type: &proto.Content_Text{
+ Text: &proto.TextContent{
+ Text: fmt.Sprintf("%s %s: sha256:%s", time.Now().Format("2006/01/02 15:04:05"), b.action, b.sha),
+ },
+ },
+ },
+ }},
+ })
+ }
+
time.Sleep(1000 * time.Millisecond)
o(&proto.AgentOutputs{
Messages: []*proto.Message{{
@@ -59,7 +108,7 @@ func (a *DockerBuilderAgent) Connect(ctx context.Context, conversationID string,
Content: &proto.Content{
Type: &proto.Content_Text{
Text: &proto.TextContent{
- Text: "* The container image is pushed.",
+ Text: "* The container image is successfully pushed.",
},
},
},
@@ -82,7 +131,7 @@ func (a *DockerMirrorAgent) Connect(ctx context.Context, conversationID string,
Content: &proto.Content{
Type: &proto.Content_Text{
Text: &proto.TextContent{
- Text: "* Starting pushing docker image now...",
+ Text: "* Validating the container image now...",
},
},
},
diff --git a/internal/gemini/gemini.go b/internal/gemini/gemini.go
index 976a187..341a3c8 100644
--- a/internal/gemini/gemini.go
+++ b/internal/gemini/gemini.go
@@ -166,7 +166,7 @@ func (t *BashTool) SystemPrompt() string {
func (t *BashTool) FuncDecl() []*genai.Tool {
osInfo := fmt.Sprintf("User's Operating System: %s (%s)", runtime.GOOS, runtime.GOARCH)
- description := fmt.Sprintf("OS specific bash execution tool. %s. Generate commands appropriate for this OS. Returns the command output or error. Never produce code, only use existing command line programs available in the system.", osInfo)
+ description := fmt.Sprintf("OS specific bash execution tool. %s. Generate commands appropriate for this OS. Never produce code, only use existing command line programs available in the system.", osInfo)
return []*genai.Tool{{
FunctionDeclarations: []*genai.FunctionDeclaration{
diff --git a/internal/gemini/gemini_planner.go b/internal/gemini/gemini_planner.go
index a9f9fcc..e86b279 100644
--- a/internal/gemini/gemini_planner.go
+++ b/internal/gemini/gemini_planner.go
@@ -18,6 +18,7 @@ import (
"context"
"fmt"
"os"
+ "strings"
"time"
"github.com/google/ax/internal/agent"
@@ -65,17 +66,19 @@ func NewGeminiPlannerAgent(ctx context.Context, registry AgentRegistry, cfg Gemi
// Default system prompt
if cfg.GeminiConfig.SystemPrompt == "" {
- cfg.GeminiConfig.SystemPrompt = `You are AX, the Primary Architect and Executor Agent in the system. Your goal is to solve the user's request as thoroughly and efficiently as possible.
-
-You have two primary ways to accomplish tasks:
-1. **Direct Execution**: You have access to a 'bash' tool to run shell commands on the system. Use this to perform work directly (e.g., creating files, running tests, searching).
-2. **Delegation**: You have access to specialized subagents (registered as function tools). Review their descriptions and delegate tasks to them if they are better suited for the job.
+ cfg.GeminiConfig.SystemPrompt = `You are AX. You are the Primary Architect and Executor Agent in the system. Your goal is to solve the user's request as thoroughly and efficiently as possible.
+You can answer your questions if there is no tool or function call you need to make.
+
+All specialized subagents available to you are registered and provided directly as standard callable function tools.
+You don't have access to shell, don't use the bash tool.
Rules for Operation:
-- **MANDATORY FIRST STEP**: You MUST first check if any available subagent is specialized for the user's request. If a specialized subagent exists, you MUST call that subagent. Do not attempt the task yourself if a subagent can handle it.
-- If no subagent is specialized, you must attempt to solve the task yourself using the 'bash' tool. Do not give up; use commands to explore, create, and verify.
-- **Clarification**: If the user's request is ambiguous or you are unclear about any requirements, stop and ask the user for clarification before proceeding with any tool calls or delegation.
-- Always be concise. Focus on action and execution results rather than conversational explanations.`
+- **DELEGATE FIRST**: Review all of your active function tool descriptions! If a tool is specialized for a delegated action (like building Docker images or deploying to Kubernetes), immediately execute that tool function. Do NOT try to perform specialized tasks yourself via shell commands if a custom agent tool exists.
+- **Clarification**: If the user's request is highly ambiguous, ask for clarification. Keep all communication crisp, direct, and focused exclusively on action.
+
+Be concise, don't come up with extra steps unless the user asks for it.
+When introducing yourself, simply reply: "I am AX, how can I help you?"
+`
}
// Fail fast if no Gemini credentials are configured. We check the three
@@ -167,11 +170,24 @@ func (p *geminiPlannerAgent) loop(ctx context.Context, conversationID string, st
if state == proto.State_STATE_PENDING {
return nil
}
+
+ // TODO(anjalisridhar): Replace it with function response
+ // for the model to be able to pick up that agent is executed.
+ start.Messages = append(start.Messages, &proto.Message{
+ Role: "assistant",
+ Content: &proto.Content{
+ Type: &proto.Content_Text{
+ Text: &proto.TextContent{
+ Text: fmt.Sprintf("This step is done by the agent %q, figure out the next step if there is one.", nextAgentID),
+ },
+ },
+ },
+ })
}
}
func (p *geminiPlannerAgent) process(ctx context.Context, start *proto.AgentStart, handler agent.OutputHandler) (agentID string, keepLooping bool, err error) {
- tools, err := agentsToTools(p.registry, p.bashTool, p.skillsTool)
+ tools, err := agentsToTools(p.registry)
if err != nil {
return "", false, fmt.Errorf("failed to convert agents to tools: %w", err)
}
@@ -235,7 +251,7 @@ func (p *geminiPlannerAgent) process(ctx context.Context, start *proto.AgentStar
Role: "model",
Content: &proto.Content{
Type: &proto.Content_Text{
- Text: &proto.TextContent{Text: part.Text},
+ Text: &proto.TextContent{Text: strings.TrimSpace(part.Text)},
},
},
}},
@@ -259,7 +275,7 @@ func (p *geminiPlannerAgent) process(ctx context.Context, start *proto.AgentStar
case "activate_skill":
return "", true, p.skillsTool.HandleCall(ctx, fc, handler)
default:
- return fc.Name, false, nil
+ return strings.ReplaceAll(fc.Name, "_", "-"), false, nil
}
}
}
@@ -335,12 +351,20 @@ func agentsToTools(registry AgentRegistry, nativeTools ...Tool) ([]*genai.Tool,
continue // Skip agents we can't get info for
}
- // Create a function declaration for this agent
+ // Set safe Gemini tool identifier logic alongside proper schema parameters
funcDecl := &genai.FunctionDeclaration{
- Name: id, // Use agent ID as function name
+ Name: strings.ReplaceAll(id, "-", "_"),
Description: fmt.Sprintf("%s, %s", info.Name, info.Description),
+ Parameters: &genai.Schema{
+ Type: genai.TypeObject,
+ Properties: map[string]*genai.Schema{
+ "request_instructions": {
+ Type: genai.TypeString,
+ Description: "Any custom instructions or directives to provide directly to the target execution sequence.",
+ },
+ },
+ },
}
-
tools = append(tools, &genai.Tool{
FunctionDeclarations: []*genai.FunctionDeclaration{funcDecl},
})
diff --git a/internal/server/server.go b/internal/server/server.go
index c53512a..57b7cd3 100644
--- a/internal/server/server.go
+++ b/internal/server/server.go
@@ -22,6 +22,7 @@ import (
"fmt"
"log/slog"
"net"
+ "sync"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
@@ -40,12 +41,15 @@ type Server struct {
controller *controller.Controller
grpcServer *grpc.Server
+ inFlight map[string]struct{}
+ inFlightMu sync.Mutex
}
// New creates a new controller server.
func New(c *controller.Controller) *Server {
return &Server{
controller: c,
+ inFlight: make(map[string]struct{}),
}
}
@@ -55,6 +59,12 @@ func (s *Server) Exec(req *proto.ExecRequest, stream grpc.ServerStreamingServer[
slog.InfoContext(ctx, "Executing...",
slog.String("conversation_id", req.ConversationId))
+ inFlight, cleanup := s.markInFlight(req.ConversationId)
+ if inFlight {
+ return status.Errorf(codes.FailedPrecondition, "conversation %q is already in flight", req.ConversationId)
+ }
+ defer cleanup()
+
outputHandler := controller.ExecHandler(func(resp *proto.ExecResponse) error {
return stream.Send(resp)
})
@@ -81,6 +91,12 @@ func (s *Server) ForkConversation(ctx context.Context, req *proto.ForkConversati
return nil, status.Errorf(codes.InvalidArgument, "dest_conversation_id is required")
}
+ inFlight, cleanup := s.markInFlight(req.DestConversationId)
+ if inFlight {
+ return nil, status.Errorf(codes.FailedPrecondition, "conversation %q is already in flight", req.DestConversationId)
+ }
+ defer cleanup()
+
destID, err := s.controller.Fork(ctx, req.SrcConversationId, req.SrcSeq, req.DestConversationId)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to fork conversation: %v", err)
@@ -96,6 +112,12 @@ func (s *Server) DeleteConversation(ctx context.Context, req *proto.DeleteConver
if req.ConversationId == "" {
return nil, status.Errorf(codes.InvalidArgument, "conversation_id is required")
}
+ inFlight, cleanup := s.markInFlight(req.ConversationId)
+ if inFlight {
+ return nil, status.Errorf(codes.FailedPrecondition, "conversation %q is already in flight", req.ConversationId)
+ }
+ defer cleanup()
+
if err := s.controller.Delete(ctx, req.ConversationId); err != nil {
return nil, status.Errorf(codes.Internal, "failed to delete conversation: %v", err)
}
@@ -135,3 +157,20 @@ func (s *Server) GracefulStop() {
s.grpcServer.GracefulStop()
}
}
+
+func (s *Server) markInFlight(id string) (exists bool, cleanup func()) {
+ s.inFlightMu.Lock()
+ defer s.inFlightMu.Unlock()
+
+ _, ok := s.inFlight[id]
+ if ok {
+ return true, func() {}
+ }
+ s.inFlight[id] = struct{}{}
+
+ return false, func() {
+ s.inFlightMu.Lock()
+ delete(s.inFlight, id)
+ s.inFlightMu.Unlock()
+ }
+}
diff --git a/manifests/ax-deployment.yaml b/manifests/ax-deployment.yaml
index 409e884..279196b 100644
--- a/manifests/ax-deployment.yaml
+++ b/manifests/ax-deployment.yaml
@@ -80,6 +80,7 @@ data:
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
stat_prefix: ingress_http
+ stream_idle_timeout: 0s
generate_request_id: true
access_log:
- name: envoy.access_loggers.stdout
@@ -119,6 +120,7 @@ data:
route:
cluster: dynamic_forward_proxy_cluster
timeout: 0s
+ idle_timeout: 0s # Support uninterrupted persistent stream socket bounds smoothly
typed_per_filter_config:
envoy.filters.http.dynamic_forward_proxy:
"@type": type.googleapis.com/envoy.extensions.filters.http.dynamic_forward_proxy.v3.PerRouteConfig
diff --git a/manifests/ax-service.yaml b/manifests/ax-service.yaml
index f0555ad..3582c8a 100644
--- a/manifests/ax-service.yaml
+++ b/manifests/ax-service.yaml
@@ -17,6 +17,8 @@ kind: Service
metadata:
name: ax-router
namespace: ax
+ annotations:
+ cloud.google.com/backend-config: '{"default": "ax-backend-config"}'
spec:
type: LoadBalancer
selector:
@@ -24,3 +26,11 @@ spec:
ports:
- port: 443
targetPort: 8080
+---
+apiVersion: cloud.google.com/v1
+kind: BackendConfig
+metadata:
+ name: ax-backend-config
+ namespace: ax
+spec:
+ timeoutSec: 3600 # an hour