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.

The Hook trait

trait Hook: Send + Sync {
    fn on_build_agent(&self, config: &mut AgentConfig);
    fn on_register_tools(&self, registry: &mut ToolRegistry);
    fn on_event(&self, event: &AgentEvent);
}
MethodWhen it runsWhat it does
on_build_agentAgent is createdModify config, inject system prompt extensions
on_register_toolsRuntime is constructedAdd tool schemas to the registry
on_eventEvery agent eventObserve text deltas, tool calls, completions

Built-in hooks

The daemon composes several hooks into DaemonHook:

HookTools registeredPurpose
InMemoryremember, recallPersistent memory
SkillHandlersearch_skill, load_skillSkill discovery
McpHandlersearch_mcp, call_mcp_toolMCP integration
OsHookread, write, bashFilesystem and shell

Memory as a hook

Every type that implements Memory + Clone + 'static automatically implements Hook. This means any memory backend can be used as a hook — it registers remember and recall tools and injects stored knowledge into the system prompt via on_build_agent.

See memory for details on how knowledge is compiled into prompts.

Composition

DaemonHook dispatches tool calls by name. When an agent invokes a tool, the hook routes it to the correct handler:

  • remember / recall → Memory handler
  • read / write / bash → OS handler
  • search_skill / load_skill → Skill handler
  • search_mcp / call_mcp_tool → MCP handler

This keeps tool dispatch centralized and makes it easy to add new tools by adding new sub-hooks.

What's next

  • Agents — how agents are configured and executed
  • Built-in tools — OsHook details
  • Memory — how memory hooks inject knowledge

On this page