hooks

package
v1.8.9 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChainHooks

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

ChainHooks chains multiple hooks together

func NewChainHooks

func NewChainHooks(hooks ...Hooks) *ChainHooks

func (*ChainHooks) Add

func (c *ChainHooks) Add(hook Hooks)

func (*ChainHooks) OnAfterEnd

func (c *ChainHooks) OnAfterEnd(ctx context.Context, hc *HookContext, finalResult *types.AgentResult) error

func (*ChainHooks) OnAfterIteration

func (c *ChainHooks) OnAfterIteration(ctx context.Context, hc *HookContext, iteration int, result *types.AgentResult) error

func (*ChainHooks) OnAfterLLMCall

func (c *ChainHooks) OnAfterLLMCall(ctx context.Context, hc *HookContext, response *types.Message) error

func (*ChainHooks) OnAfterToolCall

func (c *ChainHooks) OnAfterToolCall(ctx context.Context, hc *HookContext, toolName string, output interface{}, err error) error

func (*ChainHooks) OnBeforeIteration

func (c *ChainHooks) OnBeforeIteration(ctx context.Context, hc *HookContext, iteration int) error

func (*ChainHooks) OnBeforeLLMCall

func (c *ChainHooks) OnBeforeLLMCall(ctx context.Context, hc *HookContext, messages []types.Message) error

func (*ChainHooks) OnBeforeStart

func (c *ChainHooks) OnBeforeStart(ctx context.Context, hc *HookContext, input *types.AgentInput) error

func (*ChainHooks) OnBeforeToolCall

func (c *ChainHooks) OnBeforeToolCall(ctx context.Context, hc *HookContext, toolName string, input map[string]interface{}) error

func (*ChainHooks) OnError

func (c *ChainHooks) OnError(ctx context.Context, hc *HookContext, err error) error

type HookContext

type HookContext struct {
	AgentID   string
	SessionID string
	Iteration int
	Timestamp time.Time
	Metadata  map[string]interface{}
}

HookContext holds context information for hook execution

type HookFunc

type HookFunc func(ctx context.Context, hc *HookContext, data interface{}) (interface{}, error)

HookFunc is a function that can be registered as a hook

type Hooks

type Hooks interface {
	// Before execution hooks
	OnBeforeStart(ctx context.Context, hc *HookContext, input *types.AgentInput) error
	OnBeforeIteration(ctx context.Context, hc *HookContext, iteration int) error
	OnBeforeLLMCall(ctx context.Context, hc *HookContext, messages []types.Message) error
	OnBeforeToolCall(ctx context.Context, hc *HookContext, toolName string, input map[string]interface{}) error

	// After execution hooks
	OnAfterToolCall(ctx context.Context, hc *HookContext, toolName string, output interface{}, err error) error
	OnAfterLLMCall(ctx context.Context, hc *HookContext, response *types.Message) error
	OnAfterIteration(ctx context.Context, hc *HookContext, iteration int, result *types.AgentResult) error
	OnAfterEnd(ctx context.Context, hc *HookContext, finalResult *types.AgentResult) error

	// Error hooks
	OnError(ctx context.Context, hc *HookContext, err error) error
}

Hooks defines lifecycle hooks for agent execution

type HooksFunc

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

HooksFunc is a functional adapter for Hooks

func NewHooksFunc

func NewHooksFunc(
	onBeforeStart func(ctx context.Context, hc *HookContext, input *types.AgentInput) error,
	onBeforeIteration func(ctx context.Context, hc *HookContext, iteration int) error,
	onBeforeLLMCall func(ctx context.Context, hc *HookContext, messages []types.Message) error,
	onBeforeToolCall func(ctx context.Context, hc *HookContext, toolName string, input map[string]interface{}) error,
	onAfterToolCall func(ctx context.Context, hc *HookContext, toolName string, output interface{}, err error) error,
	onAfterLLMCall func(ctx context.Context, hc *HookContext, response *types.Message) error,
	onAfterIteration func(ctx context.Context, hc *HookContext, iteration int, result *types.AgentResult) error,
	onAfterEnd func(ctx context.Context, hc *HookContext, finalResult *types.AgentResult) error,
	onError func(ctx context.Context, hc *HookContext, err error) error,
) *HooksFunc

NewHooksFunc creates a new HooksFunc with the given functions

