Skip to content

armgit / ax

Public Imported from GitHub
0

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

Go

Remove the indirection in (e *Executor) HandleCall (#140)

Jaana Dogane132714ee03b
diff --git a/internal/controller/gemini.go b/internal/controller/gemini.go
index 209545b..d45843e 100644
--- a/internal/controller/gemini.go
+++ b/internal/controller/gemini.go
@@ -357,27 +357,19 @@ func (t *SkillsTool) HandleExecute(ctx context.Context, fc *genai.FunctionCall,
}
var output string
- if fc.Name == "run_skill_script" {
- result := t.executor.HandleCall(ctx, fc)
- if result != nil && result.FunctionResponse != nil {
- resultMap := result.FunctionResponse.Response
- if body, ok := resultMap["instructions"]; ok {
- output = body.(string)
- } else if errStr, ok := resultMap["error"]; ok {
- output = "Error: " + errStr.(string)
- } else {
- if so, ok := resultMap["stdout"].(string); ok && so != "" {
- output += so
- }
- if se, ok := resultMap["stderr"].(string); ok && se != "" {
- if output != "" {
- output += "\n"
- }
- output += "Stderr: " + se
- }
- }
+ if fc.Name == "run_skill_script" || fc.Name == "activate_skill" {
+ result, err := t.executor.HandleCall(ctx, fc)
+ if err != nil {
+ output = "Error: " + err.Error()
} else {
- output = "Error: nil response from executor"
+ var parts []string
+ if result.Stdout != "" {
+ parts = append(parts, result.Stdout)
+ }
+ if result.Stderr != "" {
+ parts = append(parts, "Stderr: "+result.Stderr)
+ }
+ output = strings.Join(parts, "\n")
}
}
diff --git a/internal/skills/exec.go b/internal/skills/exec.go
index 437938e..099b286 100644
--- a/internal/skills/exec.go
+++ b/internal/skills/exec.go
@@ -16,6 +16,7 @@ package skills
import (
"context"
+ "fmt"
"io"
"os"
@@ -61,36 +62,31 @@ func NewExecutor(dir string) (*Executor, error) {
}
// HandleCall processes an 'activate_skill' or 'run_skill_script' call.
-// It returns a genai.Part containing the function response.
-func (e *Executor) HandleCall(ctx context.Context, call *genai.FunctionCall) *genai.Part {
- respond := func(v map[string]any) *genai.Part {
- return genai.NewPartFromFunctionResponse(call.Name, v)
- }
-
+func (e *Executor) HandleCall(ctx context.Context, call *genai.FunctionCall) (*ScriptResult, error) {
switch call.Name {
case "activate_skill":
name, ok := call.Args["name"].(string)
if !ok {
- return respond(map[string]any{"error": "invalid or missing 'name' argument"})
+ return nil, fmt.Errorf("invalid or missing 'name' argument")
}
s, ok := e.byName[name]
if !ok {
- return respond(map[string]any{"error": "unknown skill: " + name})
+ return nil, fmt.Errorf("unknown skill: %s", name)
}
body, err := s.Body()
if err != nil {
- return respond(map[string]any{"error": err.Error()})
+ return nil, err
}
- return respond(map[string]any{"instructions": body})
+ return &ScriptResult{Stdout: body}, nil
case "run_skill_script":
skillName, ok := call.Args["skill"].(string)
if !ok {
- return respond(map[string]any{"error": "invalid or missing 'skill' argument"})
+ return nil, fmt.Errorf("invalid or missing 'skill' argument")
}
script, ok := call.Args["script"].(string)
if !ok {
- return respond(map[string]any{"error": "invalid or missing 'script' argument"})
+ return nil, fmt.Errorf("invalid or missing 'script' argument")
}
var args []string
if raw, ok := call.Args["args"].([]any); ok {
@@ -102,21 +98,13 @@ func (e *Executor) HandleCall(ctx context.Context, call *genai.FunctionCall) *ge
}
s, ok := e.byName[skillName]
if !ok {
- return respond(map[string]any{"error": "unknown skill: " + skillName})
+ return nil, fmt.Errorf("unknown skill: %s", skillName)
}
- result, err := s.RunScript(ctx, script, args)
- if err != nil {
- return respond(map[string]any{"error": err.Error()})
- }
- return respond(map[string]any{
- "stdout": result.Stdout,
- "stderr": result.Stderr,
- "exit_code": result.ExitCode,
- })
+ return s.RunScript(ctx, script, args)
default:
- return respond(map[string]any{"error": "unknown tool: " + call.Name})
+ return nil, fmt.Errorf("unknown tool: %s", call.Name)
}
}