runner

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultMaxTurns is the default maximum number of turns
	DefaultMaxTurns = 10
)

Variables

This section is empty.

Functions

func GenerateTaskID

func GenerateTaskID() string

GenerateTaskID generates a unique task ID

Types

type AgentType

type AgentType = *agent.Agent

Type aliases to help with import resolution

type DefaultRunHooks

type DefaultRunHooks struct{}

DefaultRunHooks provides a default implementation of RunHooks

func (*DefaultRunHooks) OnAfterHandoff

func (h *DefaultRunHooks) OnAfterHandoff(ctx context.Context, agent AgentType, handoffAgent AgentType, result interface{}) error

OnAfterHandoff is called after a handoff completes

func (*DefaultRunHooks) OnBeforeHandoff

func (h *DefaultRunHooks) OnBeforeHandoff(ctx context.Context, agent AgentType, handoffAgent AgentType) error

OnBeforeHandoff is called before a handoff occurs

func (*DefaultRunHooks) OnRunEnd

func (h *DefaultRunHooks) OnRunEnd(ctx context.Context, result *result.RunResult) error

OnRunEnd is called when the run ends

func (*DefaultRunHooks) OnRunStart

func (h *DefaultRunHooks) OnRunStart(ctx context.Context, agent *agent.Agent, input interface{}) error

OnRunStart is called when the run starts

func (*DefaultRunHooks) OnTurnEnd

func (h *DefaultRunHooks) OnTurnEnd(ctx context.Context, agent *agent.Agent, turn int, result *SingleTurnResult) error

OnTurnEnd is called when a turn ends

func (*DefaultRunHooks) OnTurnStart

func (h *DefaultRunHooks) OnTurnStart(ctx context.Context, agent *agent.Agent, turn int) error

OnTurnStart is called when a turn starts

type HandoffInputFilter

type HandoffInputFilter func(input interface{}) (interface{}, error)

HandoffInputFilter is a function that filters input during handoffs

type InputGuardrail

type InputGuardrail interface {
	// Check checks the input
	Check(input interface{}) (bool, string, error)
}

InputGuardrail is an interface for input guardrails

type Interaction

type Interaction struct {
	// Role is the role of the interaction (e.g., "user", "agent")
	Role string

	// Content is the content of the interaction
	Content interface{}

	// Timestamp is the time the interaction occurred
	Timestamp time.Time
}

Interaction represents a single interaction in a task's history

type ModelRequestType

type ModelRequestType = model.Request

Type aliases to help with import resolution

type ModelSettingsType

type ModelSettingsType = model.Settings

Type aliases to help with import resolution

type OutputGuardrail

type OutputGuardrail interface {
	// Check checks the output
	Check(output interface{}) (bool, string, error)
}

OutputGuardrail is an interface for output guardrails

type RecoveryConfig

type RecoveryConfig struct {
	// AutomaticRecovery indicates whether to attempt automatic recovery
	AutomaticRecovery bool

	// RecoveryFunc is called to attempt recovery from a panic
	RecoveryFunc func(ctx interface{}, agent AgentType, state *WorkflowState, rec interface{}) error

	// OnPanic is called when a panic occurs
	OnPanic func(ctx interface{}, panicErr interface{}) error

	// MaxRecoveryAttempts is the maximum number of recovery attempts
	MaxRecoveryAttempts int
}

RecoveryConfig configures failure recovery

type RetryConfig

type RetryConfig struct {
	// MaxRetries is the maximum number of retries for a failed operation
	MaxRetries int

	// RetryDelay is the delay between retries
	RetryDelay time.Duration

	// RetryBackoffFactor is the factor to multiply delay by after each retry
	RetryBackoffFactor float64

	// RetryableErrors are error types that should trigger a retry
	RetryableErrors []string

	// OnRetry is called before each retry attempt
	OnRetry func(attempt int, err error) error
}

RetryConfig configures retry behavior

