Skip to content

armgit / ax

Public Imported from GitHub
0

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

Go

Remove experimental testagent and clean up controller (#358)

Jaana Doganc1a6d14840d5
diff --git a/internal/controller/controller.go b/internal/controller/controller.go
index 5a03c4b..9d264ae 100644
--- a/internal/controller/controller.go
+++ b/internal/controller/controller.go
@@ -20,12 +20,9 @@ import (
"context"
"fmt"
"maps"
- "os"
"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"
"github.com/google/ax/proto"
"github.com/google/uuid"
@@ -81,26 +78,7 @@ func New(ctx context.Context, cfg Config) (*Controller, error) {
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{
registry: registry,
diff --git a/internal/experimental/testagent/agent.go b/internal/experimental/testagent/agent.go
deleted file mode 100644
index 6027129..0000000
--- a/internal/experimental/testagent/agent.go
+++ /dev/null
@@ -1,343 +0,0 @@
-// Copyright 2026 Google LLC
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package testagent
-
-import (
- "context"
- "crypto/rand"
- "encoding/hex"
- "encoding/json"
- "fmt"
- "strings"
- "time"
-
- "github.com/google/ax/internal/agent"
- "github.com/google/ax/internal/historyutil"
- "github.com/google/ax/proto"
- "github.com/google/uuid"
-)
-
-// Please note that this is not production code. testagent is only for testing ax.
-// and it will be deleted once we have comprehensive agents and integration tests.
-// testagent is not meant to be used in production.
-
-func Agents() map[string]agent.Agent {
- return map[string]agent.Agent{
- "coding": &CodingAgent{},
- "docker-build": &DockerBuilderAgent{},
- "docker-mirror": &DockerMirrorAgent{},
- "kubernetes-deploy": &KubernetesDeployAgent{},
- }
-}
-
-func DockerBuild() agent.Agent {
- return &DockerBuilderAgent{}
-}
-
-func KubernetesDeploy() agent.Agent {
- return &KubernetesDeployAgent{}
-}
-
-type KubernetesDeployAgentConfig struct {
- Regions []string `json:"regions"`
-}
-
-type CodingAgent struct{}
-
-// Connect handles processing of input content with callback handler.
-func (a *CodingAgent) Connect(ctx context.Context, conversationID string, execID string, start *proto.AgentStart, e agent.Executor, o agent.OutputHandler) error {
- exec := NewExecutor(e, o)
-
- var history []*proto.Message
- {
- inputs := []*proto.Message{
- {
- Role: "user",
- Content: &proto.Content{
- Type: &proto.Content_Text{
- Text: &proto.TextContent{
- Text: "Generate Cloud Run Python server code. Only show Python code, the output should be deployable as a server. We will deploy it to Kubernetes.",
- },
- },
- },
- },
- }
- inputs = append(inputs, start.Messages...)
- outputs, err := exec.Exec(ctx, conversationID, "code", &proto.AgentStart{
- AgentId: "gemini",
- Messages: inputs,
- })
- if err != nil {
- return err
- }
- history = append(inputs, outputs...)
- }
-
- {
- outputs, err := exec.Exec(ctx, conversationID, "docker", &proto.AgentStart{
- AgentId: "docker-build",
- Messages: history,
- })
- if err != nil {
- return err
- }
- history = append(history, outputs...)
- }
-
- {
- config, err := json.Marshal(&KubernetesDeployAgentConfig{
- Regions: []string{"us-central1"},
- })
- if err != nil {
- return err
- }
- outputs, err := exec.Exec(ctx, conversationID, "deploy", &proto.AgentStart{
- AgentId: "kubernetes-deploy",
- Messages: history,
- AgentConfig: config,
- })
- if err != nil {
- return err
- }
- history = append(history, outputs...)
- // User may need to take control back to confirm
- // or after decline.
- if historyutil.WaitsForUser(history) != nil {
- return nil
- }
- }
-
- {
- config, err := json.Marshal(&KubernetesDeployAgentConfig{
- Regions: []string{"europe-north1", "asia-east1", "us-west2"},
- })
- if err != nil {
- return err
- }
- outputs, err := exec.Exec(ctx, conversationID, "deploy-more", &proto.AgentStart{
- AgentId: "kubernetes-deploy",
- Messages: history,
- AgentConfig: config,
- })
- if err != nil {
- return err
- }
-
- history = append(history, outputs...)
- if historyutil.WaitsForUser(history) != nil {
- return nil
- }
- }
-
- if err := o(&proto.AgentOutputs{
- Messages: []*proto.Message{{
- Role: "assistant",
- Content: &proto.Content{
- Type: &proto.Content_Text{
- Text: &proto.TextContent{
- Text: "One last step, a summary...",
- },
- },
- },
- }},
- }); err != nil {
- return err
- }
-
- {
- history = append(history, &proto.Message{
- Role: "user",
- Content: &proto.Content{
- Type: &proto.Content_Text{
- Text: &proto.TextContent{
- Text: "Summarize what we did, and list links to the final deployment endpoints. Give instructions how to revert the deployments if needed",
- },
- },
- },
- })
- _, err := exec.Exec(ctx, conversationID, "summarize", &proto.AgentStart{
- AgentId: "gemini",
- Messages: history,
- })
- if err != nil {
- return err
- }
- }
- return nil
-}
-
-// Close gracefully shuts down the agent.
-func (a *CodingAgent) Close() error {
- return nil
-}
-
-var pendingRegions = make(map[string][]string) // not for production
-
-type KubernetesDeployAgent struct{}
-
-func (a *KubernetesDeployAgent) Connect(ctx context.Context, conversationID string, execID string, start *proto.AgentStart, e agent.Executor, o agent.OutputHandler) error {
- exec := NewExecutor(e, o)
-
- approved, conf := historyutil.HasConfirmationAnswer(start.Messages)
- if conf != nil && pendingRegions[conf.Id] != nil {
- if !approved {
- return nil
- }
-
- regions := pendingRegions[conf.Id]
- 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: text,
- },
- },
- },
- }
- 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 err := out(fmt.Sprintf("* Setting context to gke_acme-production_%s_cluster-1...", region)); err != nil {
- return err
- }
-
- 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(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
- }
-
- var config KubernetesDeployAgentConfig
- 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")
- }
-
- confID := uuid.NewString()
- pendingRegions[confID] = config.Regions
- return o(&proto.AgentOutputs{
- Messages: []*proto.Message{{
- Role: "assistant",
- Content: &proto.Content{
- Type: &proto.Content_Confirmation{
- Confirmation: &proto.ConfirmationContent{
- Id: confID,
- Question: fmt.Sprintf("Picked %v region(s) to deploy, continue?", strings.Join(config.Regions, ", ")),
- },
- },
- },
- }},
- })
-}
-
-// Close gracefully shuts down the agent.
-func (a *KubernetesDeployAgent) Close() error {
- return nil
-}
-
-type Executor struct {
- exec agent.Executor
- handler agent.OutputHandler
-}
-
-func NewExecutor(e agent.Executor, o agent.OutputHandler) *Executor {
- return &Executor{
- exec: e,
- handler: o,
- }
-}
-
-func (e *Executor) Exec(ctx context.Context, conversationID string, execID string, start *proto.AgentStart) ([]*proto.Message, error) {
- var outputs []*proto.Message
- if execID == "" {
- var err error
- execID, err = randomHex(8)
- if err != nil {
- return nil, err
- }
- }
- if _, err := e.exec.Exec(ctx, conversationID, execID, start, func(resp *proto.AgentOutputs) error {
- outputs = append(outputs, resp.Messages...)
- return e.handler(resp)
- }); err != nil {
- return nil, err
- }
- return outputs, nil
-}
-
-func randomHex(n int) (string, error) {
- bytes := make([]byte, n/2)
- if _, err := rand.Read(bytes); err != nil {
- return "", err
- }
- return hex.EncodeToString(bytes), nil
-}
diff --git a/internal/experimental/testagent/docker.go b/internal/experimental/testagent/docker.go
deleted file mode 100644
index d3db031..0000000
--- a/internal/experimental/testagent/docker.go
+++ /dev/null
@@ -1,160 +0,0 @@
-// Copyright 2026 Google LLC
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package testagent
-
-import (
- "context"
- "fmt"
- "time"
-
- "github.com/google/ax/internal/agent"
- "github.com/google/ax/proto"
-)
-
-type DockerBuilderAgent struct{}
-
-func (a *DockerBuilderAgent) Connect(ctx context.Context, conversationID string, execID string, start *proto.AgentStart, e agent.Executor, o agent.OutputHandler) error {
- o(&proto.AgentOutputs{
- Messages: []*proto.Message{{
- Role: "assistant",
- Content: &proto.Content{
- Type: &proto.Content_Text{
- Text: &proto.TextContent{
- Text: "Building the OCI image now...",
- },
- },
- },
- }},
- })
-
- time.Sleep(500 * time.Millisecond)
- o(&proto.AgentOutputs{
- Messages: []*proto.Message{{
- Role: "assistant",
- Content: &proto.Content{
- Type: &proto.Content_Text{
- Text: &proto.TextContent{
- 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{{
- Role: "assistant",
- Content: &proto.Content{
- Type: &proto.Content_Text{
- Text: &proto.TextContent{
- Text: "* The container image is successfully pushed.",
- },
- },
- },
- }},
- })
- return nil
-}
-
-// Close gracefully shuts down the agent.
-func (a *DockerBuilderAgent) Close() error {
- return nil
-}
-
-type DockerMirrorAgent struct{}
-
-func (a *DockerMirrorAgent) Connect(ctx context.Context, conversationID string, execID string, start *proto.AgentStart, e agent.Executor, o agent.OutputHandler) error {
- o(&proto.AgentOutputs{
- Messages: []*proto.Message{{
- Role: "assistant",
- Content: &proto.Content{
- Type: &proto.Content_Text{
- Text: &proto.TextContent{
- Text: "* Validating the container image now...",
- },
- },
- },
- }},
- })
-
- time.Sleep(2000 * time.Millisecond)
- o(&proto.AgentOutputs{
- Messages: []*proto.Message{{
- Role: "assistant",
- Content: &proto.Content{
- Type: &proto.Content_Text{
- Text: &proto.TextContent{
- Text: "* The container image is mirrored",
- },
- },
- },
- }},
- })
- return nil
-}
-
-// Close gracefully shuts down the agent.
-func (a *DockerMirrorAgent) Close() error {
- return nil
-}