func (*HooksFunc) OnAfterEnd

func (h *HooksFunc) OnAfterEnd(ctx context.Context, hc *HookContext, finalResult *types.AgentResult) error

func (*HooksFunc) OnAfterIteration

func (h *HooksFunc) OnAfterIteration(ctx context.Context, hc *HookContext, iteration int, result *types.AgentResult) error

func (*HooksFunc) OnAfterLLMCall

func (h *HooksFunc) OnAfterLLMCall(ctx context.Context, hc *HookContext, response *types.Message) error

func (*HooksFunc) OnAfterToolCall

func (h *HooksFunc) OnAfterToolCall(ctx context.Context, hc *HookContext, toolName string, output interface{}, err error) error

func (*HooksFunc) OnBeforeIteration

func (h *HooksFunc) OnBeforeIteration(ctx context.Context, hc *HookContext, iteration int) error

func (*HooksFunc) OnBeforeLLMCall

func (h *HooksFunc) OnBeforeLLMCall(ctx context.Context, hc *HookContext, messages []types.Message) error

func (*HooksFunc) OnBeforeStart

func (h *HooksFunc) OnBeforeStart(ctx context.Context, hc *HookContext, input *types.AgentInput) error

func (*HooksFunc) OnBeforeToolCall

func (h *HooksFunc) OnBeforeToolCall(ctx context.Context, hc *HookContext, toolName string, input map[string]interface{}) error

func (*HooksFunc) OnError

func (h *HooksFunc) OnError(ctx context.Context, hc *HookContext, err error) error

type NoOpHooks

type NoOpHooks struct{}

NoOpHooks is a no-op implementation of Hooks

func (NoOpHooks) OnAfterEnd

func (NoOpHooks) OnAfterEnd(ctx context.Context, hc *HookContext, finalResult *types.AgentResult) error

func (NoOpHooks) OnAfterIteration

func (NoOpHooks) OnAfterIteration(ctx context.Context, hc *HookContext, iteration int, result *types.AgentResult) error

func (NoOpHooks) OnAfterLLMCall

func (NoOpHooks) OnAfterLLMCall(ctx context.Context, hc *HookContext, response *types.Message) error

func (NoOpHooks) OnAfterToolCall

func (NoOpHooks) OnAfterToolCall(ctx context.Context, hc *HookContext, toolName string, output interface{}, err error) error

func (NoOpHooks) OnBeforeIteration

func (NoOpHooks) OnBeforeIteration(ctx context.Context, hc *HookContext, iteration int) error

func (NoOpHooks) OnBeforeLLMCall

func (NoOpHooks) OnBeforeLLMCall(ctx context.Context, hc *HookContext, messages []types.Message) error

func (NoOpHooks) OnBeforeStart

func (NoOpHooks) OnBeforeStart(ctx context.Context, hc *HookContext, input *types.AgentInput) error

func (NoOpHooks) OnBeforeToolCall

func (NoOpHooks) OnBeforeToolCall(ctx context.Context, hc *HookContext, toolName string, input map[string]interface{}) error

func (NoOpHooks) OnError

func (NoOpHooks) OnError(ctx context.Context, hc *HookContext, err error) error

type Runner

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

Runner is a helper to run hooks from AgentEngine

func NewRunner

func NewRunner(hooks Hooks, agentID, sessionID string) *Runner

func (*Runner) AfterEnd

func (r *Runner) AfterEnd(finalResult *types.AgentResult) error

func (*Runner) AfterIteration

func (r *Runner) AfterIteration(iteration int, result *types.AgentResult) error

func (*Runner) AfterLLMCall

func (r *Runner) AfterLLMCall(response *types.Message) error

func (*Runner) AfterToolCall

func (r *Runner) AfterToolCall(toolName string, output interface{}, err error) error

func (*Runner) BeforeIteration

func (r *Runner) BeforeIteration(iteration int) error

func (*Runner) BeforeLLMCall

func (r *Runner) BeforeLLMCall(messages []types.Message) error

func (*Runner) BeforeStart

func (r *Runner) BeforeStart(input *types.AgentInput) error

func (*Runner) BeforeToolCall

func (r *Runner) BeforeToolCall(toolName string, input map[string]interface{}) error

func (*Runner) OnError

func (r *Runner) OnError(err error) error

Jump to

Keyboard shortcuts

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