← Table of Contents · Page 253 of 868

LIFECYCLE HOOKS

Part 7 of 11

EXAMPLES Example 1: A pre-execution deny-list. An agent has a tool that runs commands on a computer. A pre-execution hook examines every command before it runs. Its deny-list includes the pattern for a command that erases the entire file system, written as rm -rf followed by a slash. One day the model, confused, proposes exactly that command. The hook matches the pattern and blocks the call. It returns to the model: "Blocked by safety policy: this command would delete the entire file system. Choose a narrower action." The model then proposes deleting just one temporary folder, which the hook allows. The disaster was prevented without needing the model to be perfect. Example 2: A post-execution logging hook. A team wants complete records of tool usage. They attach a post-execution hook that, after every tool call, writes one line containing the run identifier, tool name, how many milliseconds it took, and whether it succeeded or failed. The agent's own code does not mention logging at all. A month later an engineer analyzes the logs and discovers that one search tool fails 12 percent of the time, which nobody had noticed. The fix is made, and the hook paid for itself many times over. Example 3: An approval hook for a risky action. A finance agent can issue refunds. Refunds under fifty dollars are low risk, and the hook allows them automatically. Refunds of fifty dollars or more are tagged high-risk. When the agent proposes a four-hundred-dollar refund, the approval hook pauses the run and sends a message to a human reviewer, showing the customer, the order, the amount, and the agent's reason. The reviewer checks the order history, agrees, and clicks approve. The run resumes and issues the refund. If the reviewer had not responded in an hour, the hook would have denied the request by default and told the agent to inform the customer that a manager will follow up. Example 4: A continuation hook. A research agent is asked to find five peer-reviewed studies on a topic. After finding two, it writes: "I am not sure how to proceed, the search tool is returning few results." The continuation hook sees the phrase of uncertainty and also checks the goal: only two of five studies have been found, so the success criterion is unmet. It re-injects the goal with a nudge: "Remember, your task is still to find five studies. You have found two. Three approaches you have not tried are searching with synonyms for the topic, searching the reference lists of the studies you found, and searching a different database." The agent resumes, tries the reference lists, and finds the missing studies. The hook allowed one more attempt, with a cap of three, so the run could not loop forever.
Advertisement
Read Aloud:
0:00 / 0:00