Event Hooks โ Auto-Trigger at Key Moments
Event Hooks โ Auto-Trigger at Key Moments โ easy-to-understand guide based on official docs (updated 2026-08-09)
Think of event hooks like a smart doorbell that not only rings when someone arrives, but also automatically unlocks the door, turns on the lights, and texts you a photo โ all without you lifting a finger.
In Hermes Agent, event hooks are small pieces of code that run automatically at specific moments in your agentโs life. Instead of manually checking โdid the agent finish?โ or โdid a new chat start?โ, you can set up hooks to do something useful at exactly the right time.
Four Ways to Hook In
Hermes gives you four different hook systems, each with its own job:
| System | Best for |
|---|---|
| Gateway hooks | Logging, alerts, webhooks (Gateway only) |
| Plugin hooks | Tool interception, metrics, guardrails (CLI + Gateway) |
| Shell hooks | Drop-in scripts for blocking, auto-formatting (CLI + Gateway) |
| Outbound webhooks | Push signed events to external HTTP endpoints (CLI + Gateway) |
Donโt worry about memorizing all four. Start with Gateway hooks โ theyโre the easiest to understand.
Your First Gateway Hook
Gateway hooks live in ~/.hermes/hooks/. Each hook is a folder with two files:
~/.hermes/hooks/
โโโ my-hook/
โโโ HOOK.yaml # Tells Hermes which events to listen for
โโโ handler.py # The code that runs when an event fires
Step 1: Declare Events in HOOK.yaml
name: my-hook
description: Log all agent activity to a file
events:
- agent:start
- agent:end
Step 2: Write the Handler
import json
from datetime import datetime
from pathlib import Path
LOG_FILE = Path.home() / ".hermes" / "hooks" / "my-hook" / "activity.log"
async def handle(event_type: str, context: dict):
entry = {
"timestamp": datetime.now().isoformat(),
"event": event_type,
**context,
}
with open(LOG_FILE, "a") as f:
f.write(json.dumps(entry) + "\n")
Three simple rules for handlers:
- The function must be named
handle - It receives
event_type(a string) andcontext(a dictionary) - It can be
asyncor regular โ both work
What Can You Listen For?
Here are some useful events:
| Event | When it fires |
|---|---|
gateway:startup |
Gateway process starts |
session:start |
New chat session begins |
session:reset |
User runs /new |
agent:start |
Agent starts processing a message |
agent:end |
Agent finishes processing |
You can even use wildcards like command:* to catch a whole family of events.
The Best Part: Hooks Canโt Crash Your Agent
If your hook code has a bug, Hermes catches the error, logs it, and moves on. Your agent keeps working. This means you can experiment freely without fear of breaking things.
Summary & Practical Tip
Event hooks are your agentโs โauto-pilotโ โ they run at key moments to handle logging, alerts, or any custom logic you dream up. Start small: create a hook that logs agent:start and agent:end to a file. Once you see it working, expand to other events.
Pro tip: Use session:compress events to track when your agentโs context gets compacted. If you notice frequent compression, itโs a sign your conversations are getting too long โ consider telling users to start fresh sessions more often.
๐ Official Docs
This article is based on the official Hermes Agent documentation:Official docs โบ user-guide/features/hooks