docs(hooks): update SetHooks examples for error return

This commit is contained in:
xj 2026-02-22 19:28:48 -08:00
parent fed2093260
commit 91e48583d8
2 changed files with 5 additions and 3 deletions

View file

@ -1008,7 +1008,7 @@ This keeps the runtime lightweight while making new OpenAI-compatible backends m
PicoClaw provides typed lifecycle hooks for observability, outbound filtering, and tool guardrails. PicoClaw provides typed lifecycle hooks for observability, outbound filtering, and tool guardrails.
- Register hooks in Go at startup with `hooks.NewHookRegistry()`. - Register hooks in Go at startup with `hooks.NewHookRegistry()`.
- Attach once via `agentLoop.SetHooks(registry)` before `Run()`. - Attach once via `agentLoop.SetHooks(registry)` before `Run()` and handle setup errors.
- If hooks are not set, default behavior is unchanged. - If hooks are not set, default behavior is unchanged.
See runnable examples: [docs/hooks-plugin-examples.md](docs/hooks-plugin-examples.md) See runnable examples: [docs/hooks-plugin-examples.md](docs/hooks-plugin-examples.md)

View file

@ -15,7 +15,7 @@ PicoClaw's plugin model is a startup-time hook registry:
1. Build a registry (`hooks.NewHookRegistry()`). 1. Build a registry (`hooks.NewHookRegistry()`).
2. Register one or more handlers per lifecycle hook with priority. 2. Register one or more handlers per lifecycle hook with priority.
3. Attach once with `agentLoop.SetHooks(registry)` before `agentLoop.Run(...)`. 3. Attach once with `agentLoop.SetHooks(registry)` before `agentLoop.Run(...)` (check error).
4. Agent loop triggers hook handlers at specific lifecycle points. 4. Agent loop triggers hook handlers at specific lifecycle points.
Execution semantics: Execution semantics:
@ -114,7 +114,9 @@ Attach once during startup:
```go ```go
agentLoop := agent.NewAgentLoop(cfg, msgBus, provider) agentLoop := agent.NewAgentLoop(cfg, msgBus, provider)
agentLoop.SetHooks(buildHooks()) // Must be called before Run() if err := agentLoop.SetHooks(buildHooks()); err != nil {
panic(err) // replace with your startup error handling
}
``` ```
## Priority and Cancellation ## Priority and Cancellation