Hooks
Hooks react to events in the chat and tool lifecycle.
Navigation
- Service hooks: observe and control the send loop lifecycle via
service.hook().beforeSendLoop().do(cb) - Stream hooks: observe streaming output (content, reasoning, tool-call deltas, usage, finish) via
service.stream().hook().chunks().do(cb) - Chat hooks: subscribe to messages by role/regex
- Tool hooks: before, after, and error hooks on tool execution
- JSON hooks: declare hooks as
.jsonfiles in a configurable directory, auto-loaded on init/send - HookMessageWriter: how hooks queue messages with
origin: Hook
Framework types
Two base types support the hook builders:
HookBuilderBase<TCallback>: abstract base for the filter and message hook builders. Declares the abstract.do(cb)contract: implementations register the hook and return aHookfor disposal. The entry buildersChatHookBuilder,ToolHookBuilder,StreamHookBuilder, andServiceHookBuilderdo not extend it.HasHooks<THookBuilder>: interface for any class that exposes a.hook()method returning a builder. Implemented byChatInterface,ChunkStreamInterface,ToolSuiteInterface, andChatService.
HookBuilderBase and HasHooks come from @johannes.latzel/llm-chat-tool; this package does not re-export them. ToolHookBuilder is also from that package. ServiceHookBuilder is also part of this package and is returned by service.hook().