Loading…
Loading…
Features · Control · Hooks
A hook is a function shipit calls at a point in the run: before a model call, before or after a tool, when the run wants to stop. It can watch, block, or rewrite what happens next.
from shipit_agent import Agent, AgentHookshooks = AgentHooks()@hooks.on_before_tooldef guard(name, arguments): if name == "bash" and "rm -rf" in arguments.get("command", ""): return {"decision": "deny", "reason": "No recursive deletes."}
A step
model call, tool call, stop
Your hook
@hooks.on_before_tool
Its answer
allow, deny, ask or rewrite
The loop
carries on with it
Watch one run, a moment at a time.
Each step lights up as the lines it produces appear. Pause it, or step through it yourself.
0 of 5 · A step
A step
model call, tool call, stop
Your hook
@hooks.on_before_tool
Its answer
allow, deny, ask or rewrite
The loop
carries on with it
The code is a checked example from the docs; the output is an example of what it prints.
from shipit_agent import Agent, AgentHooks
hooks = AgentHooks()
@hooks.on_before_tool
def guard(name, arguments):
if name == "bash" and "rm -rf" in arguments.get("command", ""):
return {"decision": "deny", "reason": "No recursive deletes."}
@hooks.on_after_tool
def log(name, result):
print(f"{name} returned {len(str(result.output))} characters")
agent = Agent.with_builtins(llm=llm, project_root=".", hooks=hooks)
agent.run("Clean the build folder and run the tests.")6 more ways to use it
Each example is from the docs and checked against the library.
from shipit_agent import Agent, AgentHooks
from shipit_agent.llms import OpenAIChatLLM
hooks = AgentHooks()
@hooks.on_before_llm
def log_llm_call(messages, tools):
print(f"Calling LLM with {len(messages)} messages, {len(tools)} tools")
@hooks.on_after_llm
def track_tokens(response):
usage = response.usage
if usage:
print(f"Tokens: {usage.get('total_tokens', 0)}")
@hooks.on_before_tool
def log_tool_start(name, arguments):
print(f"Running {name}...")
@hooks.on_after_tool
def log_tool_end(name, result):
print(f"{name} returned {len(result.output)} chars")
agent = Agent.with_builtins(
llm=OpenAIChatLLM(model="gpt-5.5"),
hooks=hooks,
)
result = agent.run("What is the weather in Tokyo?")Every step has one
Before and after the model, around each tool, on failure, on stop, on compaction and around sub-agents.
Block or rewrite
A before-tool hook can deny a call, ask for approval, or change its arguments.
Redaction that holds
Replace a tool's output and the model reads the replacement, not the original.
Session events
In the SDK API, SessionStart and SessionEnd fire around each session.
| Parameter | Default | What it does |
|---|---|---|
| hooks | None | Code run before and after model calls and tools. Hooks. |
| guardrails | None | A `Guardrails` instance: blocks prompt-injection inputs, redacts secrets/PII from outputs, and denies tool calls whose arguments match configured patterns. See `shipit_agent.guardrails`. |
| verify_before_stop | False | Evidence-gated coding: refuse to finish a turn that edited code without fresh passing tests (the verification ledger + verify-on-stop guard). Off by default — it changes the loop's stop behaviour, so a caller opts in. |