Loop Hooks
Loop hooks provide 5 intercept points inside the LLM tool-calling loop, enabling per-roundtrip control over messages, tool execution, and cost management.Hook Interface
Usage
Hook Points
| Hook | When | Can Modify |
|---|---|---|
beforeLLMCall | Before each LLM API call | Return new messages array |
afterLLMCall | After LLM response | Read-only |
beforeToolExec | Before each tool execution | Skip tool, provide mock result |
afterToolExec | After each tool execution | Transform the result string |
onRoundtripComplete | After all tools in a roundtrip | Stop the loop early |