errorwatch

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package errorwatch provides error detection and automatic follow-up for agent errors.

Package errorwatch provides error detection and automatic follow-up for agent errors.

Index

Constants

This section is empty.

Variables

View Source
var ErrorPatterns = []string{
	"context deadline exceeded",
	"context canceled",
	"timeout",
	"connection refused",
	"connection reset",
	"exit status 1",
}

ErrorPatterns defines the patterns to detect recoverable agent errors.

Functions

func FollowUpMessage

func FollowUpMessage(agentName string) string

FollowUpMessage generates a follow-up message for an agent that encountered an error.

func IsRecoverableError

func IsRecoverableError(errMsg string) bool

IsRecoverableError checks if the error message matches known recoverable patterns.

Types

type AgentMode added in v0.9.0

type AgentMode string

AgentMode represents the mode of an individual agent

const (
	// AgentModeNormal is the default mode where the agent operates normally
	AgentModeNormal AgentMode = "normal"
	// AgentModeAuto is the mode where the agent operates automatically after error recovery
	AgentModeAuto AgentMode = "auto"
)

type AgentModeManager added in v0.9.0

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

AgentModeManager manages per-agent mode states

func NewAgentModeManager added in v0.9.0

func NewAgentModeManager() *AgentModeManager

NewAgentModeManager creates a new agent mode manager

func (*AgentModeManager) AllAutoAgents added in v0.9.0

func (m *AgentModeManager) AllAutoAgents() []string

AllAutoAgents returns a list of agents currently in auto mode

func (*AgentModeManager) AllStates added in v0.9.0

func (m *AgentModeManager) AllStates() map[string]*AgentModeState

AllStates returns all current states

func (*AgentModeManager) GetMode added in v0.9.0

func (m *AgentModeManager) GetMode(agentName string) AgentMode

GetMode returns the current mode of an agent

func (*AgentModeManager) GetState added in v0.9.0

func (m *AgentModeManager) GetState(agentName string) *AgentModeState

GetState returns the full state of an agent

func (*AgentModeManager) IsAuto added in v0.9.0

func (m *AgentModeManager) IsAuto(agentName string) bool

IsAuto returns true if the agent is in auto mode

func (*AgentModeManager) Reset added in v0.9.0

func (m *AgentModeManager) Reset(agentName string)

Reset clears the mode state for an agent

func (*AgentModeManager) ResetAll added in v0.9.0

func (m *AgentModeManager) ResetAll()

ResetAll clears all mode states

func (*AgentModeManager) SetOnModeChange added in v0.9.0

func (m *AgentModeManager) SetOnModeChange(fn func(agentName string, from, to AgentMode))

SetOnModeChange sets the callback for mode changes

func (*AgentModeManager) SwitchToAuto added in v0.9.0

func (m *AgentModeManager) SwitchToAuto(agentName string, errorMessage string)

SwitchToAuto switches an agent to auto mode

func (*AgentModeManager) SwitchToNormal added in v0.9.0

func (m *AgentModeManager) SwitchToNormal(agentName string)

SwitchToNormal switches an agent back to normal mode

type AgentModeState added in v0.9.0

type AgentModeState struct {
	Mode         AgentMode
	SwitchedAt   time.Time
	ErrorMessage string // The error that triggered auto mode
}

AgentModeState tracks the mode state of an agent

type Detector

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

Detector detects error patterns and manages follow-up cooldowns.

func DefaultDetector

func DefaultDetector() *Detector

DefaultDetector creates a detector with 30-second cooldown.

func NewDetector

func NewDetector(cooldownPeriod time.Duration) *Detector

NewDetector creates a new error detector with the specified cooldown period.

func (*Detector) CheckAndGenerateFollowUp

func (d *Detector) CheckAndGenerateFollowUp(agentName string, errMsg string) FollowUpResult

CheckAndGenerateFollowUp checks if a follow-up should be sent and generates the message. Also switches the agent to auto mode if the error is recoverable.

func (*Detector) HandleError added in v0.9.0

func (d *Detector) HandleError(agentName string, errMsg string) bool

HandleError processes an error and switches to auto mode if applicable. Returns true if the agent was switched to auto mode.

func (*Detector) IsAgentInAutoMode added in v0.9.0

func (d *Detector) IsAgentInAutoMode(agentName string) bool

IsAgentInAutoMode checks if an agent is in auto mode.

func (*Detector) ModeManager added in v0.9.0

func (d *Detector) ModeManager() *AgentModeManager

ModeManager returns the agent mode manager.

func (*Detector) RecordFollowUp

func (d *Detector) RecordFollowUp(agentName string)

RecordFollowUp records that a follow-up was sent to the agent.

func (*Detector) Reset

func (d *Detector) Reset(agentName string)

Reset clears the follow-up history for an agent.

func (*Detector) ResetAgentMode added in v0.9.0

func (d *Detector) ResetAgentMode(agentName string)

ResetAgentMode resets an agent to normal mode.

func (*Detector) ResetAll

func (d *Detector) ResetAll()

ResetAll clears all follow-up history.

func (*Detector) SetModeManager added in v0.9.0

func (d *Detector) SetModeManager(m *AgentModeManager)

SetModeManager sets a custom agent mode manager.

func (*Detector) ShouldFollowUp

func (d *Detector) ShouldFollowUp(agentName string, errMsg string) bool

ShouldFollowUp checks if a follow-up should be sent to the agent. Returns true if the error is recoverable and cooldown has passed.

type FollowUpResult

type FollowUpResult struct {
	ShouldSend     bool
	AgentName      string
	Message        string
	SwitchedToAuto bool // Whether the agent was switched to auto mode
}

FollowUpResult contains the result of checking whether to send a follow-up.

Jump to

Keyboard shortcuts

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