execution

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Checkpoint

type Checkpoint struct {
	ID          string                 `json:"id"`           // Unique checkpoint ID
	TaskID      string                 `json:"task_id"`      // Task this checkpoint belongs to
	StepID      int                    `json:"step_id"`      // Current step being executed
	StepName    string                 `json:"step_name"`    // Human-readable step name
	TurnCount   int                    `json:"turn_count"`   // Turns used so far
	State       map[string]interface{} `json:"state"`        // Arbitrary state data
	ToolResults map[string]interface{} `json:"tool_results"` // Results from tools
	CreatedAt   time.Time              `json:"created_at"`
	UpdatedAt   time.Time              `json:"updated_at"`
	IsFinal     bool                   `json:"is_final"` // True if task completed
}

Checkpoint represents a saved execution state This is the core of the resumable execution pattern

type ExecutionResult

type ExecutionResult struct {
	ToolName  string        `json:"tool_name"`
	Success   bool          `json:"success"`
	Data      interface{}   `json:"data,omitempty"`
	Error     string        `json:"error,omitempty"`
	Duration  time.Duration `json:"duration"`
	Timestamp time.Time     `json:"timestamp"`
}

ExecutionResult represents the result of a single tool execution

type Manager

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

Manager handles execution checkpointing, resumption, and validation This is Layer 3 of the Cortex three-layer architecture: Perception → Cognition → Execution

func NewManager

func NewManager(baseDir string) *Manager

NewManager creates a new execution manager

func (*Manager) CleanupCompleted

func (m *Manager) CleanupCompleted(olderThan time.Duration) int

CleanupCompleted removes completed checkpoints older than the threshold

func (*Manager) CompleteCheckpoint

func (m *Manager) CompleteCheckpoint(checkpoint *Checkpoint)

CompleteCheckpoint marks a checkpoint as successfully completed

func (*Manager) DeleteCheckpoint

func (m *Manager) DeleteCheckpoint(checkpointID string) error

DeleteCheckpoint removes a checkpoint

func (*Manager) FindCheckpoint

func (m *Manager) FindCheckpoint(taskDescription string) *Checkpoint

FindCheckpoint finds a checkpoint to resume from Returns nil if no resumable checkpoint exists

func (*Manager) GetProgress

func (m *Manager) GetProgress(checkpoint *Checkpoint) *Progress

GetProgress returns human-readable progress information

func (*Manager) ListRecentCheckpoints

func (m *Manager) ListRecentCheckpoints(limit int) []*Checkpoint

ListRecentCheckpoints returns recently active checkpoints

func (*Manager) SetAutoResume

func (m *Manager) SetAutoResume(auto bool)

SetAutoResume enables or disables auto-resume

func (*Manager) SetValidationLevel

func (m *Manager) SetValidationLevel(level ValidationLevel)

SetValidationLevel sets the validation level

func (*Manager) StartCheckpoint

func (m *Manager) StartCheckpoint(taskID string, plan *cognition.ExecutionPlan) *Checkpoint

StartCheckpoint begins a new checkpoint for a task

func (*Manager) StoreError

func (m *Manager) StoreError(checkpoint *Checkpoint, toolName string, err error)

StoreError stores an execution error

func (*Manager) StoreToolResult

func (m *Manager) StoreToolResult(checkpoint *Checkpoint, toolName string, result interface{})

StoreToolResult stores a tool execution result

func (*Manager) SuggestRecoveryAction

func (m *Manager) SuggestRecoveryAction(checkpoint *Checkpoint, err error) RecoveryAction

SuggestRecoveryAction suggests what to do after a failure

func (*Manager) UpdateCheckpoint

func (m *Manager) UpdateCheckpoint(checkpoint *Checkpoint, stepID int, stepName string)

UpdateCheckpoint updates the current checkpoint state

func (*Manager) UpdateTurnCount

func (m *Manager) UpdateTurnCount(checkpoint *Checkpoint, turns int)

UpdateTurnCount updates the turn count in the checkpoint

func (*Manager) ValidateResult

func (m *Manager) ValidateResult(checkpoint *Checkpoint, toolName string, result interface{}) *ValidationResult

ValidateResult validates an execution result against expectations

type Progress

type Progress struct {
	TaskID          string  `json:"task_id"`
	CurrentStep     int     `json:"current_step"`
	TotalSteps      int     `json:"total_steps"`
	PercentComplete float64 `json:"percent_complete"`
	CurrentAction   string  `json:"current_action"`
	Message         string  `json:"message,omitempty"`
}

Progress represents task progress information for the user

type RecoveryAction

type RecoveryAction string

RecoveryAction represents possible actions when execution fails

const (
	RecoveryRetry       RecoveryAction = "retry"       // Retry the same step
	RecoveryAlternative RecoveryAction = "alternative" // Try a different approach
	RecoveryAskUser     RecoveryAction = "ask_user"    // Ask user what to do
	RecoveryAbort       RecoveryAction = "abort"       // Give up
)

type ResumeStrategy

type ResumeStrategy string

ResumeStrategy defines how to resume from a checkpoint

const (
	ResumeAuto    ResumeStrategy = "auto"     // Resume automatically
	ResumeAskUser ResumeStrategy = "ask_user" // Ask user before resuming
	ResumeRestart ResumeStrategy = "restart"  // Start over from beginning
)

type ValidationLevel

type ValidationLevel string

ValidationLevel defines how strictly to validate execution results

const (
	ValidationNone   ValidationLevel = "none"
	ValidationBasic  ValidationLevel = "basic"  // Check for obvious errors
	ValidationStrict ValidationLevel = "strict" // Verify expected outcomes
	ValidationFull   ValidationLevel = "full"   // LLM-based quality assessment
)

type ValidationResult

type ValidationResult struct {
	Passed      bool     `json:"passed"`
	Issues      []string `json:"issues,omitempty"`
	Suggestions []string `json:"suggestions,omitempty"`
	Confidence  float64  `json:"confidence"` // 0.0 - 1.0
}

ValidationResult contains the outcome of result validation

Jump to

Keyboard shortcuts

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