Skip to content

armgit / ax

Public Imported from GitHub
0

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

Go

Revert "Introduce "type" into agent config (#83)" (#84)

Jaana Doganc651cbccb8af
diff --git a/README.md b/README.md
index c740cf9..85b20a7 100644
--- a/README.md
+++ b/README.md
@@ -226,18 +226,19 @@ health_check:
# Agents to register on startup
agents:
- - type: "remote"
- id: "text-processing-agent"
- name: "Text Processing Agent"
- description: "An agent for text processing"
- address: "localhost:50051"
- metadata:
- version: "1.0"
- - type: "k8s_sandbox"
- id: "uppercase-sandbox-agent"
- name: "Uppercase Agent"
- description: "A secure, ephemeral cloud container for executing uppercase transformations"
- sandbox_template_ref: "uppercase-agent-template"
+ - remote:
+ id: "text-processing-agent"
+ name: "Text Processing Agent"
+ description: "An agent for text processing"
+ address: "localhost:50051"
+ metadata:
+ version: "1.0"
+ - sandbox:
+ id: "uppercase-sandbox-agent"
+ name: "Sandbox Uppercase Agent"
+ description: "A secure, ephemeral cloud container for executing uppercase transformations"
+ sandbox_template_ref: "uppercase-agent-template"
+
```
Example:
@@ -340,12 +341,12 @@ To use a Sandbox Agent, specify it in your `gar.yaml` configuration using the `s
```yaml
agents:
- - type: "k8s_sandbox"
- id: "my-sandbox-agent"
- name: "Sandbox Worker"
- description: "An ephemeral sandbox processor"
- sandbox_template_ref: "your-gke-sandbox-template-name"
- container_port: 8494
+ - sandbox:
+ id: "my-sandbox-agent"
+ name: "Sandbox Worker"
+ description: "An ephemeral sandbox processor"
+ sandbox_template_ref: "your-gke-sandbox-template-name"
+ container_port: 8494
```
#### End-to-End Example (Uppercase Agent)
@@ -374,10 +375,10 @@ kubectl apply -f examples/sandbox_agent/sandbox-template.yaml
Ensure your `gar.yaml` references this sandbox agent:
```yaml
agents:
- - type: "k8s_sandbox"
- id: "uppercase-agent"
- sandbox_template_ref: "uppercase-agent-template"
- container_port: 8494
+ - id: "uppercase-agent"
+ sandbox:
+ sandbox_template_ref: "uppercase-agent-template"
+ container_port: 8494
```
**4. Run the GAR Server**
diff --git a/agent/sandbox.go b/agent/sandbox.go
index 4e37fc3..9fd6ab9 100644
--- a/agent/sandbox.go
+++ b/agent/sandbox.go
@@ -29,9 +29,9 @@ import (
"google.golang.org/grpc/metadata"
)
-type KubernetesSandboxAgent struct {
+type SandboxAgent struct {
client *sandboxclient.Client
- config KubernetesSandboxAgentConfig
+ config SandboxAgentConfig
inCluster bool
poolName string
@@ -39,8 +39,8 @@ type KubernetesSandboxAgent struct {
activeClaims map[string]struct{}
}
-// KubernetesSandboxAgentConfig configures a sandbox agent client.
-type KubernetesSandboxAgentConfig struct {
+// SandboxAgentConfig configures a sandbox agent client.
+type SandboxAgentConfig struct {
ID string
SandboxTemplateRef string
@@ -51,7 +51,7 @@ type KubernetesSandboxAgentConfig struct {
}
// NewSandboxAgent creates a new sandbox agent logic coordinator.
-func NewSandboxAgent(ctx context.Context, config KubernetesSandboxAgentConfig) (*KubernetesSandboxAgent, error) {
+func NewSandboxAgent(ctx context.Context, config SandboxAgentConfig) (*SandboxAgent, error) {
namespace := "default"
//TODO(lhuan): allow setup in yaml
if ns := os.Getenv("POD_NAMESPACE"); ns != "" {
@@ -67,8 +67,8 @@ func NewSandboxAgent(ctx context.Context, config KubernetesSandboxAgentConfig) (
}
// newSandboxAgentWithClient allows customizing the client instantiation.
-func newSandboxAgentWithClient(ctx context.Context, client *sandboxclient.Client, config KubernetesSandboxAgentConfig) (*KubernetesSandboxAgent, error) {
- agent := &KubernetesSandboxAgent{
+func newSandboxAgentWithClient(ctx context.Context, client *sandboxclient.Client, config SandboxAgentConfig) (*SandboxAgent, error) {
+ agent := &SandboxAgent{
client: client,
config: config,
inCluster: os.Getenv("KUBERNETES_SERVICE_HOST") != "",
@@ -94,12 +94,12 @@ func newSandboxAgentWithClient(ctx context.Context, client *sandboxclient.Client
}
// HealthCheck always returns nil for ephemeral agents since health is checked during Process.
-func (a *KubernetesSandboxAgent) HealthCheck(ctx context.Context) error {
+func (a *SandboxAgent) HealthCheck(ctx context.Context) error {
// TODO: implement proper health check logic for sandbox agents.
return nil
}
-func (a *KubernetesSandboxAgent) Process(ctx context.Context, sessionID string, req *proto.ProcessRequest, handler OutputHandler) error {
+func (a *SandboxAgent) Process(ctx context.Context, sessionID string, req *proto.ProcessRequest, handler OutputHandler) error {
// Use the sessionID deterministically so interactive sessions reuse the same sandbox pod,
// rather than spawning a new pod for every exchanged message.
safeSessionID := strings.ReplaceAll(sessionID, "-", "")
@@ -231,7 +231,7 @@ func findAvailablePort() (int, error) {
// Close gracefully deletes the SandboxWarmPool if one was created,
// and shreds all active SandboxClaims generated by this agent during interactive sessions.
-func (a *KubernetesSandboxAgent) Close() error {
+func (a *SandboxAgent) Close() error {
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
diff --git a/cmd/gar/serve.go b/cmd/gar/serve.go
index c853f50..10183e5 100644
--- a/cmd/gar/serve.go
+++ b/cmd/gar/serve.go
@@ -126,18 +126,16 @@ func newControllerFromConfig(ctx context.Context, cfg *config.Config) (*controll
}
for _, agentCfg := range cfg.Agents {
- typ := controller.AgentType(agentCfg.Type)
- switch typ {
- case controller.AgentTypeKubernetesSandbox:
- if err := c.Registry().RegisterSandbox(ctx, *agentCfg.KubernetesSandboxAgentConfig); err != nil {
- return nil, fmt.Errorf("failed to register k8s_sandbox agent %s: %w", agentCfg.KubernetesSandboxAgentConfig.ID, err)
+ if agentCfg.SandboxAgentConfig != nil {
+ if err := c.Registry().RegisterSandbox(ctx, *agentCfg.SandboxAgentConfig); err != nil {
+ return nil, fmt.Errorf("failed to register sandbox agent %s: %w", agentCfg.SandboxAgentConfig.ID, err)
}
- case controller.AgentTypeRemote:
+ } else if agentCfg.RemoteAgentConfig != nil {
if err := c.Registry().RegisterRemote(*agentCfg.RemoteAgentConfig); err != nil {
return nil, fmt.Errorf("failed to register remote agent %s: %w", agentCfg.RemoteAgentConfig.ID, err)
}
- default:
- return nil, fmt.Errorf("invalid agent configuration: unsupported agent type %q", typ)
+ } else {
+ return nil, fmt.Errorf("invalid agent configuration: must specify 'sandbox' or 'remote'")
}
}
diff --git a/gar.yaml b/gar.yaml
index f5c50c4..9a53b3e 100644
--- a/gar.yaml
+++ b/gar.yaml
@@ -61,19 +61,19 @@ planner:
# List of remote or sandbox agents to register on startup.
agents:
- - type: "remote"
- id: "remote-text-processor"
- name: "Remote Text Processor"
- description: "Converts text to lowercase."
- address: "localhost:50051"
- metadata:
- version: "1.0"
- - type: "k8s_sandbox"
- id: "uppercase"
- name: "Upper Case Agent"
- description: "Converts text to uppercase."
- sandbox_template_ref: "uppercase-agent-template"
- container_port: 8494
- use_router: true
- metadata:
- version: "1.0"
+ - remote:
+ id: "remote-text-processor"
+ name: "Remote Text Processor"
+ description: "Converts text to lowercase."
+ address: "localhost:50051"
+ metadata:
+ version: "1.0"
+ - sandbox:
+ id: "uppercase"
+ name: "Upper Case Agent"
+ description: "Converts text to uppercase."
+ sandbox_template_ref: "uppercase-agent-template"
+ container_port: 8494
+ use_router: true
+ metadata:
+ version: "1.0"
diff --git a/internal/config/config.go b/internal/config/config.go
index a64e34e..0360df3 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -35,9 +35,8 @@ type Config struct {
}
type Agent struct {
- Type string `yaml:"type"`
- RemoteAgentConfig *RemoteAgentConfig `yaml:",inline"`
- KubernetesSandboxAgentConfig *SandboxAgentConfig `yaml:",inline"`
+ RemoteAgentConfig *RemoteAgentConfig `yaml:"remote,omitempty"`
+ SandboxAgentConfig *SandboxAgentConfig `yaml:"sandbox,omitempty"`
}
// HealthCheckConfig defines the configuration for agent health checks.
diff --git a/internal/controller/registry.go b/internal/controller/registry.go
index 13a428d..c2539bd 100644
--- a/internal/controller/registry.go
+++ b/internal/controller/registry.go
@@ -30,7 +30,7 @@ type AgentType string
const (
AgentTypeLocal AgentType = "local"
AgentTypeRemote AgentType = "remote"
- AgentTypeKubernetesSandbox AgentType = "k8s_sandbox"
+ AgentTypeSandbox AgentType = "sandbox"
)
// AgentInfo contains metadata about a registered agent.
@@ -149,7 +149,7 @@ func (r *Registry) RegisterSandbox(ctx context.Context, cfg config.SandboxAgentC
return fmt.Errorf("agent %s already registered", cfg.ID)
}
- sandboxAgent, err := agent.NewSandboxAgent(ctx, agent.KubernetesSandboxAgentConfig{
+ sandboxAgent, err := agent.NewSandboxAgent(ctx, agent.SandboxAgentConfig{
ID: cfg.ID,
SandboxTemplateRef: cfg.SandboxTemplateRef,
WarmPoolSize: cfg.WarmPoolSize,
@@ -165,7 +165,7 @@ func (r *Registry) RegisterSandbox(ctx context.Context, cfg config.SandboxAgentC
ID: cfg.ID,
Name: cfg.Name,
Description: cfg.Description,
- Type: AgentTypeKubernetesSandbox,
+ Type: AgentTypeSandbox,
Healthy: true,
LastHealthCheck: time.Time{},
Metadata: cfg.Metadata,