executor

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package executor provides convergence goal execution.

Package executor provides workflow and goal execution.

Utility functions for the executor.

Session event logging functions for the executor.

Skill handling functions for the executor.

Sub-agent spawning and execution functions for the executor.

Tool execution functions for the executor.

Tracing instrumentation for the executor.

Package executor provides workflow execution with XML-structured context.

Index

Constants

View Source
const OrchestratorSystemPromptPrefix = `` /* 901-byte string literal not displayed */

OrchestratorSystemPromptPrefix returns the prefix to inject when spawn_agent is available.

View Source
const ScratchpadGuidancePrefix = `` /* 839-byte string literal not displayed */

ScratchpadGuidancePrefix is injected when scratchpad tools are available.

View Source
const SemanticMemoryGuidancePrefix = `` /* 831-byte string literal not displayed */

SemanticMemoryGuidancePrefix is injected when semantic memory tools are available.

View Source
const TersenessGuidance = `` /* 942-byte string literal not displayed */

TersenessGuidance is prepended to execution prompts to reduce verbosity.

Variables

This section is empty.

Functions

func BuildTaskContext

func BuildTaskContext(role, parentGoal, task string) string

BuildTaskContext builds XML context for a dynamic sub-agent task. All data content is escaped to prevent injection attacks.

func BuildTaskContextWithCorrection

func BuildTaskContextWithCorrection(role, parentGoal, task, correction string) string

BuildTaskContextWithCorrection builds XML context for a sub-agent task with supervisor correction. All data content is escaped to prevent injection attacks.

func BuildTaskContextWithPriorGoals

func BuildTaskContextWithPriorGoals(role, parentGoal, task string, priorGoals []GoalOutput) string

BuildTaskContextWithPriorGoals builds XML context for a sub-agent task including prior goal outputs. This ensures sub-agents have access to the workflow context, not just the raw task. All data content is escaped to prevent injection attacks.

Types

type AgentContribution

type AgentContribution struct {
	ID         string // Agent identifier
	Capability string // Agent's announced capability
	Round      int    // Which round this was (0 = first contribution from another agent)
	Output     string // The agent's output
}

AgentContribution represents an agent's output in a discuss round.

type AgentIdentity

type AgentIdentity struct {
	Name string // Agent name (e.g., "researcher", "writer", or workflow name for main)
	Role string // Agent role (for dynamic sub-agents, same as name; for static agents, defined role)
}

AgentIdentity holds agent name and role for logging/attribution.

type ConvergenceIteration

type ConvergenceIteration struct {
	N      int    // Iteration number (1-indexed)
	Output string // The output from this iteration
}

ConvergenceIteration represents a completed convergence iteration.

type ConvergenceResult

type ConvergenceResult struct {
	Converged  bool   // true if the goal converged before hitting the limit
	Iterations int    // number of iterations executed
	Output     string // final output (last substantive iteration)
}

ConvergenceResult tracks the outcome of a convergence goal.

type Executor

type Executor struct {

	// Callbacks
	OnGoalStart        func(name string)
	OnGoalComplete     func(name string, output string)
	OnToolCall         func(name string, args map[string]interface{}, result interface{}, agentRole string)
	OnToolError        func(name string, args map[string]interface{}, err error, agentRole string)
	OnLLMError         func(err error)
	OnSkillLoaded      func(name string)
	OnMCPToolCall      func(server, tool string, args map[string]interface{}, result interface{})
	OnSubAgentStart    func(name string, input map[string]string)
	OnSubAgentComplete func(name string, output string)
	OnSupervisionEvent func(stepID string, phase string, data interface{})
	// contains filtered or unexported fields
}

Executor executes workflows.

func NewExecutor

func NewExecutor(wf *agentfile.Workflow, provider llm.Provider, registry *tools.Registry, pol *policy.Policy) *Executor

NewExecutor creates a new executor.

func NewExecutorWithFactory

func NewExecutorWithFactory(wf *agentfile.Workflow, factory llm.ProviderFactory, registry *tools.Registry, pol *policy.Policy) *Executor

NewExecutorWithFactory creates an executor with a provider factory for profile support.

func (*Executor) AddUntrustedContent

func (e *Executor) AddUntrustedContent(ctx context.Context, content, source string)

AddUntrustedContent registers untrusted content with the security verifier.

func (*Executor) AddUntrustedContentWithTaint

func (e *Executor) AddUntrustedContentWithTaint(ctx context.Context, content, source string, taintedBy []string)

AddUntrustedContentWithTaint registers untrusted content with explicit taint lineage.

func (*Executor) GetConvergenceFailures

func (e *Executor) GetConvergenceFailures() map[string]int

GetConvergenceFailures returns goals that failed to converge.

func (*Executor) LogBashSecurity

func (e *Executor) LogBashSecurity(command, step string, allowed bool, reason string, durationMs int64, inputTokens, outputTokens int)

LogBashSecurity logs a bash security decision to the session. This is called by the bash security checker callback.

func (*Executor) PreFlight

func (e *Executor) PreFlight() error

PreFlight checks if the workflow can execute successfully. Returns an error if SUPERVISED HUMAN steps exist but no human connection is available.

func (*Executor) Registry

func (e *Executor) Registry() *tools.Registry

Registry returns the tool registry.

func (*Executor) Run

