Documentation
¶
Overview ¶
Package executor provides the execution routing layer for SubAgent tasks. It routes execution requests to either local or remote (Golem) executors based on the configured execution strategy.
Architecture:
ExecutionRouter ├── LocalExecutor (wraps existing AgentRunner — current behavior) └── GolemExecutor (NEW — dispatches to remote Golem nodes)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ExecuteRequest ¶
type ExecuteRequest struct {
// AgentID is the agent to execute.
AgentID string
// SessionID is the session created for this SubAgent.
SessionID string
// Input is the task/prompt for the SubAgent.
Input string
// Strategy is the desired execution strategy.
Strategy ExecutionStrategy
// TeamID is the team this SubAgent belongs to (if any).
TeamID string
// NodeSelector is a label-based node selector for Golem execution.
NodeSelector map[string]string
// NodeAffinityPolicy controls node placement behavior.
AffinityPolicy NodeAffinityPolicy
}
ExecuteRequest extends the SubAgent execute request with routing metadata.
type ExecutionRouter ¶
type ExecutionRouter interface {
// Route selects the appropriate executor for the given request.
Route(ctx context.Context, req *ExecuteRequest) (Executor, ExecutionStrategy, error)
// RegisterExecutor registers an executor for a specific strategy.
RegisterExecutor(strategy ExecutionStrategy, executor Executor)
}
ExecutionRouter routes SubAgent execution to the appropriate executor. It supports multiple registered executors and selects based on strategy.
Design: Analogous to K8s kube-scheduler — receives a request, picks the best executor (node), and dispatches.
func NewRouter ¶
func NewRouter() ExecutionRouter
NewRouter creates a new ExecutionRouter with no executors registered.
func NewRouterWithObserver ¶
func NewRouterWithObserver(obs observer.Observer) ExecutionRouter
NewRouterWithObserver creates an ExecutionRouter with an attached Observer.
type ExecutionStrategy ¶
type ExecutionStrategy string
ExecutionStrategy defines where a SubAgent should execute.
const ( // ExecutionStrategyLocal executes the SubAgent in the local Hivemind process. ExecutionStrategyLocal ExecutionStrategy = "local" // ExecutionStrategyGolem dispatches the SubAgent to a remote Golem node. ExecutionStrategyGolem ExecutionStrategy = "golem" // ExecutionStrategyAuto lets the router decide based on resource availability. ExecutionStrategyAuto ExecutionStrategy = "auto" )
func (ExecutionStrategy) IsValid ¶
func (s ExecutionStrategy) IsValid() bool
IsValid returns true if the strategy is a known value.
type Executor ¶
type Executor interface {
// Name returns the executor identifier.
Name() string
// Execute starts a SubAgent execution.
Execute(ctx context.Context, req *ExecuteRequest) error
}
Executor abstracts the actual execution of a SubAgent. The existing AgentExecutor interface is wrapped as a LocalExecutor.
type GolemExecutor ¶
type GolemExecutor struct {
// contains filtered or unexported fields
}
GolemExecutor dispatches SubAgent tasks to remote Golem nodes. It implements the N:1 mapping: multiple SubAgents can share a single Golem node.
Core flow:
- Build Golem ScheduleRequest from SubAgent ExecuteRequest
- Apply node affinity policy (maps to ScheduleHints.Affinity)
- Submit to Golem Scheduler
- Track task→node mapping in NodeTaskIndex
- Monitor task progress asynchronously
Fault tolerance:
- Scheduling phase failure → direct fallback to LocalExecutor (no state migration needed)
- Execution phase failure → mark SubAgent as Failed, let TeamOrchestrator decide next steps
func NewGolemExecutor ¶
func NewGolemExecutor(sched scheduler.Scheduler, localFallback Executor) *GolemExecutor
NewGolemExecutor creates a GolemExecutor with the given Golem scheduler.
func NewGolemExecutorWithObserver ¶
func NewGolemExecutorWithObserver(sched scheduler.Scheduler, localFallback Executor, obs observer.Observer) *GolemExecutor
NewGolemExecutorWithObserver creates a GolemExecutor with an attached Observer.
func (*GolemExecutor) Execute ¶
func (e *GolemExecutor) Execute(ctx context.Context, req *ExecuteRequest) error
Execute dispatches the SubAgent task to a Golem node. If scheduling fails (no available nodes), it falls back to local execution.
func (*GolemExecutor) Name ¶
func (e *GolemExecutor) Name() string
type LocalExecutor ¶
type LocalExecutor struct {
// contains filtered or unexported fields
}
LocalExecutor wraps the existing AgentExecutor to implement the Executor interface. This is the adapter between the new execution routing layer and the current local SubAgent execution pipeline.
func NewLocalExecutor ¶
func NewLocalExecutor(agentExecutor subagent.AgentExecutor) *LocalExecutor
NewLocalExecutor creates a LocalExecutor wrapping the existing AgentExecutor.
func (*LocalExecutor) Execute ¶
func (e *LocalExecutor) Execute(ctx context.Context, req *ExecuteRequest) error
Execute starts a Subagent run using the existing local execution pipeline.
func (*LocalExecutor) Name ¶
func (e *LocalExecutor) Name() string
type NodeAffinityPolicy ¶
type NodeAffinityPolicy string
NodeAffinityPolicy defines node placement preferences for Golem execution. These map to the Golem Scheduler's ScheduleHints.Affinity mechanism.
const ( // NodeAffinityNone: no placement preference. NodeAffinityNone NodeAffinityPolicy = "none" // NodeAffinityPreferColocate: prefer placing on the same node as team members. NodeAffinityPreferColocate NodeAffinityPolicy = "prefer_colocate" // NodeAffinityRequireColocate: require same-node placement. NodeAffinityRequireColocate NodeAffinityPolicy = "require_colocate" // NodeAffinityPreferSpread: prefer distributing across different nodes. NodeAffinityPreferSpread NodeAffinityPolicy = "prefer_spread" // NodeAffinityRequireSpread: require different-node placement. NodeAffinityRequireSpread NodeAffinityPolicy = "require_spread" )
type NodeTaskIndex ¶
type NodeTaskIndex struct {
// contains filtered or unexported fields
}
NodeTaskIndex maintains a reverse index of task→node mappings. It supports:
- Querying all active SubAgents on a given node
- Node affinity scheduling (co-locate team members)
- Node-level resource budget control
func NewNodeTaskIndex ¶
func NewNodeTaskIndex() *NodeTaskIndex
NewNodeTaskIndex creates an empty index.
func (*NodeTaskIndex) Add ¶
func (idx *NodeTaskIndex) Add(nodeID, sessionID, teamID string)
Add records a task→node mapping.
func (*NodeTaskIndex) GetNodesByTeam ¶
func (idx *NodeTaskIndex) GetNodesByTeam(teamID string) []string
GetNodesByTeam returns all node IDs that have members of the given team.
func (*NodeTaskIndex) GetTasksOnNode ¶
func (idx *NodeTaskIndex) GetTasksOnNode(nodeID string) []string
GetTasksOnNode returns all session IDs for tasks running on a given node.
func (*NodeTaskIndex) Remove ¶
func (idx *NodeTaskIndex) Remove(sessionID string)
Remove cleans up a task mapping.