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);
}| Method | When it runs | What it does |
|---|---|---|
on_build_agent | Agent is created | Modify config, inject system prompt extensions |
on_register_tools | Runtime is constructed | Add tool schemas to the registry |
on_event | Every agent event | Observe text deltas, tool calls, completions |
Built-in hooks
The daemon composes several hooks into DaemonHook:
| Hook | Tools registered | Purpose |
|---|---|---|
InMemory | remember, recall | Persistent memory |
SkillHandler | search_skill, load_skill | Skill discovery |
McpHandler | search_mcp, call_mcp_tool | MCP integration |
OsHook | read, write, bash | Filesystem 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 handlerread/write/bash→ OS handlersearch_skill/load_skill→ Skill handlersearch_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