type RunConfig

type RunConfig struct {
	// Model is a model override (string or Model)
	Model interface{}

	// ModelProvider is the provider for resolving model names
	ModelProvider model.Provider

	// ModelSettings are global model settings
	ModelSettings *model.Settings

	// HandoffInputFilter is a global handoff input filter
	HandoffInputFilter HandoffInputFilter

	// InputGuardrails are global input guardrails
	InputGuardrails []InputGuardrail

	// OutputGuardrails are global output guardrails
	OutputGuardrails []OutputGuardrail

	// TracingDisabled indicates whether tracing is disabled
	TracingDisabled bool

	// TracingConfig is tracing configuration
	TracingConfig *TracingConfig
}

RunConfig configures global settings

type RunHooks

type RunHooks interface {
	// OnRunStart is called when the run starts
	OnRunStart(ctx context.Context, agent *agent.Agent, input interface{}) error

	// OnTurnStart is called when a turn starts
	OnTurnStart(ctx context.Context, agent *agent.Agent, turn int) error

	// OnTurnEnd is called when a turn ends
	OnTurnEnd(ctx context.Context, agent *agent.Agent, turn int, result *SingleTurnResult) error

	// OnRunEnd is called when the run ends
	OnRunEnd(ctx context.Context, result *result.RunResult) error

	// OnBeforeHandoff is called before a handoff occurs
	OnBeforeHandoff(ctx context.Context, agent AgentType, handoffAgent AgentType) error

	// OnAfterHandoff is called after a handoff completes
	OnAfterHandoff(ctx context.Context, agent AgentType, handoffAgent AgentType, result interface{}) error
}

RunHooks defines lifecycle hooks for a run

type RunOptions

type RunOptions struct {
	// Input is the input to the run
	Input interface{}

	// Context is a user-provided context object
	Context interface{}

	// MaxTurns is the maximum number of turns
	MaxTurns int

	// Hooks are lifecycle hooks for the run
	Hooks RunHooks

	// RunConfig is global configuration
	RunConfig *RunConfig

	// WorkflowConfig configures workflow-specific behavior
	WorkflowConfig *WorkflowConfig
}

RunOptions configures a run

type Runner

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

Runner executes agents

func NewRunner

func NewRunner() *Runner

NewRunner creates a new runner with default configuration

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, agent AgentType, opts *RunOptions) (*result.RunResult, error)

Run executes an agent with the given input and options

func (*Runner) RunStreaming

func (r *Runner) RunStreaming(ctx context.Context, agent AgentType, opts *RunOptions) (*result.StreamedRunResult, error)

RunStreaming executes an agent with streaming responses

func (*Runner) RunSync

func (r *Runner) RunSync(agent AgentType, opts *RunOptions) (*result.RunResult, error)

RunSync is a synchronous version of Run

func (*Runner) WithDefaultMaxTurns

func (r *Runner) WithDefaultMaxTurns(maxTurns int) *Runner

WithDefaultMaxTurns sets the default maximum turns

func (*Runner) WithDefaultProvider

func (r *Runner) WithDefaultProvider(provider model.Provider) *Runner

WithDefaultProvider sets the default model provider

type SingleTurnResult

type SingleTurnResult struct {
	Agent    *agent.Agent
	Response interface{}
	Output   interface{}
}

SingleTurnResult contains the result of a single turn

type StateManagementConfig

type StateManagementConfig struct {
	// PersistState indicates whether to persist workflow state
	PersistState bool

	// StateStore is the interface for storing workflow state
	StateStore WorkflowStateStore

	// CheckpointFrequency determines how often to save state
	CheckpointFrequency time.Duration

	// RestoreOnFailure indicates whether to restore state on failure
	RestoreOnFailure bool
}

StateManagementConfig configures workflow state management

type TaskContext

