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 ¶
- type ChainHook
- func (c *ChainHook) OnDryRun(ctx context.Context, event DryRunEvent)
- func (c *ChainHook) OnIterationEnd(ctx context.Context, event IterationEndEvent)
- func (c *ChainHook) OnIterationStart(ctx context.Context, event IterationStartEvent)
- func (c *ChainHook) OnPlanExecution(ctx context.Context, event PlanExecutionEvent)
- func (c *ChainHook) OnReflection(ctx context.Context, event ReflectionEvent)
- func (c *ChainHook) OnToolValidation(ctx context.Context, event ToolValidationEvent)
- type DryRunEvent
- type ExecutionHook
- type IterationEndEvent
- type IterationStartEvent
- type NoOpHook
- func (NoOpHook) OnDryRun(_ context.Context, _ DryRunEvent)
- func (NoOpHook) OnIterationEnd(_ context.Context, _ IterationEndEvent)
- func (NoOpHook) OnIterationStart(_ context.Context, _ IterationStartEvent)
- func (NoOpHook) OnPlanExecution(_ context.Context, _ PlanExecutionEvent)
- func (NoOpHook) OnReflection(_ context.Context, _ ReflectionEvent)
- func (NoOpHook) OnToolValidation(_ context.Context, _ ToolValidationEvent)
- type PlanExecutionEvent
- type ReflectionEvent
- type ToolValidationEvent
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) 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 ¶
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 ¶
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) 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 ¶
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.