func (e *Executor) Run(ctx context.Context, inputs map[string]string) (*Result, error)

logEvent logs an event to the session's chronological event stream.

func (*Executor) SetDebug

func (e *Executor) SetDebug(debug bool)

SetDebug enables verbose logging of prompts, responses, and tool outputs. When disabled (default), content is redacted to prevent PII leakage in production.

func (*Executor) SetMCPManager

func (e *Executor) SetMCPManager(m *mcp.Manager)

SetMCPManager sets the MCP manager for external tool access.

func (*Executor) SetMetricsCollector

func (e *Executor) SetMetricsCollector(mc MetricsCollector)

SetObservationExtraction enables observation extraction and storage for semantic memory. SetMetricsCollector sets the metrics collector for heartbeat reporting.

func (*Executor) SetObservationExtraction

func (e *Executor) SetObservationExtraction(extractor ObservationExtractor, store ObservationStore)

func (*Executor) SetSecurityResearchScope

func (e *Executor) SetSecurityResearchScope(scope string)

SetSecurityResearchScope sets the security research scope for defensive framing. When set, system prompts will include context indicating authorized security research.

func (*Executor) SetSecurityVerifier

func (e *Executor) SetSecurityVerifier(v *security.Verifier)

SetSecurityVerifier sets the security verifier for tool call verification.

func (*Executor) SetSession

func (e *Executor) SetSession(sess *session.Session, mgr session.SessionManager)

SetSession sets the session for logging events.

func (*Executor) SetSkills

func (e *Executor) SetSkills(refs []skills.SkillRef)

SetSkills sets available skills for the executor.

func (*Executor) SetSupervision

func (e *Executor) SetSupervision(store *checkpoint.Store, supervisorProvider llm.Provider, humanAvailable bool, humanInputChan chan string)

SetSupervision configures supervision for the executor.

func (*Executor) SetTimeouts

func (e *Executor) SetTimeouts(mcp, webSearch, webFetch int)

SetTimeouts configures timeouts for network operations. Values are in seconds. Zero means use default (60s for MCP/WebFetch, 30s for WebSearch).

type GoalOutput

type GoalOutput struct {
	ID     string // Goal identifier
	Output string // The LLM's response for this goal
}

GoalOutput represents a completed goal's output for context building.

type GoalResult

type GoalResult struct {
	Output        string
	ToolCallsMade bool
}

GoalResult contains the result of executing a goal.

type MetricsCollector

type MetricsCollector interface {
	RecordLLMCall(inputTokens, outputTokens, cacheCreation, cacheRead int, latencyMs int64)
	RecordSupervision(approved bool)
	SetSubagents(count int)
}

MetricsCollector receives LLM and supervision metrics for heartbeat reporting.

type ObservationExtractor

type ObservationExtractor interface {
	Extract(ctx context.Context, stepName, stepType, output string) (interface{}, error)
}

ObservationExtractor extracts observations from step outputs.

type ObservationStore

type ObservationStore interface {
	StoreObservation(ctx context.Context, obs interface{}) error
	QueryRelevantObservations(ctx context.Context, query string, limit int) ([]interface{}, error)
}

ObservationStore stores and retrieves observations.

type Result

type Result struct {
	Status     Status
	Outputs    map[string]string
	Iterations map[string]int
	Error      string
}

Result represents the execution result.

type Status

type Status string

Status represents the execution status.

const (
	StatusRunning  Status = "running"
	StatusComplete Status = "complete"
	StatusFailed   Status = "failed"
)

type XMLContextBuilder

type XMLContextBuilder struct {
	// contains filtered or unexported fields
}

XMLContextBuilder builds XML-structured prompts for LLM communication.

func NewXMLContextBuilder

func NewXMLContextBuilder(workflowName string) *XMLContextBuilder

NewXMLContextBuilder creates a new context builder for a workflow.

func (*XMLContextBuilder) AddConvergenceIteration

func (b *XMLContextBuilder) AddConvergenceIteration(n int, output string)

AddConvergenceIteration adds a completed convergence iteration to the context.

func (*XMLContextBuilder) AddDiscussContribution

func (b *XMLContextBuilder) AddDiscussContribution(id, capability string, round int, output string)

AddDiscussContribution adds an agent's output from a discuss round.

func (*XMLContextBuilder) AddPriorGoal

func (b *XMLContextBuilder) AddPriorGoal(id, output string)

AddPriorGoal adds a completed goal's output to the context.

func (*XMLContextBuilder) Build

func (b *XMLContextBuilder) Build() string

Build generates the XML-structured prompt. All data content is escaped to prevent injection attacks.

func (*XMLContextBuilder) SetConvergenceMode

func (b *XMLContextBuilder) SetConvergenceMode()

SetConvergenceMode enables convergence mode for the context builder.

func (*XMLContextBuilder) SetCorrection

func (b *XMLContextBuilder) SetCorrection(correction string)

SetCorrection sets the supervisor correction for the current goal.

func (*XMLContextBuilder) SetCurrentGoal

func (b *XMLContextBuilder) SetCurrentGoal(id, description string)

SetCurrentGoal sets the current goal to be executed.

func (*XMLContextBuilder) SetDiscussTaskID

func (b *XMLContextBuilder) SetDiscussTaskID(taskID string)

SetDiscussTaskID sets the task ID for discuss context.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL