extension

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API interface {
	// Typed hook registration
	OnBeforeAgentStart(fn BeforeAgentStartHook)
	OnAgentEnd(fn ObserverHook)
	OnTurnStart(fn ObserverHook)
	OnTurnEnd(fn ObserverHook)
	OnToolCall(fn ToolCallHook)
	OnToolResult(fn ToolResultHook)
	OnContext(fn ContextHook)

	// Tool registration
	RegisterTool(t core.Tool) error
	UnregisterTool(name string)

	// Logging
	Logger() *slog.Logger
}

API is what extensions receive to interact with the agent.

type BeforeAgentStartHook

type BeforeAgentStartHook func(ctx context.Context) (inject []core.AgentMessage, err error)

BeforeAgentStartHook: can inject messages before the first LLM call. Blocking, 200ms deadline.

type ContextHook

type ContextHook func(ctx context.Context, messages []core.AgentMessage) ([]core.AgentMessage, error)

ContextHook: can modify the message list before convertToLLM. Blocking, 500ms deadline (context manipulation may be heavier).

type Extension

type Extension interface {
	// Init is called once when the extension is loaded.
	// Use api to register hooks, tools, and commands.
	Init(api API) error
}

Extension is a Go-native extension that registers hooks and tools.

type Host

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

Host manages loaded extensions and dispatches hooks with deadlines and panic recovery.

func NewHost

func NewHost(tools *core.Registry, logger *slog.Logger) *Host

NewHost creates an extension host.

func (*Host) FireBeforeAgentStart

func (h *Host) FireBeforeAgentStart(ctx context.Context) []core.AgentMessage

FireBeforeAgentStart calls all before_agent_start hooks, collects injected messages. Each hook runs with a deadline. Panics are recovered and logged.

func (*Host) FireContext

func (h *Host) FireContext(ctx context.Context, msgs []core.AgentMessage) []core.AgentMessage

FireContext runs context hooks in order. Each receives and returns the message list.

func (*Host) FireObserver

func (h *Host) FireObserver(event core.AgentEvent)

FireObserver dispatches observer hooks with a timeout. Each hook runs in its own goroutine with panic recovery and a deadline. A semaphore limits concurrent observer goroutines to prevent leaks from slow/blocking hooks.

func (*Host) FireToolCall

func (h *Host) FireToolCall(ctx context.Context, name string, args map[string]any) *core.ToolCallDecision

FireToolCall runs tool_call hooks. Returns first blocking decision, or nil.

func (*Host) FireToolResult

func (h *Host) FireToolResult(ctx context.Context, name string, result core.Result, isError bool) core.Result

FireToolResult runs tool_result hooks. Returns modified result (or original).

func (*Host) Load

func (h *Host) Load(ext Extension) error

Load initializes an extension, giving it access to register hooks and tools. If Init returns an error, any hooks or tools registered during Init are rolled back.

type ObserverHook

type ObserverHook func(ctx context.Context, event core.AgentEvent)

ObserverHook: fire-and-forget. Return value ignored. Async, no deadline.

type ToolCallHook

type ToolCallHook func(ctx context.Context, toolName string, args map[string]any) *core.ToolCallDecision

ToolCallHook: can block a tool call before execution. Blocking, 200ms deadline.

type ToolResultHook

type ToolResultHook func(ctx context.Context, toolName string, result core.Result, isError bool) (*core.Result, error)

ToolResultHook: can observe or modify a tool result after execution. Blocking, 200ms deadline.

Jump to

Keyboard shortcuts

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