schema

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrCodeValidation        = "VALIDATION_ERROR"
	ErrCodeExecution         = "EXECUTION_ERROR"
	ErrCodeTimeout           = "TIMEOUT_ERROR"
	ErrCodeNotFound          = "NOT_FOUND"
	ErrCodeConflict          = "CONFLICT"
	ErrCodeInvalidTransition = "INVALID_TRANSITION"
	ErrCodeCycleDetected     = "CYCLE_DETECTED"
	ErrCodeStepFailed        = "STEP_FAILED"
	ErrCodeCancelled         = "CANCELLED"
	ErrCodeSignalFailed      = "SIGNAL_FAILED"
	ErrCodeRetryExhausted    = "RETRY_EXHAUSTED"
	ErrCodeStore             = "STORE_ERROR"
	ErrCodeInterpolation     = "INTERPOLATION_ERROR"
	ErrCodeCircuitOpen       = "CIRCUIT_OPEN"
	ErrCodeNonRetryable      = "NON_RETRYABLE"
	ErrCodePermissionDenied  = "PERMISSION_DENIED"
	ErrCodeActionUnavailable = "ACTION_UNAVAILABLE"
	ErrCodeAssertionFailed   = "ASSERTION_FAILED"
	ErrCodeIsolation         = "ISOLATION_ERROR"
	ErrCodePathDenied        = "PATH_DENIED"
	ErrCodeVault             = "VAULT_ERROR"
)

Error codes for structured error reporting.

View Source
const (
	EventWorkflowStarted   = "workflow_started"
	EventWorkflowCompleted = "workflow_completed"
	EventWorkflowFailed    = "workflow_failed"
	EventWorkflowCancelled = "workflow_cancelled"
	EventWorkflowSuspended = "workflow_suspended"
	EventWorkflowResumed   = "workflow_resumed"
	EventWorkflowTimedOut  = "workflow_timed_out"

	EventStepStarted   = "step_started"
	EventStepCompleted = "step_completed"
	EventStepFailed    = "step_failed"
	EventStepSkipped   = "step_skipped"
	EventStepRetrying  = "step_retrying"
	EventStepSuspended = "step_suspended"

	EventDecisionRequested = "decision_requested"
	EventDecisionResolved  = "decision_resolved"

	EventSignalReceived = "signal_received"
	EventVariableSet    = "variable_set"
	EventDAGMutated     = "dag_mutated"

	EventStepRetryAttempt       = "step_retry_attempt"
	EventErrorHandlerInvoked    = "error_handler_invoked"
	EventCircuitBreakerOpen     = "circuit_breaker_open"
	EventCircuitBreakerHalfOpen = "circuit_breaker_half_open"
	EventCircuitBreakerClosed   = "circuit_breaker_closed"
	EventStepFallback           = "step_fallback"
	EventStepIgnored            = "step_ignored"

	EventConditionEvaluated = "condition_evaluated"
	EventLoopIterStarted    = "loop_iter_started"
	EventLoopIterCompleted  = "loop_iter_completed"
	EventLoopCompleted      = "loop_completed"
	EventParallelStarted    = "parallel_started"
	EventParallelCompleted  = "parallel_completed"
	EventWaitStarted        = "wait_started"
	EventWaitCompleted      = "wait_completed"

	EventWorkflowInterrupted = "workflow_interrupted"
)

Event type constants for the event sourcing log.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConditionConfig

type ConditionConfig struct {
	Expression string                      `json:"expression"` // CEL expression
	Branches   map[string][]StepDefinition `json:"branches"`   // value → steps
	Default    []StepDefinition            `json:"default,omitempty"`
}

ConditionConfig is the config block for condition-type steps.

type DAGMutation

type DAGMutation struct {
	Action     DAGMutationAction `json:"action"`
	TargetStep string            `json:"target_step"`
	Steps      []StepDefinition  `json:"steps,omitempty"`
	Variable   *VariableSet      `json:"variable,omitempty"`
}

DAGMutation describes an in-flight modification to a running workflow's DAG.

type DAGMutationAction

type DAGMutationAction string

DAGMutationAction enumerates the kinds of in-flight DAG mutations.

const (
	MutationInsertAfter  DAGMutationAction = "insert_after"
	MutationInsertBefore DAGMutationAction = "insert_before"
	MutationReplace      DAGMutationAction = "replace"
	MutationRemove       DAGMutationAction = "remove"
	MutationSetVariable  DAGMutationAction = "set_variable"
)

type ErrorHandler

type ErrorHandler struct {
	Strategy     ErrorStrategy `json:"strategy"`                // ignore | fail_workflow | fallback_step | retry
	FallbackStep string        `json:"fallback_step,omitempty"` // step ID to jump to (for fallback_step strategy)
}

ErrorHandler configures what happens when a step fails after retries are exhausted.

type ErrorStrategy

