← Table of Contents · Page 383 of 868
THE SAFETY ARCHITECTURE
Part 8 of 13
USER-DEFINED LIFECYCLE HOOKS
A hook is a place where you can attach your own code that runs automatically at a particular moment.
Lifecycle hooks run at defined points in an agent's life, such as before a tool call, after a tool call, when a session starts, or when the agent finishes.
User-defined means the person operating the harness can write them, rather than being limited to built-in rules.
For safety, a before-tool hook is especially powerful.
It receives the planned tool call and may allow it, change it, or block it.
Examples include a hook that blocks any shell command containing a dangerous pattern, a hook that scans outgoing text for secrets such as API keys, a hook that requires a ticket number to be present before a production change, and an after-tool hook that logs the outcome to an audit file.
Because hooks are ordinary code run by the harness, not text the model might ignore, they provide deterministic enforcement, meaning the same input always yields the same decision.
Many coding-agent products offer hook features of this kind, and you will see how to design them in the capstone projects.
Advertisement
Read Aloud:
0:00 / 0:00