Skip to content

armgit / ax

Public Imported from GitHub
0

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

Go

Reject Reserved agent IDs during registration (#334)

Daqing Yi73d7ee43ab28
diff --git a/internal/controller/controller.go b/internal/controller/controller.go
index d9c66b9..5a03c4b 100644
--- a/internal/controller/controller.go
+++ b/internal/controller/controller.go
@@ -31,7 +31,15 @@ import (
"github.com/google/uuid"
)
-const plannerAgentID = "__planner"
+const (
+ plannerAgentID = "__planner"
+ geminiAgentID = "gemini"
+)
+
+var reservedAgentIDs = map[string]struct{}{
+ plannerAgentID: {},
+ geminiAgentID: {},
+}
type ExecHandler func(resp *proto.ExecResponse) error
@@ -191,7 +199,7 @@ func (d *Controller) Exec(ctx context.Context, req *proto.ExecRequest, handler E
registry[plannerAgentID] = planner
// TODO(lhuan): consider remove this.
- registry["gemini"] = gemini.NewGeminiAgent()
+ registry[geminiAgentID] = gemini.NewGeminiAgent()
if req.AgentId == "" {
req.AgentId = plannerAgentID
diff --git a/internal/controller/validation.go b/internal/controller/validation.go
index 4148238..df7ebfe 100644
--- a/internal/controller/validation.go
+++ b/internal/controller/validation.go
@@ -18,11 +18,12 @@ import (
"errors"
"fmt"
"regexp"
+ "strings"
)
var validIDRegex = regexp.MustCompile(`^[A-Za-z0-9\-_]+$`)
-// validateID checks if an ID contains allowed characters.
+// validateID checks if an ID contains allowed characters and is not reserved.
func validateID(id string) error {
if id == "" {
return errors.New("empty ID")
@@ -31,5 +32,10 @@ func validateID(id string) error {
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/controller/validation_test.go b/internal/controller/validation_test.go
index 4b1dde1..4d4a8a9 100644
--- a/internal/controller/validation_test.go
+++ b/internal/controller/validation_test.go
@@ -59,6 +59,26 @@ func TestValidateID(t *testing.T) {
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 {