type ErrorStrategy string

ErrorStrategy enumerates error handling strategies for steps.

const (
	// ErrorStrategyIgnore marks the step as skipped and continues the workflow.
	ErrorStrategyIgnore ErrorStrategy = "ignore"
	// ErrorStrategyFailWorkflow fails the entire workflow immediately.
	ErrorStrategyFailWorkflow ErrorStrategy = "fail_workflow"
	// ErrorStrategyFallbackStep executes a designated fallback step instead.
	ErrorStrategyFallbackStep ErrorStrategy = "fallback_step"
	// ErrorStrategyRetry defers to the retry policy (default behavior if retry is configured).
	ErrorStrategyRetry ErrorStrategy = "retry"
)

type LoopConfig

type LoopConfig struct {
	Over      string           `json:"over,omitempty"`      // expression producing iterable
	Condition string           `json:"condition,omitempty"` // while/until condition (CEL)
	Mode      string           `json:"mode,omitempty"`      // for_each | while | until
	Body      []StepDefinition `json:"body"`
	MaxIter   int              `json:"max_iter,omitempty"`
}

LoopConfig is the config block for loop-type steps.

type OpcodeError

type OpcodeError struct {
	Code    string         `json:"code"`
	Message string         `json:"message"`
	Details map[string]any `json:"details,omitempty"`
	StepID  string         `json:"step_id,omitempty"`
	Cause   error          `json:"-"`
}

OpcodeError is the structured error type for all OPCODE operations.

func NewError

func NewError(code, message string) *OpcodeError

NewError creates a new OpcodeError.

func NewErrorf

func NewErrorf(code, format string, args ...any) *OpcodeError

NewErrorf creates a new OpcodeError with a formatted message.

func (*OpcodeError) Error

func (e *OpcodeError) Error() string

func (*OpcodeError) IsRetryable

func (e *OpcodeError) IsRetryable() bool

IsRetryable returns whether this error should be retried. Non-retryable: validation, permission denied, not found, conflict. Retryable: execution errors, timeouts, store errors.

func (*OpcodeError) Unwrap

func (e *OpcodeError) Unwrap() error

func (*OpcodeError) WithCause

func (e *OpcodeError) WithCause(err error) *OpcodeError

WithCause attaches an underlying cause.

func (*OpcodeError) WithDetails

func (e *OpcodeError) WithDetails(details map[string]any) *OpcodeError

WithDetails attaches key-value details.

func (*OpcodeError) WithStep

func (e *OpcodeError) WithStep(stepID string) *OpcodeError

WithStep attaches a step ID to the error.

type ParallelConfig

type ParallelConfig struct {
	Branches [][]StepDefinition `json:"branches"`
	Mode     string             `json:"mode,omitempty"` // all | race (default: all)
}

ParallelConfig is the config block for parallel-type steps.

type ReasoningConfig

type ReasoningConfig struct {
	PromptContext string            `json:"prompt_context"`
	DataInject    map[string]string `json:"data_inject,omitempty"`
	Options       []ReasoningOption `json:"options"`
	Timeout       string            `json:"timeout,omitempty"`
	Fallback      string            `json:"fallback,omitempty"`
	TargetAgent   string            `json:"target_agent,omitempty"`
}

ReasoningConfig is the config block for reasoning-type steps.

type ReasoningOption

type ReasoningOption struct {
	ID          string `json:"id"`
	Description string `json:"description,omitempty"`
}

ReasoningOption is one choice available at a reasoning node.

type RetryPolicy

type RetryPolicy struct {
	Max      int    `json:"max"`                 // max retry attempts
	Backoff  string `json:"backoff,omitempty"`   // none | linear | exponential | constant (default: none)
	Delay    string `json:"delay,omitempty"`     // initial delay (e.g. "1s", "500ms")
	MaxDelay string `json:"max_delay,omitempty"` // cap on backoff delay (e.g. "30s")
}

RetryPolicy configures retry behavior for a step.

type Signal

type Signal struct {
	Type      SignalType     `json:"type"`
	StepID    string         `json:"step_id,omitempty"`
	AgentID   string         `json:"agent_id,omitempty"`
	Payload   map[string]any `json:"payload,omitempty"`
	Reasoning string         `json:"reasoning,omitempty"`
}

Signal is an agent-initiated message to a suspended workflow.

type SignalType

type SignalType string

SignalType enumerates the kinds of signals an agent can send.

const (
	SignalDecision SignalType = "decision"
	SignalData     SignalType = "data"
	SignalCancel   SignalType = "cancel"
	SignalRetry    SignalType = "retry"
	SignalSkip     SignalType = "skip"
)

type StepDefinition

