hooks

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: Apache-2.0 Imports: 1 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package hooks defines lifecycle hook interfaces for the ReAcTree execution engine.

Hooks are observer-style callbacks invoked at well-defined points during tree execution. They allow external packages (audit, telemetry, debugging) to react to execution lifecycle events without modifying the core loop.

Key design decisions:

  • Event structs use primitive types only — no reactree imports allowed, preventing circular dependencies.
  • Hooks are fire-and-forget (no return values that influence control flow). Control-flow decisions like reflection-based halting belong in the reflector interface, not in hooks.
  • All methods must be safe to call concurrently.
  • Implementations should be cheap; expensive work should be dispatched asynchronously.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChainHook

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

ChainHook fans out lifecycle events to multiple ExecutionHook implementations. This allows composing audit hooks, telemetry hooks, debug hooks, etc. into a single injectable dependency.

func NewChainHook

func NewChainHook(hooks ...ExecutionHook) *ChainHook

NewChainHook creates a ChainHook from the provided hooks. Nil entries are silently skipped.

func (*ChainHook) OnDryRun

func (c *ChainHook) OnDryRun(ctx context.Context, event DryRunEvent)

func (*ChainHook) OnIterationEnd

func (c *ChainHook) OnIterationEnd(ctx context.Context, event IterationEndEvent)

func (*ChainHook) OnIterationStart

func (c *ChainHook) OnIterationStart(ctx context.Context, event IterationStartEvent)

func (*ChainHook) OnPlanExecution

func (c *ChainHook) OnPlanExecution(ctx context.Context, event PlanExecutionEvent)

func (*ChainHook) OnReflection

func (c *ChainHook) OnReflection(ctx context.Context, event ReflectionEvent)

func (*ChainHook) OnToolValidation

func (c *ChainHook) OnToolValidation(ctx context.Context, event ToolValidationEvent)

type DryRunEvent

type DryRunEvent struct {
	PlannedSteps  int
	ToolsUsed     []string
	EstimatedCost string
}

DryRunEvent is fired when a dry run simulation completes.

type ExecutionHook

type ExecutionHook interface {
	// OnIterationStart is called before each adaptive loop iteration executes.
	OnIterationStart(ctx context.Context, event IterationStartEvent)

	// OnIterationEnd is called after each adaptive loop iteration completes,
	// with the iteration's result status and tool usage.
	OnIterationEnd(ctx context.Context, event IterationEndEvent)

	// OnReflection is called after a RAR reflection step completes.
	OnReflection(ctx context.Context, event ReflectionEvent)

	// OnToolValidation is called when the critic middleware evaluates a tool call.
	OnToolValidation(ctx context.Context, event ToolValidationEvent)

	// OnDryRun is called when a dry run simulation completes.
	OnDryRun(ctx context.Context, event DryRunEvent)

	// OnPlanExecution is called when the orchestrator starts executing a plan.
	OnPlanExecution(ctx context.Context, event PlanExecutionEvent)
}

ExecutionHook defines lifecycle callbacks for ReAcTree execution. All methods are optional — implementations may embed NoOpHook to get default no-op behavior and override only the hooks they care about.

type IterationEndEvent

type IterationEndEvent struct {
	Iteration      int
	Status         string         // "running", "success", "failure"
	ToolCallCounts map[string]int // per-tool call counts for this iteration
	TaskCompleted  bool
	Output         string
}

IterationEndEvent is fired at the end of each adaptive loop iteration.

type IterationStartEvent

type IterationStartEvent struct {
	Goal          string
	Iteration     int
	MaxIterations int
}

IterationStartEvent is fired at the beginning of each adaptive loop iteration.

type NoOpHook

type NoOpHook struct{}

NoOpHook is a default implementation that does nothing. Embed this in custom hook implementations to avoid implementing every method.

func (NoOpHook) OnDryRun

func (NoOpHook) OnDryRun(_ context.Context, _ DryRunEvent)

func (NoOpHook) OnIterationEnd

func (NoOpHook) OnIterationEnd(_ context.Context, _ IterationEndEvent)

func (NoOpHook) OnIterationStart

func (NoOpHook) OnIterationStart(_ context.Context, _ IterationStartEvent)

func (NoOpHook) OnPlanExecution

func (NoOpHook) OnPlanExecution(_ context.Context, _ PlanExecutionEvent)

func (NoOpHook) OnReflection

func (NoOpHook) OnReflection(_ context.Context, _ ReflectionEvent)

func (NoOpHook) OnToolValidation

func (NoOpHook) OnToolValidation(_ context.Context, _ ToolValidationEvent)

type PlanExecutionEvent

type PlanExecutionEvent struct {
	Flow      string // "sequence", "parallel", "fallback"
	StepCount int
	StepNames []string
}

PlanExecutionEvent is fired when the orchestrator starts executing a plan.

type ReflectionEvent

type ReflectionEvent struct {
	Iteration     int
	Monologue     string
	ShouldProceed bool
}

ReflectionEvent is fired after a RAR reflection step completes.

type ToolValidationEvent

type ToolValidationEvent struct {
	ToolName string
	Allowed  bool
	Reason   string // non-empty when Allowed=false
}

ToolValidationEvent is fired when the critic middleware validates a tool call.

Jump to

Keyboard shortcuts

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