type TaskContext struct {
	// TaskID is a unique identifier for the task
	TaskID string

	// ParentAgentName is the name of the agent that delegated the task
	ParentAgentName string

	// ChildAgentName is the name of the agent executing the task
	ChildAgentName string

	// Status indicates the current status of the task
	Status TaskStatus

	// CreatedAt is the time the task was created
	CreatedAt time.Time

	// CompletedAt is the time the task was completed
	CompletedAt *time.Time

	// Result contains the result of the task
	Result interface{}

	// RelatedTaskIDs contains IDs of related tasks (e.g., parent, children)
	RelatedTaskIDs []string

	// TaskDescription contains a human-readable description of the task
	TaskDescription string

	// WorkingContext contains context information about what is being worked on
	WorkingContext *WorkingContext

	// InteractionHistory contains the history of interactions for this task
	InteractionHistory []Interaction
}

TaskContext tracks information about a delegated task

func NewTaskContext

func NewTaskContext(taskID, parentName, childName string) *TaskContext

NewTaskContext creates a new task context

func (*TaskContext) AddInteraction

func (t *TaskContext) AddInteraction(role string, content interface{})

AddInteraction adds an interaction to the task history

func (*TaskContext) AddMetadata

func (t *TaskContext) AddMetadata(key string, value interface{})

AddMetadata adds metadata to the task context

func (*TaskContext) AddRelatedTask

func (t *TaskContext) AddRelatedTask(taskID string)

AddRelatedTask adds a related task ID

func (*TaskContext) Complete

func (t *TaskContext) Complete(result interface{})

Complete marks the task as complete with a result

func (*TaskContext) Fail

func (t *TaskContext) Fail(err error)

Fail marks the task as failed with an error

func (*TaskContext) GetArtifact

func (t *TaskContext) GetArtifact() interface{}

GetArtifact returns the working artifact for the task

func (*TaskContext) GetDelegationChain

func (t *TaskContext) GetDelegationChain() string

GetDelegationChain returns the delegation chain in the format "parent -> child"

func (*TaskContext) GetInteractionHistory

func (t *TaskContext) GetInteractionHistory() []Interaction

GetInteractionHistory returns the interaction history for the task

func (*TaskContext) GetLastInteraction

func (t *TaskContext) GetLastInteraction() *Interaction

GetLastInteraction returns the most recent interaction

func (*TaskContext) GetMetadata

func (t *TaskContext) GetMetadata(key string) interface{}

GetMetadata retrieves metadata from the task context

func (*TaskContext) GetResult

func (t *TaskContext) GetResult() interface{}

GetResult returns the task result

func (*TaskContext) IsComplete

func (t *TaskContext) IsComplete() bool

IsComplete checks if the task is complete

func (*TaskContext) IsFailed

func (t *TaskContext) IsFailed() bool

IsFailed checks if the task has failed

func (*TaskContext) IsFinished

func (t *TaskContext) IsFinished() bool

IsFinished checks if the task is either complete or failed

func (*TaskContext) IsPending

func (t *TaskContext) IsPending() bool

IsPending checks if the task is still pending

func (*TaskContext) SetArtifact

func (t *TaskContext) SetArtifact(artifact interface{}, artifactType string)

SetArtifact sets the working artifact for the task

func (*TaskContext) SetDescription

func (t *TaskContext) SetDescription(description string)

SetDescription sets a human-readable description for the task

func (*TaskContext) ToJSON

func (t *TaskContext) ToJSON() (string, error)

ToJSON converts the task context to JSON

type TaskStatus

type TaskStatus string

TaskStatus represents the status of a delegated task

const (
	// TaskStatusPending indicates the task is in progress
	TaskStatusPending TaskStatus = "pending"

	// TaskStatusComplete indicates the task is complete
	TaskStatusComplete TaskStatus = "complete"

	// TaskStatusFailed indicates the task failed
	TaskStatusFailed TaskStatus = "failed"
)

type TracingConfig

