Agent Executor (AX) is Google's open agentic orchestration runtime
Go
Initial commit of the Substrate refactor (#17)
Jaana Dogan4d04e36470eb
diff --git a/Makefile b/Makefileindex dc3615b..d4ba6bd 100644--- a/Makefile+++ b/Makefile@@ -74,10 +74,14 @@ axepp-image:@echo "Building axepp container image with ko..."GOFLAGS="-tags=ate" ko build --base-import-paths ./cmd/axepp+axharness-image:+ @echo "Building axharness container image with ko..."+ ko build --base-import-paths ./cmd/axharness+ax-shell-image:# Used to debug ax servers within a cluster.@echo "Building ax shell container image with ko using busybox..."KO_DOCKER_REPO=$(KO_DOCKER_REPO)/ax-shell KO_DEFAULTBASEIMAGE=busybox:1.36 GOFLAGS="-tags=ate" ko build --base-import-paths ./cmd/ax# Build all container images-images: ax-image axepp-image ax-shell-image+images: ax-image axepp-image axharness-image ax-shell-imagediff --git a/cmd/axharness/main.go b/cmd/axharness/main.gonew file mode 100644index 0000000..f4fbd3b--- /dev/null+++ b/cmd/axharness/main.go@@ -0,0 +1,61 @@+// 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 main++import (+ "flag"+ "fmt"+ "log"+ "net"+ "os"+ "os/signal"+ "syscall"++ "google.golang.org/grpc"++ "github.com/google/ax/proto"+)++var (+ port = flag.Int("port", 50053, "The port for the gRPC HarnessService to listen on")+)++func main() {+ flag.Parse()++ lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))+ if err != nil {+ log.Fatalf("Failed to listen on port :%d: %v", *port, err)+ }++ // Start gRPC Server+ grpcServer := grpc.NewServer()+ harnessServer := NewHarnessServiceServer()+ proto.RegisterHarnessServiceServer(grpcServer, harnessServer)++ // Graceful shutdown handling+ sigChan := make(chan os.Signal, 1)+ signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)+ go func() {+ <-sigChan+ log.Println("\nReceived shutdown signal, stopping gRPC HarnessService server gracefully...")+ grpcServer.GracefulStop()+ }()++ log.Printf("gRPC HarnessService listening on port :%d...\n", *port)+ if err := grpcServer.Serve(lis); err != nil {+ log.Fatalf("Failed to serve gRPC: %v", err)+ }+}diff --git a/cmd/axharness/service.go b/cmd/axharness/service.gonew file mode 100644index 0000000..76fe954--- /dev/null+++ b/cmd/axharness/service.go@@ -0,0 +1,63 @@+// 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 main++import (+ "io"++ "github.com/google/ax/proto"+)++// HarnessServiceServer implements the gRPC proto.HarnessServiceServer interface.+type HarnessServiceServer struct {+ proto.UnimplementedHarnessServiceServer+}++// NewHarnessServiceServer creates a new HarnessServiceServer.+func NewHarnessServiceServer() *HarnessServiceServer {+ return &HarnessServiceServer{}+}++// Connect implements the bidirectional gRPC streaming capability.+// It receives client inputs and responds only with "Hello world".+func (s *HarnessServiceServer) Connect(stream proto.HarnessService_ConnectServer) error {+ for {+ _, err := stream.Recv()+ if err == io.EOF {+ return nil+ }+ if err != nil {+ return err+ }++ err = stream.Send(&proto.HarnessMessage{+ Messages: []*proto.Message{+ {+ Role: "assistant",+ Content: &proto.Content{+ Type: &proto.Content_Text{+ Text: &proto.TextContent{+ Text: "Hello world",+ },+ },+ },+ },+ },+ })+ if err != nil {+ return err+ }+ }+}diff --git a/internal/SUBSTRATE_REFACTOR_CLEANUPS.md b/internal/SUBSTRATE_REFACTOR_CLEANUPS.mdnew file mode 100644index 0000000..7eb1c37--- /dev/null+++ b/internal/SUBSTRATE_REFACTOR_CLEANUPS.md@@ -0,0 +1,6 @@+* Make internal/manifests/ax-deployment2.yaml the new templated ax-deployment.yaml.tmpl.+* Remove harnesstest package.+* Update HarnessService with the actual protocol.+* Remove axepp.+* Remove ate build tag.+* Remove harnessHandler once Exec RPC is revisited.diff --git a/internal/controller/registry_ate.go b/internal/controller/registry_ate.goindex 938f5dc..2443089 100644--- a/internal/controller/registry_ate.go+++ b/internal/controller/registry_ate.go@@ -1,5 +1,3 @@-//go:build ate-// Copyright 2026 Google LLC//// Licensed under the Apache License, Version 2.0 (the "License");diff --git a/internal/controller/registry_noate.go b/internal/controller/registry_noate.godeleted file mode 100644index 9f37be5..0000000--- a/internal/controller/registry_noate.go+++ /dev/null@@ -1,29 +0,0 @@-//go:build !ate--// 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 controller--import (- "context"- "fmt"-- "github.com/google/ax/internal/config"-)--// RegisterATE returns an error stating that ATE support is not compiled in.-func (r *Registry) RegisterATE(ctx context.Context, ateTarget string, cfg config.SubstrateAgentConfig) error {- return fmt.Errorf("ATE support not compiled in; rebuild with -tags ate")-}diff --git a/internal/controller2/controller.go b/internal/controller2/controller.gonew file mode 100644index 0000000..6095515--- /dev/null+++ b/internal/controller2/controller.go@@ -0,0 +1,192 @@+// 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 controller implements the single-writer orchestrator that coordinates+// agentic loops, manages executions, and communicates with local and remote agents.+package controller2++import (+ "context"+ "fmt"++ "github.com/google/ax/internal/controller/executor"+ "github.com/google/ax/internal/harness/harnesstest"+ "github.com/google/ax/proto"+ "github.com/google/uuid"+)++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 {+ registry *Registry+ eventLog executor.EventLog+}++// Config configures the controller.+type Config struct {+ EventLogBuilder executor.EventLogBuilder+}++// New creates a new controller instance.+func New(ctx context.Context, cfg Config) (*Controller, error) {+ // Initialize agent registry+ registry := NewRegistry()++ if cfg.EventLogBuilder == nil {+ return nil, fmt.Errorf("event log builder is required")+ }+ eventLog, err := cfg.EventLogBuilder()+ if err != nil {+ return nil, fmt.Errorf("failed to create event log: %w", err)+ }++ return &Controller{+ registry: registry,+ eventLog: eventLog,+ }, nil+}++// Exec executes a new agentic loop execution or resumes an existing one.+// If id is empty, a UUID will be generated.+// If the execution already exists, it will be resumed with optional new inputs.+func (d *Controller) Exec(ctx context.Context, req *proto.ExecRequest, handler ExecHandler) error {+ if req.ConversationId == "" {+ return fmt.Errorf("conversation_id is required")+ }++ // TODO(jbd): Resume an incomplete execution if there exists one.+ // TODO(jbd): Enable bringing a remote harness that implements HarnessService.++ h := harnesstest.New()+ exec, err := h.Start(ctx, req.ConversationId)+ if err != nil {+ return fmt.Errorf("failed to start harness session: %w", err)+ }+ defer exec.Close(ctx)++ if err := exec.Queue(ctx, req.Inputs...); err != nil {+ return fmt.Errorf("failed to queue inputs: %w", err)+ }++ hhandler := &harnessHandler{+ execHandler: handler,+ }+ if err := exec.Run(ctx, hhandler); err != nil {+ return fmt.Errorf("harness execution turn failed: %w", err)+ }++ return nil+}++type harnessHandler struct {+ execHandler ExecHandler+}++func (a *harnessHandler) OnMessage(ctx context.Context, execID string, msg *proto.Message) error {+ if a.execHandler == nil {+ return nil+ }+ return a.execHandler(&proto.ExecResponse{+ Outputs: []*proto.Message{msg},+ })+}++func (a *harnessHandler) OnComplete(ctx context.Context, execID string) error {+ return nil+}++// Delete deletes all events for a specific conversation ID.+func (d *Controller) Delete(ctx context.Context, conversationID string) error {+ if conversationID == "" {+ return fmt.Errorf("conversation_id is required")+ }++ return d.eventLog.DeleteEvents(ctx, conversationID)+}++// Fork forks an event log from a specific conversation up to a checkpoint.+func (d *Controller) Fork(ctx context.Context, srcConversationID string, srcSeq int32, destConversationID string) (string, error) {+ if srcConversationID == "" {+ return "", fmt.Errorf("src_conversation_id is required")+ }+ // TODO(anj-s): Check whether destination ID already exists and reject collisions.+ if destConversationID == "" {+ destConversationID = uuid.NewString()+ }++ events, err := d.eventLog.Events(ctx, srcConversationID)+ if err != nil {+ return "", fmt.Errorf("failed to retrieve source events: %w", err)+ }+ if len(events) == 0 {+ return "", fmt.Errorf("source conversation %s not found or has no events", srcConversationID)+ }++ // When the caller specifies srcSeq, require that it actually exists in+ // the source event log. Without this check a typo or stale checkpoint+ // silently degrades to "fork all events", which is misleading. Walk+ // the events once: stop as soon as we pass the requested seq, and+ // truncate the slice on an exact match so the copy loop below doesn't+ // need to re-check the bound.+ if srcSeq > 0 {+ found := false+ for i, ev := range events {+ if ev.Seq == srcSeq {+ events = events[:i+1]+ found = true+ break+ }+ if ev.Seq > srcSeq {+ break+ }+ }+ if !found {+ return "", fmt.Errorf("src_seq %d not found in conversation %s", srcSeq, srcConversationID)+ }+ }++ for _, ev := range events {+ // Clone the event to update the conversation ID.+ newEvent := &proto.ConversationEvent{+ ConversationId: destConversationID,+ Seq: ev.Seq,+ ExecId: ev.ExecId,+ Messages: ev.Messages,+ State: ev.State,+ }+ if _, err := d.eventLog.Append(ctx, newEvent); err != nil {+ return "", fmt.Errorf("failed to append forked event: %w", err)+ }+ }++ return destConversationID, nil+}++// Registry returns the agent registry.+func (d *Controller) Registry() *Registry {+ return d.registry+}++// Close gracefully shuts down the controller.+func (d *Controller) Close() error {+ if err := d.eventLog.Close(); err != nil {+ return fmt.Errorf("failed to close event log: %w", err)+ }+ if err := d.registry.Close(); err != nil {+ return fmt.Errorf("failed to close registry: %w", err)+ }+ return nil+}diff --git a/internal/controller2/controller_test.go b/internal/controller2/controller_test.gonew file mode 100644index 0000000..3dae3a4--- /dev/null+++ b/internal/controller2/controller_test.go@@ -0,0 +1,83 @@+// 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 controller2++import (+ "context"+ "testing"++ "github.com/google/ax/internal/agent"+ "github.com/google/ax/internal/controller/executor"+ "github.com/google/ax/internal/controller/executor/executortest"+ "github.com/google/ax/proto"+)++type dummyAgent struct{}++func (a *dummyAgent) Connect(ctx context.Context, conversationID string, execID string, start *proto.AgentStart, e agent.Executor, o agent.OutputHandler) error {+ return nil+}++func (a *dummyAgent) Close() error { return nil }++func TestController2_ExecHelloWorld(t *testing.T) {+ ctx := context.Background()+ cid := "test-conversation-id"++ log := &executortest.MemoryEventLog{}+ c, err := New(ctx, Config{+ EventLogBuilder: func() (executor.EventLog, error) {+ return log, nil+ },+ })+ if err != nil {+ t.Fatal(err)+ }+ defer c.Close()++ var outputs []*proto.Message+ handler := ExecHandler(func(resp *proto.ExecResponse) error {+ outputs = append(outputs, resp.Outputs...)+ return nil+ })++ inputs := []*proto.Message{+ {+ Role: "user",+ Content: &proto.Content{+ Type: &proto.Content_Text{+ Text: &proto.TextContent{Text: "Trigger prompt"},+ },+ },+ },+ }++ err = c.Exec(ctx, &proto.ExecRequest{+ ConversationId: cid,+ Inputs: inputs,+ }, handler)+ if err != nil {+ t.Fatalf("Controller2.Exec failed: %v", err)+ }++ if len(outputs) != 1 {+ t.Fatalf("expected exactly 1 output message, got %d", len(outputs))+ }++ gotText := outputs[0].GetContent().GetText().GetText()+ if gotText != "Hello world" {+ t.Errorf("expected 'Hello world' output text response, got %q", gotText)+ }+}diff --git a/internal/controller2/fork_test.go b/internal/controller2/fork_test.gonew file mode 100644index 0000000..3f5fff4--- /dev/null+++ b/internal/controller2/fork_test.go@@ -0,0 +1,154 @@+// 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 controller2++import (+ "context"+ "testing"++ "github.com/google/ax/internal/controller/executor"+ "github.com/google/ax/internal/controller/executor/executortest"+ "github.com/google/ax/proto"+)++func TestController_Fork(t *testing.T) {+ ctx := context.Background()+ srcCID := "src-conv"+ destCID := "dest-conv"++ log := &executortest.MemoryEventLog{}+ // Pre-populate history+ log.AllEvents = []*proto.ConversationEvent{+ {+ ConversationId: srcCID,+ Seq: 1,+ Messages: []*proto.Message{+ {Role: "user", Content: &proto.Content{Type: &proto.Content_Text{Text: &proto.TextContent{Text: "msg 1"}}}},+ },+ State: proto.State_STATE_COMPLETED,+ },+ {+ ConversationId: srcCID,+ Seq: 2,+ Messages: []*proto.Message{+ {Role: "assistant", Content: &proto.Content{Type: &proto.Content_Text{Text: &proto.TextContent{Text: "msg 2"}}}},+ },+ State: proto.State_STATE_COMPLETED,+ },+ }++ c, err := New(ctx, Config{+ EventLogBuilder: func() (executor.EventLog, error) {+ return log, nil+ },+ })+ if err != nil {+ t.Fatal(err)+ }+ defer c.Close()++ // Case 1: Fork without seq (should copy all)+ forkedID, err := c.Fork(ctx, srcCID, 0, destCID)+ if err != nil {+ t.Fatal(err)+ }+ if forkedID != destCID {+ t.Fatalf("expected destCID %s, got %s", destCID, forkedID)+ }++ events, err := log.Events(ctx, destCID)+ if err != nil {+ t.Fatal(err)+ }+ if len(events) != 2 {+ t.Fatalf("expected 2 events, got %d", len(events))+ }+ if events[0].Seq != 1 || events[1].Seq != 2 {+ t.Errorf("sequences mismatch")+ }++ // Case 2: Fork with seq 1+ destCID2 := "dest-conv-2"+ forkedID2, err := c.Fork(ctx, srcCID, 1, destCID2)+ if err != nil {+ t.Fatal(err)+ }+ if forkedID2 != destCID2 {+ t.Fatalf("expected destCID2 %s, got %s", destCID2, forkedID2)+ }++ events2, err := log.Events(ctx, destCID2)+ if err != nil {+ t.Fatal(err)+ }+ if len(events2) != 1 {+ t.Fatalf("expected 1 event, got %d", len(events2))+ }+ if events2[0].Seq != 1 {+ t.Errorf("expected seq 1, got %d", events2[0].Seq)+ }+}++func TestController_Fork_SrcSeqNotFound(t *testing.T) {+ ctx := context.Background()+ srcCID := "src-conv"++ log := &executortest.MemoryEventLog{}+ log.AllEvents = []*proto.ConversationEvent{+ {+ ConversationId: srcCID,+ Seq: 1,+ Messages: []*proto.Message{+ {Role: "user", Content: &proto.Content{Type: &proto.Content_Text{Text: &proto.TextContent{Text: "msg 1"}}}},+ },+ State: proto.State_STATE_COMPLETED,+ },+ {+ ConversationId: srcCID,+ Seq: 2,+ Messages: []*proto.Message{+ {Role: "assistant", Content: &proto.Content{Type: &proto.Content_Text{Text: &proto.TextContent{Text: "msg 2"}}}},+ },+ State: proto.State_STATE_COMPLETED,+ },+ }++ c, err := New(ctx, Config{+ EventLogBuilder: func() (executor.EventLog, error) {+ return log, nil+ },+ })+ if err != nil {+ t.Fatal(err)+ }+ defer c.Close()++ // Non-existent src_seq must error and write nothing.+ if _, err := c.Fork(ctx, srcCID, 99, "dest-conv"); err == nil {+ t.Fatal("expected error when src_seq does not exist, got nil")+ }+ events, err := log.Events(ctx, "dest-conv")+ if err != nil {+ t.Fatal(err)+ }+ if len(events) != 0 {+ t.Fatalf("expected 0 events on failed fork, got %d", len(events))+ }++ // src_seq exactly at the max is valid and must succeed.+ if _, err := c.Fork(ctx, srcCID, 2, "dest-conv-boundary"); err != nil {+ t.Fatalf("unexpected error forking at boundary src_seq: %v", err)+ }+}diff --git a/internal/controller2/registry.go b/internal/controller2/registry.gonew file mode 100644index 0000000..373c2af--- /dev/null+++ b/internal/controller2/registry.go@@ -0,0 +1,239 @@+// 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 controller2++import (+ "context"+ "fmt"+ "strings"+ "sync"++ "github.com/google/ax/internal/agent"+ "github.com/google/ax/internal/config"+ "github.com/google/ax/internal/experimental/a2abridge"+ expagent "github.com/google/ax/internal/experimental/agent"+)++// Registry manages a collection of local and remote agents.+// It provides agent discovery, health monitoring, and load balancing.+type Registry struct {+ mu sync.RWMutex+ agents map[string]agent.Agent+ agentInfo map[string]*agent.AgentInfo+}++// NewRegistry creates a new agent registry.+func NewRegistry() *Registry {+ return &Registry{+ agents: make(map[string]agent.Agent),+ agentInfo: make(map[string]*agent.AgentInfo),+ }+}++func (r *Registry) Map() map[string]agent.Agent {+ r.mu.RLock()+ defer r.mu.RUnlock()++ return r.agents+}++// RegisterLocal registers a local (in-process) agent.+func (r *Registry) RegisterLocal(cfg config.LocalAgentConfig) error {+ r.mu.Lock()+ defer r.mu.Unlock()++ if err := validateID(cfg.ID); err != nil {+ return err+ }++ if _, ok := r.agents[cfg.ID]; ok {+ return fmt.Errorf("agent %s already registered", cfg.ID)+ }++ r.agents[cfg.ID] = cfg.Agent+ r.agentInfo[cfg.ID] = &agent.AgentInfo{+ ID: cfg.ID,+ Name: cfg.Name,+ Description: cfg.Description,+ Metadata: cfg.Metadata,+ }++ return nil+}++// RegisterRemote registers a remote agent by creating a remote agent client.+// The protocol field determines what kind of remote agent to register+// (matched case-insensitively):+// - "axp" (default): AX's proto.AgentService.+// - "a2a": A2A protocol.+func (r *Registry) RegisterRemote(ctx context.Context, cfg config.RemoteAgentConfig) error {+ r.mu.Lock()+ defer r.mu.Unlock()++ if err := validateID(cfg.ID); err != nil {+ return err+ }+ if _, ok := r.agents[cfg.ID]; ok {+ return fmt.Errorf("agent %s already registered", cfg.ID)+ }++ switch strings.ToLower(cfg.Protocol) {+ case "", "axp":+ return r.registerRemote(cfg)+ case "a2a":+ return r.registerA2A(ctx, cfg)+ default:+ return fmt.Errorf("remote agent %s: invalid protocol %q (want \"axp\" or \"a2a\")", cfg.ID, cfg.Protocol)+ }+}++func (r *Registry) registerRemote(cfg config.RemoteAgentConfig) error {+ remoteAgent, err := agent.NewRemoteAgent(agent.RemoteAgentConfig{+ Address: cfg.Address,+ Reconnect: true,+ MaxRetries: 3,+ })+ if err != nil {+ return fmt.Errorf("failed to create remote agent: %w", err)+ }+ r.agents[cfg.ID] = remoteAgent+ r.agentInfo[cfg.ID] = &agent.AgentInfo{+ ID: cfg.ID,+ Name: cfg.Name,+ Description: cfg.Description,+ Metadata: cfg.Metadata,+ }+ return nil+}++// Creates an A2A-protocol agent client. The agent's AgentCard is resolved at+// registration time and used to populate the agent's information.+func (r *Registry) registerA2A(ctx context.Context, cfg config.RemoteAgentConfig) error {+ a2aAgent, err := expagent.NewA2AAgent(ctx, expagent.A2AAgentConfig{+ ID: cfg.ID,+ Address: cfg.Address,+ Auth: cfg.Auth,+ Headers: cfg.Headers,+ Stateless: cfg.A2A.Stateless,+ })+ if err != nil {+ return fmt.Errorf("failed to create a2a agent: %w", err)+ }+ name, description := a2abridge.AgentMetadataFromCard(a2aAgent.Card(), cfg.Name, cfg.Description)+ r.agents[cfg.ID] = a2aAgent+ r.agentInfo[cfg.ID] = &agent.AgentInfo{+ ID: cfg.ID,+ Name: name,+ Description: description,+ Metadata: cfg.Metadata,+ }+ return nil+}++// RegisterColab registers a Colab agent that executes a local Python file+// on a remote Colab session via the colab CLI.+func (r *Registry) RegisterColab(cfg config.ColabAgentConfig) error {+ r.mu.Lock()+ defer r.mu.Unlock()++ if err := validateID(cfg.ID); err != nil {+ return err+ }++ if _, ok := r.agents[cfg.ID]; ok {+ return fmt.Errorf("agent %s already registered", cfg.ID)+ }++ colabAgent, err := expagent.NewColabAgent(expagent.ColabAgentConfig{+ ID: cfg.ID,+ LocalFile: cfg.LocalFile,+ DriveFile: cfg.DriveFile,+ Accelerator: cfg.Accelerator,+ DriveMountPath: cfg.DriveMountPath,+ Requirements: cfg.Requirements,+ InputFlag: cfg.InputFlag,+ OutputImage: cfg.OutputImage,+ OutputDrivePath: cfg.OutputDrivePath,+ })+ if err != nil {+ return fmt.Errorf("failed to create colab agent: %w", err)+ }++ r.agents[cfg.ID] = colabAgent+ r.agentInfo[cfg.ID] = &agent.AgentInfo{+ ID: cfg.ID,+ Name: cfg.Name,+ Description: cfg.Description,+ Metadata: cfg.Metadata,+ }++ return nil+}++// Get retrieves an agent by ID.+func (r *Registry) Get(id string) (agent.Agent, error) {+ r.mu.RLock()+ defer r.mu.RUnlock()++ a, exists := r.agents[id]+ if !exists {+ return nil, fmt.Errorf("agent %s not found", id)+ }++ return a, nil+}++// GetInfo retrieves agent metadata by ID.+func (r *Registry) GetInfo(id string) (*agent.AgentInfo, error) {+ r.mu.RLock()+ defer r.mu.RUnlock()++ info, ok := r.agentInfo[id]+ if !ok {+ return nil, fmt.Errorf("agent %s not found", id)+ }++ return info, nil+}++// List returns all registered agent IDs.+func (r *Registry) List() []string {+ r.mu.RLock()+ defer r.mu.RUnlock()++ ids := make([]string, 0, len(r.agents))+ for id := range r.agents {+ ids = append(ids, id)+ }++ return ids+}++// Close stops the registry and closes all agents.+func (r *Registry) Close() error {++ r.mu.Lock()+ defer r.mu.Unlock()++ // Close all agents+ var firstErr error+ for id, a := range r.agents {+ if err := a.Close(); err != nil && firstErr == nil {+ firstErr = fmt.Errorf("failed to close agent %s: %w", id, err)+ }+ }++ return firstErr+}diff --git a/internal/controller2/registry_ate.go b/internal/controller2/registry_ate.gonew file mode 100644index 0000000..b72181d--- /dev/null+++ b/internal/controller2/registry_ate.go@@ -0,0 +1,62 @@+// 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 controller2++import (+ "context"+ "fmt"++ "github.com/google/ax/internal/agent"+ "github.com/google/ax/internal/config"+ expagent "github.com/google/ax/internal/experimental/agent"+)++// RegisterATE registers an ATE agent by creating an ATE agent client.+func (r *Registry) RegisterATE(ctx context.Context, ateTarget string, cfg config.SubstrateAgentConfig) error {+ r.mu.Lock()+ defer r.mu.Unlock()++ if err := validateID(cfg.ID); err != nil {+ return err+ }++ if _, ok := r.agents[cfg.ID]; ok {+ return fmt.Errorf("agent %s already registered", cfg.ID)+ }++ // Create ATE agent client+ substrateAgent, err := expagent.NewSubstrateAgent(ateTarget, expagent.SubstrateAgentConfig{+ ID: cfg.ID,+ Namespace: cfg.Namespace,+ Template: cfg.Template,+ Port: cfg.Port,+ Protocol: cfg.Protocol,+ Auth: cfg.Auth,+ Headers: cfg.Headers,+ })+ if err != nil {+ return fmt.Errorf("failed to create ATE agent: %w", err)+ }++ r.agents[cfg.ID] = substrateAgent+ r.agentInfo[cfg.ID] = &agent.AgentInfo{+ ID: cfg.ID,+ Name: cfg.Name,+ Description: cfg.Description,+ Metadata: cfg.Metadata,+ }++ return nil+}diff --git a/internal/controller2/registry_test.go b/internal/controller2/registry_test.gonew file mode 100644index 0000000..9052f2a--- /dev/null+++ b/internal/controller2/registry_test.go@@ -0,0 +1,75 @@+// 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 controller2++// TODO(lhuan): Setup a better automated testing framework++import (+ "context"+ "fmt"+ "net"+ "testing"++ "google.golang.org/grpc"++ "github.com/google/ax/internal/config"+ "github.com/google/ax/proto"+)++type mockAgentServer struct {+ proto.UnimplementedAgentServiceServer+ healthy bool+}++func startMockGRPCServer(t *testing.T, healthy bool) (string, func()) {+ lis, err := net.Listen("tcp", "localhost:0")+ if err != nil {+ t.Fatalf("failed to listen: %v", err)+ }+ s := grpc.NewServer()+ proto.RegisterAgentServiceServer(s, &mockAgentServer{healthy: healthy})+ go func() {+ if err := s.Serve(lis); err != nil {+ // server might be closed+ }+ }()+ return lis.Addr().String(), func() {+ s.Stop()+ lis.Close()+ }+}++func TestRegistry_GracefulShutdown(t *testing.T) {+ r := NewRegistry()++ address, cleanup := startMockGRPCServer(t, true)+ defer cleanup()++ // Register multiple agents to create workload+ for i := range 50 {+ err := r.RegisterRemote(context.Background(), config.RemoteAgentConfig{+ ID: fmt.Sprintf("remote-shutdown-test-%d", i),+ Name: "Shutdown Test Remote",+ Address: address,+ })+ if err != nil {+ t.Fatalf("Failed to register remote agent for shutdown test: %v", err)+ }+ }++ // Close should return specific errors for failed agents, but NOT panic or deadlock+ // We are testing for absence of panic/deadlock here.+ _ = r.Close()+}diff --git a/internal/controller2/validation.go b/internal/controller2/validation.gonew file mode 100644index 0000000..4f71a74--- /dev/null+++ b/internal/controller2/validation.go@@ -0,0 +1,46 @@+// 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 controller2++import (+ "errors"+ "fmt"+ "regexp"+ "strings"+)++var reservedAgentIDs = map[string]struct{}{+ "gemini": {},+ "__planner": {},+}++var validIDRegex = regexp.MustCompile(`^[A-Za-z0-9\-_]+$`)++// validateID checks if an ID contains allowed characters and is not reserved.+func validateID(id string) error {+ if id == "" {+ return errors.New("empty ID")+ }++ if !validIDRegex.MatchString(id) {+ return fmt.Errorf("invalid ID %q: must only contain A-Z, a-z, 0-9, -, and _", id)+ }++ if _, isReserved := reservedAgentIDs[strings.ToLower(id)]; isReserved {+ return fmt.Errorf("agent ID %q is reserved", id)+ }++ return nil+}diff --git a/internal/controller2/validation_test.go b/internal/controller2/validation_test.gonew file mode 100644index 0000000..16c15d0--- /dev/null+++ b/internal/controller2/validation_test.go@@ -0,0 +1,92 @@+// 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 controller2++import (+ "testing"+)++func TestValidateID(t *testing.T) {+ tests := []struct {+ name string+ id string+ wantErr bool+ }{+ {+ name: "valid lowercase",+ id: "task123",+ wantErr: false,+ },+ {+ name: "valid mixed",+ id: "Task-ID_123",+ wantErr: false,+ },+ {+ name: "valid simple",+ id: "Task-ID",+ wantErr: false,+ },+ {+ name: "valid underscore",+ id: "task_id",+ wantErr: false,+ },+ {+ name: "invalid space",+ id: "task id",+ wantErr: true,+ },+ {+ name: "invalid char",+ id: "task!",+ wantErr: true,+ },+ {+ name: "empty",+ id: "",+ wantErr: true,+ },+ {+ name: "reserved gemini",+ id: "gemini",+ wantErr: true,+ },+ {+ name: "reserved gemini mixed case",+ id: "Gemini",+ wantErr: true,+ },+ {+ name: "reserved __planner",+ id: "__planner",+ wantErr: true,+ },+ {+ name: "reserved __planner mixed case",+ id: "__Planner",+ wantErr: true,+ },+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ err := validateID(tt.id)+ if (err != nil) != tt.wantErr {+ t.Errorf("validateID(%q) error = %v, wantErr %v", tt.id, err, tt.wantErr)+ }+ })+ }+}diff --git a/internal/experimental/agent/ate.go b/internal/experimental/agent/ate.goindex a547424..8197b43 100644--- a/internal/experimental/agent/ate.go+++ b/internal/experimental/agent/ate.go@@ -1,5 +1,3 @@-//go:build ate-// Copyright 2026 Google LLC//// Licensed under the Apache License, Version 2.0 (the "License");diff --git a/internal/experimental/k8s/ate/client.go b/internal/experimental/k8s/ate/client.goindex de4d930..8f36a17 100644--- a/internal/experimental/k8s/ate/client.go+++ b/internal/experimental/k8s/ate/client.go@@ -1,5 +1,3 @@-//go:build ate-// Copyright 2026 Google LLC//// Licensed under the Apache License, Version 2.0 (the "License");@@ -14,6 +12,7 @@// See the License for the specific language governing permissions and// limitations under the License.+// Package ate provides a client for the Agent Substrate Control API.package ateimport (@@ -57,10 +56,10 @@ func NewClient(ns, template, target string, opts ...grpc.DialOption) (*Client, e}// CreateActor creates a new actor.-func (c *Client) CreateActor(ctx context.Context, execID string) (*ateapipb.CreateActorResponse, error) {+func (c *Client) CreateActor(ctx context.Context, id string) (*ateapipb.CreateActorResponse, error) {client := ateapipb.NewControlClient(c.conn)resp, err := client.CreateActor(ctx, &ateapipb.CreateActorRequest{- ActorId: execID,+ ActorId: id,ActorTemplateNamespace: c.namespace,ActorTemplateName: c.template,})@@ -71,10 +70,10 @@ func (c *Client) CreateActor(ctx context.Context, execID string) (*ateapipb.Crea}// SuspendActor suspends the actor.-func (c *Client) SuspendActor(ctx context.Context, execID string) (*ateapipb.SuspendActorResponse, error) {+func (c *Client) SuspendActor(ctx context.Context, id string) (*ateapipb.SuspendActorResponse, error) {client := ateapipb.NewControlClient(c.conn)resp, err := client.SuspendActor(ctx, &ateapipb.SuspendActorRequest{- ActorId: execID,+ ActorId: id,})if err != nil {return nil, fmt.Errorf("error when calling Control.SuspendActor: %w", err)diff --git a/internal/experimental/k8s/ate/doc.go b/internal/experimental/k8s/ate/doc.godeleted file mode 100644index 5a9dc83..0000000--- a/internal/experimental/k8s/ate/doc.go+++ /dev/null@@ -1,16 +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 ate provides a client for the SubstrATE Control API.-package atediff --git a/internal/harness/harnesstest/harnesstest.go b/internal/harness/harnesstest/harnesstest.gonew file mode 100644index 0000000..77990b9--- /dev/null+++ b/internal/harness/harnesstest/harnesstest.go@@ -0,0 +1,112 @@+// 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 harnesstest++import (+ "context"+ "sync"++ "github.com/google/ax/internal/harness"+ "github.com/google/ax/proto"+ "github.com/google/uuid"+)++// TODO(jbd): Remove once the Harness refractor is done.++// Harness implements the harness.Harness interface for testing purposes.+type Harness struct {+ mu sync.Mutex+ Active map[string]*Execution+}++// New creates a new Harness instance.+func New() *Harness {+ return &Harness{+ Active: make(map[string]*Execution),+ }+}++// Start implements harness.Harness.+func (h *Harness) Start(ctx context.Context, conversationID string) (harness.Execution, error) {+ h.mu.Lock()+ defer h.mu.Unlock()++ execID := uuid.NewString()+ exec := &Execution{+ harness: h,+ conversationID: conversationID,+ id: execID,+ }+ h.Active[execID] = exec+ return exec, nil+}++// Execution implements the harness.Execution interface.+type Execution struct {+ harness *Harness+ conversationID string+ id string++ mu sync.Mutex+ queued []*proto.Message+ closed bool+}++// ID implements harness.Execution.+func (e *Execution) ID() string {+ return e.id+}++// Queue implements harness.Execution.+func (e *Execution) Queue(ctx context.Context, msg ...*proto.Message) error {+ e.mu.Lock()+ defer e.mu.Unlock()+ e.queued = append(e.queued, msg...)+ return nil+}++// Run implements harness.Execution.+// It generates a "Hello world" message and completes the turn.+func (e *Execution) Run(ctx context.Context, handler harness.Handler) error {+ msg := &proto.Message{+ Role: "assistant",+ Content: &proto.Content{+ Type: &proto.Content_Text{+ Text: &proto.TextContent{+ Text: "Hello world",+ },+ },+ },+ }++ if err := handler.OnMessage(ctx, e.id, msg); err != nil {+ return err+ }++ return handler.OnComplete(ctx, e.id)+}++// Close implements harness.Execution.+func (e *Execution) Close(ctx context.Context) error {+ e.mu.Lock()+ defer e.mu.Unlock()+ e.closed = true++ e.harness.mu.Lock()+ delete(e.harness.Active, e.id)+ e.harness.mu.Unlock()++ return nil+}diff --git a/internal/harness/substrate.go b/internal/harness/substrate.gonew file mode 100644index 0000000..9dafb9c--- /dev/null+++ b/internal/harness/substrate.go@@ -0,0 +1,180 @@+// 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 harness++import (+ "context"+ "errors"+ "fmt"+ "io"+ "log"+ "sync"+ "time"++ "google.golang.org/grpc"+ "google.golang.org/grpc/credentials/insecure"++ "github.com/google/ax/internal/experimental/k8s/ate"+ "github.com/google/ax/proto"+ "github.com/google/uuid"+)++// SubstrateHarness manages execution in a SubstrATE sandboxed actor over gRPC HarnessService.+type SubstrateHarness struct {+ ateClient *ate.Client+ port int+ dialOpts []grpc.DialOption+}++// NewSubstrateHarness creates a new SubstrateHarness.+func NewSubstrateHarness(endpoint string, namespace string, template string, port int, opts ...grpc.DialOption) (*SubstrateHarness, error) {+ if port == 0 {+ port = 50053 // Default HarnessService port+ }+ if namespace == "" {+ namespace = "ax"+ }+ if template == "" {+ template = "ax-harness-template"+ }+ client, err := ate.NewClient(namespace, template, endpoint)+ if err != nil {+ return nil, fmt.Errorf("failed to create ATE client: %w", err)+ }+ if len(opts) == 0 {+ opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))+ }+ return &SubstrateHarness{+ ateClient: client,+ port: port,+ dialOpts: opts,+ }, nil+}++// Start implements Harness interface. It creates/resumes the target actor.+func (h *SubstrateHarness) Start(ctx context.Context, conversationID string) (Execution, error) {+ if conversationID == "" {+ return nil, errors.New("SubstrateHarness needs valid conversationID")+ }++ resp, err := h.ateClient.CreateActor(ctx, conversationID)+ if err != nil {+ return nil, fmt.Errorf("failed to create substrate actor %s: %w", conversationID, err)+ }+ actor := resp.Actor+ if actor == nil {+ return nil, fmt.Errorf("received nil actor in response for %s", conversationID)+ }+ if actor.AteomPodIp == "" {+ return nil, fmt.Errorf("actor %s has no active worker IP address", conversationID)+ }++ // 2. Establish connection to the actor's worker IP+ workerAddr := fmt.Sprintf("%s:%d", actor.AteomPodIp, h.port)+ conn, err := grpc.NewClient(workerAddr, h.dialOpts...)+ if err != nil {+ return nil, fmt.Errorf("failed to dial remote harness service at %s: %w", workerAddr, err)+ }++ return &substrateExecution{+ harness: h,+ conversationID: conversationID,+ execID: uuid.NewString(),+ conn: conn,+ client: proto.NewHarnessServiceClient(conn),+ }, nil+}++type substrateExecution struct {+ harness *SubstrateHarness+ conversationID string+ execID string+ conn *grpc.ClientConn+ client proto.HarnessServiceClient++ mu sync.Mutex+ pending []*proto.Message+}++func (e *substrateExecution) ID() string {+ return e.execID+}++func (e *substrateExecution) Queue(ctx context.Context, msg ...*proto.Message) error {+ e.mu.Lock()+ defer e.mu.Unlock()+ e.pending = append(e.pending, msg...)+ return nil+}++func (e *substrateExecution) Run(ctx context.Context, handler Handler) error {+ e.mu.Lock()+ inputs := e.pending+ e.pending = nil+ e.mu.Unlock()++ stream, err := e.client.Connect(ctx)+ if err != nil {+ return fmt.Errorf("failed to open harness service stream: %w", err)+ }++ // Send inputs+ err = stream.Send(&proto.HarnessMessage{+ Messages: inputs,+ })+ if err != nil {+ return fmt.Errorf("failed to send harness inputs: %w", err)+ }++ // Close send direction to trigger server processing+ if err := stream.CloseSend(); err != nil {+ return fmt.Errorf("failed to close stream send direction: %w", err)+ }++ // Receive response stream+ for {+ resp, err := stream.Recv()+ if err == io.EOF {+ break+ }+ if err != nil {+ return fmt.Errorf("error receiving from harness stream: %w", err)+ }+ for _, m := range resp.Messages {+ if err := handler.OnMessage(ctx, e.execID, m); err != nil {+ return err+ }+ }+ }++ return handler.OnComplete(ctx, e.execID)+}++func (e *substrateExecution) Close(ctx context.Context) error {+ // Close connection+ if e.conn != nil {+ e.conn.Close()+ }++ // Suspend actor to return resource to standard standby pool+ log.Printf("Suspending SubstrATE actor for conversation %s (execution %s)", e.conversationID, e.execID)+ suspendCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)+ defer cancel()+ if _, err := e.harness.ateClient.SuspendActor(suspendCtx, e.conversationID); err != nil {+ log.Printf("Failed to suspend actor %s: %v", e.conversationID, err)+ }++ return nil+}diff --git a/internal/manifests/ax-deployment2.yaml b/internal/manifests/ax-deployment2.yamlnew file mode 100644index 0000000..0a917c0--- /dev/null+++ b/internal/manifests/ax-deployment2.yaml@@ -0,0 +1,83 @@+# 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.++# TODO(jbd): This yaml will eventually become the ax-deployment.yaml.tmpl.++apiVersion: v1+kind: Namespace+metadata:+ name: ax+---+apiVersion: ate.dev/v1alpha1+kind: WorkerPool+metadata:+ name: ax-harness-workerpool+ namespace: ax+spec:+ replicas: 5+ ateomImage: ko://github.com/agent-substrate/substrate/cmd/servers/ateom-gvisor+---+apiVersion: ate.dev/v1alpha1+kind: ActorTemplate+metadata:+ name: ax-harness-template+ namespace: ax+spec:+ workerPoolRef:+ name: ax-harness-workerpool+ namespace: ax+ runsc:+ amd64:+ url: "gs://gvisor/releases/nightly/2026-05-19/x86_64/runsc"+ sha256Hash: "a397be1abc2420d26bce6c70e6e2ff96c73aaaab929756c56f5e2089ea842b63"+ arm64:+ url: "gs://gvisor/releases/nightly/2026-05-19/aarch64/runsc"+ sha256Hash: "1ba2366ae2efceba166046f51a4104f9261c9cb72c6db8f5b3fe2dc57dea86b9"+ pauseImage: "gcr.io/gke-release/pause@sha256:bcbd57ba5653580ec647b16d8163cdd1112df3609129b01f912a8032e48265da"+ containers:+ - name: "axharness"+ image: ko://github.com/google/ax/cmd/axharness+ ports:+ - containerPort: 50053+ snapshotsConfig:+ location: gs://${BUCKET_NAME}/ax-harness/+---+apiVersion: apps/v1+kind: ReplicaSet+metadata:+ name: ax-server+ namespace: ax+ labels:+ app: ax-server+spec:+ replicas: 3+ selector:+ matchLabels:+ app: ax-server+ template:+ metadata:+ labels:+ app: ax-server+ spec:+ containers:+ - name: ax-server+ image: ko://github.com/google/ax/cmd/ax+ command: ["/ko-app/ax", "serve"]+ ports:+ - containerPort: 8494+ env:+ - name: GEMINI_API_KEY+ value: "${GEMINI_API_KEY}"+ - name: AX_SUBSTRATE+ value: "1"diff --git a/proto/ax.pb.go b/proto/ax.pb.goindex 4c07b57..344adb1 100644--- a/proto/ax.pb.go+++ b/proto/ax.pb.go@@ -715,6 +715,52 @@ func (x *HealthCheckResponse) GetMessage() string {return ""}+type HarnessMessage struct {+ state protoimpl.MessageState `protogen:"open.v1"`+ // TODO(jbd): This is a placeholder message+ // and will be replaced with the actual protocol.+ Messages []*Message `protobuf:"bytes,1,rep,name=messages,proto3" json:"messages,omitempty"`+ unknownFields protoimpl.UnknownFields+ sizeCache protoimpl.SizeCache+}++func (x *HarnessMessage) Reset() {+ *x = HarnessMessage{}+ mi := &file_proto_ax_proto_msgTypes[10]+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))+ ms.StoreMessageInfo(mi)+}++func (x *HarnessMessage) String() string {+ return protoimpl.X.MessageStringOf(x)+}++func (*HarnessMessage) ProtoMessage() {}++func (x *HarnessMessage) ProtoReflect() protoreflect.Message {+ mi := &file_proto_ax_proto_msgTypes[10]+ if x != nil {+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))+ if ms.LoadMessageInfo() == nil {+ ms.StoreMessageInfo(mi)+ }+ return ms+ }+ return mi.MessageOf(x)+}++// Deprecated: Use HarnessMessage.ProtoReflect.Descriptor instead.+func (*HarnessMessage) Descriptor() ([]byte, []int) {+ return file_proto_ax_proto_rawDescGZIP(), []int{10}+}++func (x *HarnessMessage) GetMessages() []*Message {+ if x != nil {+ return x.Messages+ }+ return nil+}+// ExecRequest for executing.type ExecRequest struct {state protoimpl.MessageState `protogen:"open.v1"`@@ -729,7 +775,7 @@ type ExecRequest struct {func (x *ExecRequest) Reset() {*x = ExecRequest{}- mi := &file_proto_ax_proto_msgTypes[10]+ mi := &file_proto_ax_proto_msgTypes[11]ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))ms.StoreMessageInfo(mi)}@@ -741,7 +787,7 @@ func (x *ExecRequest) String() string {func (*ExecRequest) ProtoMessage() {}func (x *ExecRequest) ProtoReflect() protoreflect.Message {- mi := &file_proto_ax_proto_msgTypes[10]+ mi := &file_proto_ax_proto_msgTypes[11]if x != nil {ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))if ms.LoadMessageInfo() == nil {@@ -754,7 +800,7 @@ func (x *ExecRequest) ProtoReflect() protoreflect.Message {// Deprecated: Use ExecRequest.ProtoReflect.Descriptor instead.func (*ExecRequest) Descriptor() ([]byte, []int) {- return file_proto_ax_proto_rawDescGZIP(), []int{10}+ return file_proto_ax_proto_rawDescGZIP(), []int{11}}func (x *ExecRequest) GetConversationId() string {@@ -803,7 +849,7 @@ type ExecResponse struct {func (x *ExecResponse) Reset() {*x = ExecResponse{}- mi := &file_proto_ax_proto_msgTypes[11]+ mi := &file_proto_ax_proto_msgTypes[12]ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))ms.StoreMessageInfo(mi)}@@ -815,7 +861,7 @@ func (x *ExecResponse) String() string {func (*ExecResponse) ProtoMessage() {}func (x *ExecResponse) ProtoReflect() protoreflect.Message {- mi := &file_proto_ax_proto_msgTypes[11]+ mi := &file_proto_ax_proto_msgTypes[12]if x != nil {ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))if ms.LoadMessageInfo() == nil {@@ -828,7 +874,7 @@ func (x *ExecResponse) ProtoReflect() protoreflect.Message {// Deprecated: Use ExecResponse.ProtoReflect.Descriptor instead.func (*ExecResponse) Descriptor() ([]byte, []int) {- return file_proto_ax_proto_rawDescGZIP(), []int{11}+ return file_proto_ax_proto_rawDescGZIP(), []int{12}}func (x *ExecResponse) GetOutputs() []*Message {@@ -854,7 +900,7 @@ type DeleteConversationRequest struct {func (x *DeleteConversationRequest) Reset() {*x = DeleteConversationRequest{}- mi := &file_proto_ax_proto_msgTypes[12]+ mi := &file_proto_ax_proto_msgTypes[13]ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))ms.StoreMessageInfo(mi)}@@ -866,7 +912,7 @@ func (x *DeleteConversationRequest) String() string {func (*DeleteConversationRequest) ProtoMessage() {}func (x *DeleteConversationRequest) ProtoReflect() protoreflect.Message {- mi := &file_proto_ax_proto_msgTypes[12]+ mi := &file_proto_ax_proto_msgTypes[13]if x != nil {ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))if ms.LoadMessageInfo() == nil {@@ -879,7 +925,7 @@ func (x *DeleteConversationRequest) ProtoReflect() protoreflect.Message {// Deprecated: Use DeleteConversationRequest.ProtoReflect.Descriptor instead.func (*DeleteConversationRequest) Descriptor() ([]byte, []int) {- return file_proto_ax_proto_rawDescGZIP(), []int{12}+ return file_proto_ax_proto_rawDescGZIP(), []int{13}}func (x *DeleteConversationRequest) GetConversationId() string {@@ -897,7 +943,7 @@ type DeleteConversationResponse struct {func (x *DeleteConversationResponse) Reset() {*x = DeleteConversationResponse{}- mi := &file_proto_ax_proto_msgTypes[13]+ mi := &file_proto_ax_proto_msgTypes[14]ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))ms.StoreMessageInfo(mi)}@@ -909,7 +955,7 @@ func (x *DeleteConversationResponse) String() string {func (*DeleteConversationResponse) ProtoMessage() {}func (x *DeleteConversationResponse) ProtoReflect() protoreflect.Message {- mi := &file_proto_ax_proto_msgTypes[13]+ mi := &file_proto_ax_proto_msgTypes[14]if x != nil {ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))if ms.LoadMessageInfo() == nil {@@ -922,7 +968,7 @@ func (x *DeleteConversationResponse) ProtoReflect() protoreflect.Message {// Deprecated: Use DeleteConversationResponse.ProtoReflect.Descriptor instead.func (*DeleteConversationResponse) Descriptor() ([]byte, []int) {- return file_proto_ax_proto_rawDescGZIP(), []int{13}+ return file_proto_ax_proto_rawDescGZIP(), []int{14}}type ForkConversationRequest struct {@@ -941,7 +987,7 @@ type ForkConversationRequest struct {func (x *ForkConversationRequest) Reset() {*x = ForkConversationRequest{}- mi := &file_proto_ax_proto_msgTypes[14]+ mi := &file_proto_ax_proto_msgTypes[15]ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))ms.StoreMessageInfo(mi)}@@ -953,7 +999,7 @@ func (x *ForkConversationRequest) String() string {func (*ForkConversationRequest) ProtoMessage() {}func (x *ForkConversationRequest) ProtoReflect() protoreflect.Message {- mi := &file_proto_ax_proto_msgTypes[14]+ mi := &file_proto_ax_proto_msgTypes[15]if x != nil {ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))if ms.LoadMessageInfo() == nil {@@ -966,7 +1012,7 @@ func (x *ForkConversationRequest) ProtoReflect() protoreflect.Message {// Deprecated: Use ForkConversationRequest.ProtoReflect.Descriptor instead.func (*ForkConversationRequest) Descriptor() ([]byte, []int) {- return file_proto_ax_proto_rawDescGZIP(), []int{14}+ return file_proto_ax_proto_rawDescGZIP(), []int{15}}func (x *ForkConversationRequest) GetSrcConversationId() string {@@ -999,7 +1045,7 @@ type ForkConversationResponse struct {func (x *ForkConversationResponse) Reset() {*x = ForkConversationResponse{}- mi := &file_proto_ax_proto_msgTypes[15]+ mi := &file_proto_ax_proto_msgTypes[16]ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))ms.StoreMessageInfo(mi)}@@ -1011,7 +1057,7 @@ func (x *ForkConversationResponse) String() string {func (*ForkConversationResponse) ProtoMessage() {}func (x *ForkConversationResponse) ProtoReflect() protoreflect.Message {- mi := &file_proto_ax_proto_msgTypes[15]+ mi := &file_proto_ax_proto_msgTypes[16]if x != nil {ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))if ms.LoadMessageInfo() == nil {@@ -1024,7 +1070,7 @@ func (x *ForkConversationResponse) ProtoReflect() protoreflect.Message {// Deprecated: Use ForkConversationResponse.ProtoReflect.Descriptor instead.func (*ForkConversationResponse) Descriptor() ([]byte, []int) {- return file_proto_ax_proto_rawDescGZIP(), []int{15}+ return file_proto_ax_proto_rawDescGZIP(), []int{16}}func (x *ForkConversationResponse) GetConversationId() string {@@ -1079,7 +1125,9 @@ const file_proto_ax_proto_rawDesc = "" +"\x12HealthCheckRequest\"I\n" +"\x13HealthCheckResponse\x12\x18\n" +"\ahealthy\x18\x01 \x01(\bR\ahealthy\x12\x18\n" +- "\amessage\x18\x02 \x01(\tR\amessage\"\xb4\x01\n" ++ "\amessage\x18\x02 \x01(\tR\amessage\"9\n" ++ "\x0eHarnessMessage\x12'\n" ++ "\bmessages\x18\x01 \x03(\v2\v.ax.MessageR\bmessages\"\xb4\x01\n" +"\vExecRequest\x12'\n" +"\x0fconversation_id\x18\x01 \x01(\tR\x0econversationId\x12#\n" +"\x06inputs\x18\x02 \x03(\v2\v.ax.MessageR\x06inputs\x12\x19\n" +@@ -1105,7 +1153,9 @@ const file_proto_ax_proto_rawDesc = "" +"\x0fSTATE_COMPLETED\x10\x032\x80\x01\n" +"\fAgentService\x120\n" +"\aConnect\x12\x10.ax.AgentRequest\x1a\x11.ax.AgentResponse0\x01\x12>\n" +- "\vHealthCheck\x12\x16.ax.HealthCheckRequest\x1a\x17.ax.HealthCheckResponse2@\n" ++ "\vHealthCheck\x12\x16.ax.HealthCheckRequest\x1a\x17.ax.HealthCheckResponse2G\n" ++ "\x0eHarnessService\x125\n" ++ "\aConnect\x12\x12.ax.HarnessMessage\x1a\x12.ax.HarnessMessage(\x010\x012@\n" +"\x11ControllerService\x12+\n" +"\x04Exec\x12\x0f.ax.ExecRequest\x1a\x10.ax.ExecResponse0\x012\xb9\x01\n" +"\x13ConversationService\x12S\n" +@@ -1125,7 +1175,7 @@ func file_proto_ax_proto_rawDescGZIP() []byte {}var file_proto_ax_proto_enumTypes = make([]protoimpl.EnumInfo, 1)-var file_proto_ax_proto_msgTypes = make([]protoimpl.MessageInfo, 16)+var file_proto_ax_proto_msgTypes = make([]protoimpl.MessageInfo, 17)var file_proto_ax_proto_goTypes = []any{(State)(0), // 0: ax.State(*AgentStart)(nil), // 1: ax.AgentStart@@ -1138,14 +1188,15 @@ var file_proto_ax_proto_goTypes = []any{(*ExecutionEvent)(nil), // 8: ax.ExecutionEvent(*HealthCheckRequest)(nil), // 9: ax.HealthCheckRequest(*HealthCheckResponse)(nil), // 10: ax.HealthCheckResponse- (*ExecRequest)(nil), // 11: ax.ExecRequest- (*ExecResponse)(nil), // 12: ax.ExecResponse- (*DeleteConversationRequest)(nil), // 13: ax.DeleteConversationRequest- (*DeleteConversationResponse)(nil), // 14: ax.DeleteConversationResponse- (*ForkConversationRequest)(nil), // 15: ax.ForkConversationRequest- (*ForkConversationResponse)(nil), // 16: ax.ForkConversationResponse- (*Content)(nil), // 17: ax.Content- (*timestamppb.Timestamp)(nil), // 18: google.protobuf.Timestamp+ (*HarnessMessage)(nil), // 11: ax.HarnessMessage+ (*ExecRequest)(nil), // 12: ax.ExecRequest+ (*ExecResponse)(nil), // 13: ax.ExecResponse+ (*DeleteConversationRequest)(nil), // 14: ax.DeleteConversationRequest+ (*DeleteConversationResponse)(nil), // 15: ax.DeleteConversationResponse+ (*ForkConversationRequest)(nil), // 16: ax.ForkConversationRequest+ (*ForkConversationResponse)(nil), // 17: ax.ForkConversationResponse+ (*Content)(nil), // 18: ax.Content+ (*timestamppb.Timestamp)(nil), // 19: google.protobuf.Timestamp}var file_proto_ax_proto_depIdxs = []int32{6, // 0: ax.AgentStart.messages:type_name -> ax.Message@@ -1153,30 +1204,33 @@ var file_proto_ax_proto_depIdxs = []int32{1, // 2: ax.AgentRequest.start:type_name -> ax.AgentStart2, // 3: ax.AgentResponse.outputs:type_name -> ax.AgentOutputs3, // 4: ax.AgentResponse.end:type_name -> ax.AgentEnd- 17, // 5: ax.Message.content:type_name -> ax.Content+ 18, // 5: ax.Message.content:type_name -> ax.Content6, // 6: ax.ConversationEvent.messages:type_name -> ax.Message0, // 7: ax.ConversationEvent.state:type_name -> ax.State6, // 8: ax.ExecutionEvent.inputs:type_name -> ax.Message6, // 9: ax.ExecutionEvent.outputs:type_name -> ax.Message0, // 10: ax.ExecutionEvent.state:type_name -> ax.State- 18, // 11: ax.ExecutionEvent.timestamp:type_name -> google.protobuf.Timestamp- 6, // 12: ax.ExecRequest.inputs:type_name -> ax.Message- 6, // 13: ax.ExecResponse.outputs:type_name -> ax.Message- 4, // 14: ax.AgentService.Connect:input_type -> ax.AgentRequest- 9, // 15: ax.AgentService.HealthCheck:input_type -> ax.HealthCheckRequest- 11, // 16: ax.ControllerService.Exec:input_type -> ax.ExecRequest- 13, // 17: ax.ConversationService.DeleteConversation:input_type -> ax.DeleteConversationRequest- 15, // 18: ax.ConversationService.ForkConversation:input_type -> ax.ForkConversationRequest- 5, // 19: ax.AgentService.Connect:output_type -> ax.AgentResponse- 10, // 20: ax.AgentService.HealthCheck:output_type -> ax.HealthCheckResponse- 12, // 21: ax.ControllerService.Exec:output_type -> ax.ExecResponse- 14, // 22: ax.ConversationService.DeleteConversation:output_type -> ax.DeleteConversationResponse- 16, // 23: ax.ConversationService.ForkConversation:output_type -> ax.ForkConversationResponse- 19, // [19:24] is the sub-list for method output_type- 14, // [14:19] is the sub-list for method input_type- 14, // [14:14] is the sub-list for extension type_name- 14, // [14:14] is the sub-list for extension extendee- 0, // [0:14] is the sub-list for field type_name+ 19, // 11: ax.ExecutionEvent.timestamp:type_name -> google.protobuf.Timestamp+ 6, // 12: ax.HarnessMessage.messages:type_name -> ax.Message+ 6, // 13: ax.ExecRequest.inputs:type_name -> ax.Message+ 6, // 14: ax.ExecResponse.outputs:type_name -> ax.Message+ 4, // 15: ax.AgentService.Connect:input_type -> ax.AgentRequest+ 9, // 16: ax.AgentService.HealthCheck:input_type -> ax.HealthCheckRequest+ 11, // 17: ax.HarnessService.Connect:input_type -> ax.HarnessMessage+ 12, // 18: ax.ControllerService.Exec:input_type -> ax.ExecRequest+ 14, // 19: ax.ConversationService.DeleteConversation:input_type -> ax.DeleteConversationRequest+ 16, // 20: ax.ConversationService.ForkConversation:input_type -> ax.ForkConversationRequest+ 5, // 21: ax.AgentService.Connect:output_type -> ax.AgentResponse+ 10, // 22: ax.AgentService.HealthCheck:output_type -> ax.HealthCheckResponse+ 11, // 23: ax.HarnessService.Connect:output_type -> ax.HarnessMessage+ 13, // 24: ax.ControllerService.Exec:output_type -> ax.ExecResponse+ 15, // 25: ax.ConversationService.DeleteConversation:output_type -> ax.DeleteConversationResponse+ 17, // 26: ax.ConversationService.ForkConversation:output_type -> ax.ForkConversationResponse+ 21, // [21:27] is the sub-list for method output_type+ 15, // [15:21] is the sub-list for method input_type+ 15, // [15:15] is the sub-list for extension type_name+ 15, // [15:15] is the sub-list for extension extendee+ 0, // [0:15] is the sub-list for field type_name}func init() { file_proto_ax_proto_init() }@@ -1195,9 +1249,9 @@ func file_proto_ax_proto_init() {GoPackagePath: reflect.TypeOf(x{}).PkgPath(),RawDescriptor: unsafe.Slice(unsafe.StringData(file_proto_ax_proto_rawDesc), len(file_proto_ax_proto_rawDesc)),NumEnums: 1,- NumMessages: 16,+ NumMessages: 17,NumExtensions: 0,- NumServices: 3,+ NumServices: 4,},GoTypes: file_proto_ax_proto_goTypes,DependencyIndexes: file_proto_ax_proto_depIdxs,diff --git a/proto/ax.proto b/proto/ax.protoindex 986a3ad..dc4a563 100644--- a/proto/ax.proto+++ b/proto/ax.proto@@ -109,6 +109,16 @@ service AgentService {rpc HealthCheck(HealthCheckRequest) returns (HealthCheckResponse);}+message HarnessMessage {+ // TODO(jbd): This is a placeholder message+ // and will be replaced with the actual protocol.+ repeated Message messages = 1;+}++service HarnessService {+ rpc Connect(stream HarnessMessage) returns (stream HarnessMessage);+}+// State represents the state of an executionenum State {STATE_UNSPECIFIED = 0; // Unspecified statediff --git a/proto/ax_grpc.pb.go b/proto/ax_grpc.pb.goindex f35669d..9f68557 100644--- a/proto/ax_grpc.pb.go+++ b/proto/ax_grpc.pb.go@@ -196,6 +196,102 @@ var AgentService_ServiceDesc = grpc.ServiceDesc{Metadata: "proto/ax.proto",}+const (+ HarnessService_Connect_FullMethodName = "/ax.HarnessService/Connect"+)++// HarnessServiceClient is the client API for HarnessService service.+//+// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.+type HarnessServiceClient interface {+ Connect(ctx context.Context, opts ...grpc.CallOption) (grpc.BidiStreamingClient[HarnessMessage, HarnessMessage], error)+}++type harnessServiceClient struct {+ cc grpc.ClientConnInterface+}++func NewHarnessServiceClient(cc grpc.ClientConnInterface) HarnessServiceClient {+ return &harnessServiceClient{cc}+}++func (c *harnessServiceClient) Connect(ctx context.Context, opts ...grpc.CallOption) (grpc.BidiStreamingClient[HarnessMessage, HarnessMessage], error) {+ cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)+ stream, err := c.cc.NewStream(ctx, &HarnessService_ServiceDesc.Streams[0], HarnessService_Connect_FullMethodName, cOpts...)+ if err != nil {+ return nil, err+ }+ x := &grpc.GenericClientStream[HarnessMessage, HarnessMessage]{ClientStream: stream}+ return x, nil+}++// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.+type HarnessService_ConnectClient = grpc.BidiStreamingClient[HarnessMessage, HarnessMessage]++// HarnessServiceServer is the server API for HarnessService service.+// All implementations must embed UnimplementedHarnessServiceServer+// for forward compatibility.+type HarnessServiceServer interface {+ Connect(grpc.BidiStreamingServer[HarnessMessage, HarnessMessage]) error+ mustEmbedUnimplementedHarnessServiceServer()+}++// UnimplementedHarnessServiceServer must be embedded to have+// forward compatible implementations.+//+// NOTE: this should be embedded by value instead of pointer to avoid a nil+// pointer dereference when methods are called.+type UnimplementedHarnessServiceServer struct{}++func (UnimplementedHarnessServiceServer) Connect(grpc.BidiStreamingServer[HarnessMessage, HarnessMessage]) error {+ return status.Errorf(codes.Unimplemented, "method Connect not implemented")+}+func (UnimplementedHarnessServiceServer) mustEmbedUnimplementedHarnessServiceServer() {}+func (UnimplementedHarnessServiceServer) testEmbeddedByValue() {}++// UnsafeHarnessServiceServer may be embedded to opt out of forward compatibility for this service.+// Use of this interface is not recommended, as added methods to HarnessServiceServer will+// result in compilation errors.+type UnsafeHarnessServiceServer interface {+ mustEmbedUnimplementedHarnessServiceServer()+}++func RegisterHarnessServiceServer(s grpc.ServiceRegistrar, srv HarnessServiceServer) {+ // If the following call pancis, it indicates UnimplementedHarnessServiceServer was+ // embedded by pointer and is nil. This will cause panics if an+ // unimplemented method is ever invoked, so we test this at initialization+ // time to prevent it from happening at runtime later due to I/O.+ if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {+ t.testEmbeddedByValue()+ }+ s.RegisterService(&HarnessService_ServiceDesc, srv)+}++func _HarnessService_Connect_Handler(srv interface{}, stream grpc.ServerStream) error {+ return srv.(HarnessServiceServer).Connect(&grpc.GenericServerStream[HarnessMessage, HarnessMessage]{ServerStream: stream})+}++// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.+type HarnessService_ConnectServer = grpc.BidiStreamingServer[HarnessMessage, HarnessMessage]++// HarnessService_ServiceDesc is the grpc.ServiceDesc for HarnessService service.+// It's only intended for direct use with grpc.RegisterService,+// and not to be introspected or modified (even as a copy)+var HarnessService_ServiceDesc = grpc.ServiceDesc{+ ServiceName: "ax.HarnessService",+ HandlerType: (*HarnessServiceServer)(nil),+ Methods: []grpc.MethodDesc{},+ Streams: []grpc.StreamDesc{+ {+ StreamName: "Connect",+ Handler: _HarnessService_Connect_Handler,+ ServerStreams: true,+ ClientStreams: true,+ },+ },+ Metadata: "proto/ax.proto",+}+const (ControllerService_Exec_FullMethodName = "/ax.ControllerService/Exec")