Agent Executor (AX) is Google's open agentic orchestration runtime
Go
pr1 tests (#272)
anj-se35da2c1cc5a
diff --git a/internal/controller/gemini.go b/internal/controller/gemini.goindex 2b4747b..504fadc 100644--- a/internal/controller/gemini.go+++ b/internal/controller/gemini.go@@ -19,6 +19,8 @@ import ("encoding/json""errors""fmt"+ "io"+ "os""os/exec""runtime""strings"@@ -310,11 +312,13 @@ type SkillsTool struct {func NewSkillsTool(dir string) (Tool, error) {executor, err := skills.NewExecutor(dir)if err != nil {+ // If no skills are found or the directory does not exist, fallback to a no-op tool+ // to avoid hard errors when skills are not configured or available.+ if errors.Is(err, io.EOF) || errors.Is(err, os.ErrNotExist) {+ return &NoopTool{}, nil+ }return nil, err}- if !executor.HasSkills() {- return &NoopTool{}, nil- }return &SkillsTool{executor: executor}, nil}diff --git a/internal/controller/gemini_planner_integration_test.go b/internal/controller/gemini_planner_integration_test.gonew file mode 100644index 0000000..e497b88--- /dev/null+++ b/internal/controller/gemini_planner_integration_test.go@@ -0,0 +1,82 @@+//go:build integration++// 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"+ "os"+ "testing"++ "github.com/google/ax/internal/agent"+ "github.com/google/ax/proto"+)++func TestIntegrationGeminiPlanner(t *testing.T) {+ apiKey := os.Getenv("GEMINI_API_KEY")+ if apiKey == "" {+ t.Skip("GEMINI_API_KEY not set, skipping integration test")+ }++ ctx := context.Background()+ registry := NewRegistry()++ cfg := GeminiPlannerConfig{+ MaxSteps: 5,+ }++ planner, err := NewGeminiPlannerAgent(ctx, registry, cfg)+ if err != nil {+ t.Fatal(err)+ }++ start := &proto.AgentStart{+ AgentId: "__planner",+ Messages: []*proto.Message{+ {+ Role: "user",+ Content: &proto.Content{+ Type: &proto.Content_Text{+ Text: &proto.TextContent{Text: "Hello, who are you?"},+ },+ },+ },+ },+ }++ var outputs []*proto.Message+ handler := func(resp *proto.AgentOutputs) error {+ outputs = append(outputs, resp.Messages...)+ return nil+ }++ err = planner.Connect(ctx, "test-conv", "test-exec", start, &dummyExecutor{}, handler)+ if err != nil {+ t.Fatal(err)+ }++ if len(outputs) == 0 {+ t.Fatal("expected outputs from Gemini")+ }++ t.Logf("Gemini response: %v", outputs[0].GetContent().GetText().GetText())+}++type dummyExecutor struct{}++func (e *dummyExecutor) Exec(ctx context.Context, conversationID string, execID string, start *proto.AgentStart, o agent.OutputHandler) (proto.State, error) {+ return proto.State_STATE_COMPLETED, nil+}diff --git a/internal/controller/gemini_planner_test.go b/internal/controller/gemini_planner_test.gonew file mode 100644index 0000000..ef99636--- /dev/null+++ b/internal/controller/gemini_planner_test.go@@ -0,0 +1,131 @@+// 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 (+ "testing"++ "github.com/google/ax/proto"+ "google.golang.org/protobuf/types/known/structpb"+)++func TestProtoToContents(t *testing.T) {+ inputs := []*proto.Message{+ {+ Role: "user",+ Content: &proto.Content{+ Type: &proto.Content_Text{+ Text: &proto.TextContent{Text: "hello"},+ },+ },+ },+ {+ Role: "model",+ Content: &proto.Content{+ Type: &proto.Content_ToolCall{+ ToolCall: &proto.ToolCallContent{+ Id: "call-123",+ Type: &proto.ToolCallContent_FunctionCall{+ FunctionCall: &proto.FunctionCallContent{+ Name: "test_tool",+ Arguments: &structpb.Struct{+ Fields: map[string]*structpb.Value{+ "arg1": structpb.NewStringValue("val1"),+ },+ },+ },+ },+ },+ },+ },+ },+ }++ contents := protoToContents(inputs)++ if len(contents) != 2 {+ t.Fatalf("expected 2 contents, got %d", len(contents))+ }++ if contents[0].Role != "user" {+ t.Errorf("expected role user, got %s", contents[0].Role)+ }+ if contents[0].Parts[0].Text != "hello" {+ t.Errorf("expected text hello, got %s", contents[0].Parts[0].Text)+ }++ if contents[1].Role != "model" {+ t.Errorf("expected role model, got %s", contents[1].Role)+ }+ fc := contents[1].Parts[0].FunctionCall+ if fc == nil {+ t.Fatal("expected function call")+ }+ if fc.Name != "test_tool" {+ t.Errorf("expected function name test_tool, got %s", fc.Name)+ }+}++func TestHandleConfirmationAnswer(t *testing.T) {+ inputs := []*proto.Message{+ {+ Role: "model",+ Content: &proto.Content{+ Type: &proto.Content_ToolCall{+ ToolCall: &proto.ToolCallContent{+ Id: "call-123",+ Type: &proto.ToolCallContent_FunctionCall{+ FunctionCall: &proto.FunctionCallContent{+ Name: "bash",+ Arguments: &structpb.Struct{+ Fields: map[string]*structpb.Value{+ "command": structpb.NewStringValue("ls"),+ },+ },+ },+ },+ },+ },+ },+ },+ {+ Role: "user",+ Content: &proto.Content{+ Type: &proto.Content_Confirmation{+ Confirmation: &proto.ConfirmationContent{+ Id: "call-123",+ Decision: &proto.ConfirmationContent_Approval{Approval: &proto.ApprovalDecision{Approved: true}},+ },+ },+ },+ },+ }++ p := &geminiPlannerAgent{+ bashTool: &BashTool{},+ }++ fc, approved := p.handleConfirmationAnswer(inputs)++ if fc == nil {+ t.Fatal("expected function call")+ }+ if fc.ID != "call-123" {+ t.Errorf("expected ID call-123, got %s", fc.ID)+ }+ if !approved {+ t.Error("expected approved to be true")+ }+}diff --git a/internal/controller/gemini_test.go b/internal/controller/gemini_test.gonew file mode 100644index 0000000..6a46d97--- /dev/null+++ b/internal/controller/gemini_test.go@@ -0,0 +1,99 @@+// 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 (+ "os"+ "path/filepath"+ "testing"+)++// TestNewSkillsTool_NonExistentDir verifies that NewSkillsTool returns a NoopTool+// and no error when the specified skills directory does not exist.+func TestNewSkillsTool_NonExistentDir(t *testing.T) {+ // Use a directory that definitely does not exist+ nonExistentDir := filepath.Join(t.TempDir(), "does-not-exist")++ tool, err := NewSkillsTool(nonExistentDir)+ if err != nil {+ t.Fatalf("NewSkillsTool failed for non-existent dir: %v", err)+ }++ // Verify it returned a NoopTool+ if _, ok := tool.(*NoopTool); !ok {+ t.Errorf("Expected NoopTool, got %T", tool)+ }+ if len(tool.FuncDecl()) != 0 {+ t.Errorf("Expected empty FuncDecl for NoopTool, got %d", len(tool.FuncDecl()))+ }+ if tool.SystemPrompt() != "" {+ t.Errorf("Expected empty SystemPrompt for NoopTool, got %s", tool.SystemPrompt())+ }+}++// TestNewSkillsTool_EmptyDir verifies that NewSkillsTool returns a NoopTool+// and no error when the specified skills directory contains no skills.+func TestNewSkillsTool_EmptyDir(t *testing.T) {+ // Use an empty directory+ emptyDir := t.TempDir()++ tool, err := NewSkillsTool(emptyDir)+ if err != nil {+ t.Fatalf("NewSkillsTool failed for empty dir: %v", err)+ }++ // Verify it returned a NoopTool+ if _, ok := tool.(*NoopTool); !ok {+ t.Errorf("Expected NoopTool, got %T", tool)+ }+ if len(tool.FuncDecl()) != 0 {+ t.Errorf("Expected empty FuncDecl for NoopTool, got %d", len(tool.FuncDecl()))+ }+ if tool.SystemPrompt() != "" {+ t.Errorf("Expected empty SystemPrompt for NoopTool, got %s", tool.SystemPrompt())+ }+}++// TestNewSkillsTool_WithSkills verifies that NewSkillsTool successfully creates+// a SkillsTool when valid skills are present.+func TestNewSkillsTool_WithSkills(t *testing.T) {+ tmpDir := t.TempDir()+ skillDir := filepath.Join(tmpDir, "test-skill")+ err := os.MkdirAll(filepath.Join(skillDir, "scripts"), 0755)+ if err != nil {+ t.Fatal(err)+ }++ skillContent := `---+name: test-skill+description: A test skill+---+Instructions go here.`++ err = os.WriteFile(filepath.Join(skillDir, "SKILL.md"), []byte(skillContent), 0644)+ if err != nil {+ t.Fatal(err)+ }++ tool, err := NewSkillsTool(tmpDir)+ if err != nil {+ t.Fatalf("NewSkillsTool failed: %v", err)+ }++ // Verify it returned a SkillsTool (FuncDecl should not be empty)+ if len(tool.FuncDecl()) == 0 {+ t.Error("Expected non-empty FuncDecl for SkillsTool")+ }+}