type TracingConfig struct {
	// WorkflowName is the name of the workflow
	WorkflowName string

	// TraceID is a custom trace ID
	TraceID string

	// GroupID is a grouping identifier
	GroupID string

	// Metadata is additional metadata
	Metadata map[string]interface{}
}

TracingConfig configures tracing

type ValidationConfig

type ValidationConfig struct {
	// PreHandoffValidation validates data before handoff
	PreHandoffValidation []ValidationRule

	// PostHandoffValidation validates data after handoff
	PostHandoffValidation []ValidationRule

	// PhaseTransitionValidation validates phase transitions
	PhaseTransitionValidation []ValidationRule
}

ValidationConfig configures validation behavior

type ValidationRule

type ValidationRule struct {
	// Name is the name of the rule
	Name string

	// Validate is the validation function
	Validate func(data interface{}) (bool, error)

	// ErrorMessage is the message to show on validation failure
	ErrorMessage string

	// Severity determines if validation failure should block progress
	Severity ValidationSeverity
}

ValidationRule defines a validation rule

type ValidationSeverity

type ValidationSeverity string

ValidationSeverity indicates the severity of a validation failure

const (
	// ValidationError indicates a blocking validation failure
	ValidationError ValidationSeverity = "error"

	// ValidationWarning indicates a non-blocking validation failure
	ValidationWarning ValidationSeverity = "warning"
)

type WorkflowConfig

type WorkflowConfig struct {
	// RetryConfig configures retry behavior for handoffs and tool calls
	RetryConfig *RetryConfig

	// StateManagement configures how workflow state is managed
	StateManagement *StateManagementConfig

	// ValidationConfig configures input/output validation between phases
	ValidationConfig *ValidationConfig

	// RecoveryConfig configures how to handle and recover from failures
	RecoveryConfig *RecoveryConfig
}

WorkflowConfig configures workflow behavior

type WorkflowRunner

type WorkflowRunner struct {
	*Runner
	// contains filtered or unexported fields
}

WorkflowRunner extends the base Runner with workflow capabilities

func NewWorkflowRunner

func NewWorkflowRunner(baseRunner *Runner, config *WorkflowConfig) *WorkflowRunner

NewWorkflowRunner creates a new workflow runner

func (*WorkflowRunner) RunWorkflow

func (wr *WorkflowRunner) RunWorkflow(ctx context.Context, agent AgentType, opts *RunOptions) (*result.RunResult, error)

RunWorkflow executes a workflow with the given options

type WorkflowState

type WorkflowState struct {
	// CurrentPhase is the current phase of the workflow
	CurrentPhase string
	// CompletedPhases are the phases that have been completed
	CompletedPhases []string
	// Artifacts are data produced during workflow execution
	Artifacts map[string]interface{}
	// LastCheckpoint is when the state was last saved
	LastCheckpoint time.Time
	// Metadata is additional workflow metadata
	Metadata map[string]interface{}
}

WorkflowState represents the current state of a workflow

type WorkflowStateStore

type WorkflowStateStore interface {
	// SaveState saves the current workflow state
	SaveState(workflowID string, state interface{}) error

	// LoadState loads a workflow state
	LoadState(workflowID string) (interface{}, error)

	// ListCheckpoints lists available checkpoints for a workflow
	ListCheckpoints(workflowID string) ([]string, error)

	// DeleteCheckpoint deletes a checkpoint
	DeleteCheckpoint(workflowID string, checkpointID string) error
}

WorkflowStateStore defines the interface for storing workflow state

type WorkingContext

type WorkingContext struct {
	// Artifact is the primary artifact being worked on (e.g., code, text)
	Artifact interface{} `json:"artifact,omitempty"`

	// ArtifactType indicates the type of artifact (e.g., "code", "text")
	ArtifactType string `json:"artifact_type,omitempty"`

	// Metadata contains additional metadata about the task
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

WorkingContext contains context information about the task

Jump to

Keyboard shortcuts

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