You want your AI assistant to send you a Telegram message whenever a long-running agent finishes its work. Or you want to block certain tools from running without your approval. Or you want every research task to automatically save its results to a file.
Meggy's Hooks system makes this possible. Hooks are user-configurable rules that fire automatically when specific events happen — no code required. Think of them as "if this, then that" for your AI assistant.
A hook consists of two parts:
You create hooks through a simple UI that lets you pick an event, configure conditions, and choose one or more actions. Once saved, hooks run automatically in the background.
Meggy exposes 20 lifecycle events that you can hook into:
| Event | When It Fires |
|---|---|
agentStarted |
An agent begins execution |
agentCompleted |
An agent finishes successfully |
agentFailed |
An agent encounters an error |
agentSuspended |
An agent is paused |
agentResumed |
A paused agent resumes |
| Event | When It Fires |
|---|---|
toolCallRequested |
The AI wants to call a tool |
toolCallApproved |
A tool call was approved |
toolCallRejected |
A tool call was rejected |
toolCallCompleted |
A tool finished executing |
toolCallFailed |
A tool encountered an error |
| Event | When It Fires |
|---|---|
messageReceived |
A new message arrives (any channel) |
messageSent |
A response is sent |
channelConnected |
A messaging channel comes online |
channelDisconnected |
A messaging channel goes offline |
| Event | When It Fires |
|---|---|
deviceDiscovered |
A new smart device appears on the network |
deviceOnline |
A device comes back online |
deviceOffline |
A device goes offline |
| Event | When It Fires |
|---|---|
scheduledTaskRan |
A scheduled task executed |
memoryUpdated |
A new fact was stored in memory |
vaultIngested |
A new document was added to the vault |
When a hook fires, it can execute one or more of 6 action types:
Block or allow the event from proceeding. Useful for implementing safety policies.
Example: Block all terminal tool calls unless you explicitly approve them.
Write event details to a log file or the system log.
Example: Log every tool call with its arguments and results for auditing.
Send a notification through a connected channel (desktop notification, Telegram, WhatsApp, Email).
Example: Send a Telegram message when an agent finishes a long research task.
Trigger another agent or action in response to the event.
Example: When a research agent completes, automatically start a summary agent on its output.
Execute a shell script or Node.js snippet.
Example: Run a backup script whenever a new document is added to the vault.
Modify the event's data before it continues through the pipeline.
Example: Append a disclaimer to every outbound email message.
Here are some practical hooks you might set up:
| Goal | Event | Action |
|---|---|---|
| Stay informed | agentCompleted |
Notify → Send Telegram message with the result summary |
| Safety guardrails | toolCallRequested (tool = delete_file) |
Gate → Block and ask for confirmation |
| Audit trail | toolCallCompleted |
Log → Write tool name, arguments, and result to audit.log |
| Workflow chains | agentCompleted (agent = "Researcher") |
Chain → Start "Writer" agent with the research results |
| Smart home alerts | deviceOffline |
Notify → Send desktop notification |
| Auto-backup | vaultIngested |
Script → Run backup script to copy vault database |
Hooks support conditions that limit when they fire:
This lets you create precise rules without getting overwhelmed by notifications.
Hooks are powerful because they let your AI assistant work for you even when you're not actively using it. Set up the rules once, and Meggy follows them automatically.