Documentation
¶
Index ¶
- type API
- type BeforeAgentStartHook
- type ContextHook
- type Extension
- type Host
- func (h *Host) FireBeforeAgentStart(ctx context.Context) []core.AgentMessage
- func (h *Host) FireContext(ctx context.Context, msgs []core.AgentMessage) []core.AgentMessage
- func (h *Host) FireObserver(event core.AgentEvent)
- func (h *Host) FireToolCall(ctx context.Context, name string, args map[string]any) *core.ToolCallDecision
- func (h *Host) FireToolResult(ctx context.Context, name string, result core.Result, isError bool) core.Result
- func (h *Host) Load(ext Extension) error
- type ObserverHook
- type ToolCallHook
- type ToolResultHook
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 (*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.
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.