Skip to content

armgit / ax

Public Imported from GitHub
0

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

Go

PlanFunc and EvaluateFunc should accept a context

JBDa7063e04ace0
diff --git a/internal/controller/gemini.go b/internal/controller/gemini.go
index 19332dd..1a02265 100644
--- a/internal/controller/gemini.go
+++ b/internal/controller/gemini.go
@@ -78,9 +78,9 @@ Guidelines:
}
// Return the plan function
- return func(session *Session) (*Task, error) {
+ return func(ctx context.Context, session *Session) (*Task, error) {
// Create a context with timeout
- ctx, cancel := context.WithTimeout(context.Background(), config.Timeout)
+ ctx, cancel := context.WithTimeout(ctx, config.Timeout)
defer cancel()
// Get healthy agents
diff --git a/internal/controller/loop.go b/internal/controller/loop.go
index 2a66ffd..e15c46a 100644
--- a/internal/controller/loop.go
+++ b/internal/controller/loop.go
@@ -33,11 +33,11 @@ type LoopExecutor struct {
// PlanFunc determines the next agent task to execute.
// It receives the current session state and returns the next task.
-type PlanFunc func(session *Session) (*Task, error)
+type PlanFunc func(ctx context.Context, session *Session) (*Task, error)
// EvaluateFunc evaluates the agent's response to determine if the goal is achieved.
// Returns true if the goal is met and the loop should terminate.
-type EvaluateFunc func(session *Session, task *Task, output []*proto.Content) (bool, error)
+type EvaluateFunc func(ctx context.Context, session *Session, task *Task, output []*proto.Content) (bool, error)
// LoopConfig configures the loop executor.
type LoopConfig struct {
@@ -139,7 +139,7 @@ func (e *LoopExecutor) runLoop(ctx context.Context, session *Session) error {
}
// Phase 1: Plan - Determine next agent and action
- task, err := e.planFunc(session)
+ task, err := e.planFunc(ctx, session)
if err != nil {
session.SetState(proto.State_STATE_FAILED)
return fmt.Errorf("planning failed: %w", err)
@@ -166,7 +166,7 @@ func (e *LoopExecutor) runLoop(ctx context.Context, session *Session) error {
}
// Phase 3: Evaluate - Check if goal achieved
- goalAchieved, err := e.evaluateFunc(session, task, output)
+ goalAchieved, err := e.evaluateFunc(ctx, session, task, output)
if err != nil {
session.SetState(proto.State_STATE_FAILED)
return fmt.Errorf("evaluation failed: %w", err)
@@ -229,7 +229,7 @@ func (e *LoopExecutor) executeTask(ctx context.Context, session *Session, ag age
// defaultEvaluateFunc is a simple default evaluation function.
// It considers the goal achieved after processing one step.
-func defaultEvaluateFunc(session *Session, task *Task, output []*proto.Content) (bool, error) {
+func defaultEvaluateFunc(ctx context.Context, session *Session, task *Task, output []*proto.Content) (bool, error) {
// Simple evaluation: goal achieved if we got any output
return len(output) > 0, nil
}