type StepDefinition struct {
	ID        string          `json:"id"`
	Type      StepType        `json:"type,omitempty"`       // action, condition, reasoning, parallel, loop (default: action)
	Action    string          `json:"action,omitempty"`     // action name (e.g. "http.request", "jq")
	Params    json.RawMessage `json:"params,omitempty"`     // action-specific parameters
	DependsOn []string        `json:"depends_on,omitempty"` // step IDs that must complete first
	Condition string          `json:"condition,omitempty"`  // CEL expression, evaluated before execution
	Retry     *RetryPolicy    `json:"retry,omitempty"`
	Timeout   string          `json:"timeout,omitempty"`  // step-level timeout (e.g. "30s", "5m")
	OnError   *ErrorHandler   `json:"on_error,omitempty"` // error handling strategy
	Config    json.RawMessage `json:"config,omitempty"`   // type-specific config (reasoning nodes, parallel, loop)
}

StepDefinition describes a single step in a workflow.

type StepStatus

type StepStatus string

StepStatus represents the lifecycle state of a step.

const (
	StepStatusPending   StepStatus = "pending"
	StepStatusScheduled StepStatus = "scheduled"
	StepStatusRunning   StepStatus = "running"
	StepStatusCompleted StepStatus = "completed"
	StepStatusFailed    StepStatus = "failed"
	StepStatusSkipped   StepStatus = "skipped"
	StepStatusSuspended StepStatus = "suspended"
	StepStatusRetrying  StepStatus = "retrying"
)

type StepType

type StepType string

StepType enumerates the kinds of steps in a workflow.

const (
	StepTypeAction    StepType = "action"
	StepTypeCondition StepType = "condition"
	StepTypeReasoning StepType = "reasoning"
	StepTypeParallel  StepType = "parallel"
	StepTypeLoop      StepType = "loop"
	StepTypeWait      StepType = "wait"
)

type ValidationIssue

type ValidationIssue struct {
	Path     string             `json:"path"`
	Code     string             `json:"code"`
	Message  string             `json:"message"`
	Severity ValidationSeverity `json:"severity"`
}

ValidationIssue is a single validation problem with location context.

type ValidationResult

type ValidationResult struct {
	Errors   []ValidationIssue `json:"errors,omitempty"`
	Warnings []ValidationIssue `json:"warnings,omitempty"`
}

ValidationResult aggregates all issues from the validation pipeline.

func (*ValidationResult) AddError

func (r *ValidationResult) AddError(path, code, message string)

AddError appends an error-severity issue.

func (*ValidationResult) AddWarning

func (r *ValidationResult) AddWarning(path, code, message string)

AddWarning appends a warning-severity issue.

func (*ValidationResult) Merge

func (r *ValidationResult) Merge(other *ValidationResult)

Merge combines another ValidationResult into this one.

func (*ValidationResult) ToError

func (r *ValidationResult) ToError() error

ToError converts the result to an OpcodeError if invalid, nil if valid.

func (*ValidationResult) Valid

func (r *ValidationResult) Valid() bool

Valid returns true if there are no errors (warnings are acceptable).

type ValidationSeverity

type ValidationSeverity string

ValidationSeverity indicates whether an issue is an error or warning.

const (
	SeverityError   ValidationSeverity = "error"
	SeverityWarning ValidationSeverity = "warning"
)

type VariableSet

type VariableSet struct {
	Key   string `json:"key"`
	Value any    `json:"value"`
}

VariableSet injects a variable into a running workflow's context.

type WaitConfig

type WaitConfig struct {
	Duration string `json:"duration,omitempty"` // e.g. "5s", "1m"
	Signal   string `json:"signal,omitempty"`   // wait for named signal
}

WaitConfig is the config block for wait-type steps.

type WorkflowDefinition

type WorkflowDefinition struct {
	Steps      []StepDefinition `json:"steps"`
	Inputs     map[string]any   `json:"inputs,omitempty"`
	OnComplete *StepDefinition  `json:"on_complete,omitempty"`
	OnError    *StepDefinition  `json:"on_error,omitempty"`
	Timeout    string           `json:"timeout,omitempty"`
	OnTimeout  string           `json:"on_timeout,omitempty"` // fail | suspend | cancel (default: fail)
	Metadata   map[string]any   `json:"metadata,omitempty"`
}

WorkflowDefinition is the JSON-serializable workflow format. Agents provide this via opcode.run (inline) or opcode.define (template).

type WorkflowStatus

type WorkflowStatus string

WorkflowStatus represents the lifecycle state of a workflow.

const (
	WorkflowStatusPending   WorkflowStatus = "pending"
	WorkflowStatusActive    WorkflowStatus = "active"
	WorkflowStatusSuspended WorkflowStatus = "suspended"
	WorkflowStatusCompleted WorkflowStatus = "completed"
	WorkflowStatusFailed    WorkflowStatus = "failed"
	WorkflowStatusCancelled WorkflowStatus = "cancelled"
)

Jump to

Keyboard shortcuts

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