execcontext

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExecutionContext

type ExecutionContext struct {
	Parent *ExecutionContext

	// Workflow information
	Workflow  *ast.Workflow
	RunID     string
	StartTime time.Time
	Cwd       string

	// Input parameters and state
	Inputs  map[string]interface{}
	State   map[string]interface{}
	Outputs map[string]interface{}

	// Step execution tracking
	StepResults      map[string]*StepResult
	CurrentStepIndex int
	TotalSteps       int

	// Environment and metadata
	Environment map[string]string
	Metadata    map[string]interface{}

	// Execution control
	Context RunContext
	Logger  zerolog.Logger
	// contains filtered or unexported fields
}

ExecutionContext contains all the state and metadata for a workflow execution

func NewExecutionContext

func NewExecutionContext(ctx RunContext, workflow *ast.Workflow, inputs map[string]interface{}, wd string) *ExecutionContext

NewExecutionContext creates a new execution context for a workflow

func (*ExecutionContext) GetAllState

func (ec *ExecutionContext) GetAllState() map[string]interface{}

GetAllState returns a copy of all state variables

func (*ExecutionContext) GetEnvironment

func (ec *ExecutionContext) GetEnvironment(key string) (string, bool)

GetEnvironment returns an environment variable value

func (*ExecutionContext) GetExecutionSummary

func (ec *ExecutionContext) GetExecutionSummary() ExecutionSummary

GetExecutionSummary returns a summary of the execution

func (*ExecutionContext) GetInput

func (ec *ExecutionContext) GetInput(key string) (interface{}, bool)

GetInput returns an input parameter value

func (*ExecutionContext) GetMetadata

func (ec *ExecutionContext) GetMetadata(key string) (interface{}, bool)

GetMetadata returns a metadata value

func (*ExecutionContext) GetState

func (ec *ExecutionContext) GetState(key string) (interface{}, bool)

GetState returns a state variable value

func (*ExecutionContext) GetStepResult

func (ec *ExecutionContext) GetStepResult(stepID string) (*StepResult, bool)

GetStepResult returns the result of a specific step

func (*ExecutionContext) GetWorkflowOutputs

func (ec *ExecutionContext) GetWorkflowOutputs() map[string]interface{}

GetWorkflowOutputs returns a copy of workflow outputs

func (*ExecutionContext) IncrementCurrentStep

func (ec *ExecutionContext) IncrementCurrentStep()

IncrementCurrentStep advances to the next step

func (*ExecutionContext) IsCancelled

func (ec *ExecutionContext) IsCancelled() bool

IsCancelled returns true if the execution context has been cancelled

func (*ExecutionContext) IsCompleted

func (ec *ExecutionContext) IsCompleted() bool

IsCompleted returns true if all steps have been executed

func (*ExecutionContext) NewChild

func (ec *ExecutionContext) NewChild(steps []*ast.Step) *ExecutionContext

NewChild creates a new execution context for a sub step execution This is used to create an execution context that is scoped to the sub steps and so will not pollute the parent execution context. The parent execution context is used to track the overall execution status, progress and state.

func (*ExecutionContext) SetStepResult

func (ec *ExecutionContext) SetStepResult(stepID string, result *StepResult)

SetStepResult updates the result for a specific step

func (*ExecutionContext) SetWorkflowOutputs

func (ec *ExecutionContext) SetWorkflowOutputs(outputs map[string]interface{})

SetWorkflowOutputs updates the workflow outputs

func (*ExecutionContext) UpdateState

func (ec *ExecutionContext) UpdateState(updates map[string]interface{})

UpdateState updates multiple state variables

func (*ExecutionContext) Write

func (ec *ExecutionContext) Write(p []byte) (n int, err error)

type ExecutionStatus

type ExecutionStatus string

ExecutionStatus represents the overall execution status

const (
	ExecutionStatusPending   ExecutionStatus = "pending"
	ExecutionStatusRunning   ExecutionStatus = "running"
	ExecutionStatusCompleted ExecutionStatus = "completed"
	ExecutionStatusFailed    ExecutionStatus = "failed"
	ExecutionStatusCancelled ExecutionStatus = "cancelled"
)

type ExecutionSummary

type ExecutionSummary struct {
	RunID         string                 `json:"run_id"`
	Status        ExecutionStatus        `json:"status"`
	StartTime     time.Time              `json:"start_time"`
	EndTime       time.Time              `json:"end_time,omitempty"`
	Duration      time.Duration          `json:"duration"`
	Steps         []StepResult           `json:"steps"`
	Inputs        map[string]interface{} `json:"inputs"`
	State         map[string]interface{} `json:"state"`
	Outputs       map[string]interface{} `json:"outputs,omitempty"`
	TotalTokens   int                    `json:"total_tokens"`
	EstimatedCost float64                `json:"estimated_cost"`
}

ExecutionSummary provides a summary of workflow execution

type RunContext

type RunContext struct {
	Context context.Context
	StdOut  io.Writer
	StdErr  io.Writer
}

func (RunContext) Printf

func (rc RunContext) Printf(format string, v ...any)

func (RunContext) Write

func (rc RunContext) Write(p []byte) (n int, err error)

type StepResult

type StepResult struct {
	StepID     string                 `json:"step_id"`
	Status     StepStatus             `json:"status"`
	StartTime  time.Time              `json:"start_time"`
	EndTime    time.Time              `json:"end_time"`
	Duration   time.Duration          `json:"duration"`
	Output     map[string]interface{} `json:"output"`
	Response   string                 `json:"response,omitempty"`
	Error      error                  `json:"error,omitempty"`
	TokenUsage *TokenUsage            `json:"token_usage,omitempty"`
	Retries    int                    `json:"retries"`
}

StepResult represents the result of executing a single step

type StepStatus

type StepStatus string

StepStatus represents the execution status of a step

const (
	StepStatusPending   StepStatus = "pending"
	StepStatusRunning   StepStatus = "running"
	StepStatusCompleted StepStatus = "completed"
	StepStatusFailed    StepStatus = "failed"
	StepStatusSkipped   StepStatus = "skipped"
)

type TokenUsage

type TokenUsage struct {
	PromptTokens     int `json:"prompt_tokens"`
	CompletionTokens int `json:"completion_tokens"`
	TotalTokens      int `json:"total_tokens"`
}

TokenUsage tracks token consumption for model API calls

Jump to

Keyboard shortcuts

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