OpenWalrusOpenWalrus

Hooks

The Hook trait — compose agent behaviors by registering tools, enriching configs, and observing events.

Hooks let you inject behavior into the agent lifecycle without modifying agents directly. They're the primary extension point in OpenWalrus — both in-process hooks and external extensions implement the same lifecycle callbacks.

The Hook trait

trait Hook: Send + Sync {
    fn on_build_agent(&self, config: AgentConfig) -> AgentConfig;
    fn on_register_tools(&self, registry: &mut ToolRegistry);
    fn on_event(&self, agent: &str, event: &AgentEvent);
    fn on_compact(&self, prompt: &mut String);
}

All methods have default no-op implementations. You only override what you need.

MethodWhen it runsWhat it does
on_build_agentAgent is createdEnrich config, inject system prompt extensions
on_register_toolsRuntime is constructedAdd tool schemas to the registry
on_eventEvery agent eventObserve text deltas, tool calls, completions
on_compactContext compactionEnrich the compaction prompt

In-process hooks

The daemon composes several hooks into DaemonHook:

HookTools registeredPurpose
SkillHandlersearch_skill, load_skillSkill discovery
McpHandlersearch_mcp, call_mcp_toolMCP integration
OsHookread, write, edit, bashFilesystem and shell
TaskRegistrydelegate, collectContext isolation

External extensions

Memory, search, and other capabilities run as external extensions. They communicate over protobuf and implement the same lifecycle callbacks (BuildAgent, BeforeRun, Compact, EventObserver, AfterRun, Infer, AfterCompact) via the Walrus Extension Protocol.

ServiceToolsCapabilities
Searchweb_searchTools

Third-party extensions use the same protocol as official ones — the daemon treats all extensions equally.

DaemonHook composition

DaemonHook is the central composition point. It holds in-process hooks plus the service registry for external extensions:

FieldTypeDescription
skillsSkillHandlerSkill registry and loader
mcpMcpHandlerMCP server bridge
tasksArc<Mutex<TaskRegistry>>Agent delegation registry
downloadsArc<Mutex<DownloadRegistry>>Hub download tracker
permissionsPermissionConfigPer-tool permission rules
scopesBTreeMapPer-agent tool whitelists
registryOption<ServiceRegistry>External extension handles

Tool dispatch

When an agent invokes a tool, DaemonHook::dispatch_tool routes it:

  1. Permission check — resolves Allow/Ask/Deny
  2. Scope check — verifies the tool is in the agent's whitelist
  3. Route by name — dispatches to the correct handler:
ToolsHandler
read, write, edit, bashOS (in-process)
search_skill, load_skillSkills (in-process)
search_mcp, call_mcp_toolMCP (in-process)
delegate, collectTasks (in-process)
Tools registered by extensionsServiceRegistry (external)
Unknown toolsForwarded to MCP bridge (fallback)

What's next

  • Agents — how agents are configured and scoped
  • Built-in tools — OsHook details
  • Tasks — context isolation via delegate and collect
  • Extensions — external extension architecture

On this page