v1.6.1

Hooks

Last updated


Added in v1.4.0. A hook is a Python or JavaScript script that Agenvoy runs at a fixed point of every task. It receives that point's data as JSON on stdin and answers whether the task may go on — for blocking a phrase, capping a token budget, or logging and notifying when a tool runs or a task ends.

Where hooks live


LocationScope
~/.config/agenvoy/hooks/<state>.py or .jsEvery task; the only location read
~/.config/agenvoy/hooks/demo/Demo script for every state (.py and .js), installed by make build and shipped in release archives

Project hooks under <work dir>/.config/agenvoy/hooks/ are no longer loaded, so a cloned repository cannot bring hooks that run on their own; put hooks in ~/.config/agenvoy/hooks/ (Removed in v1.5.0). The file name is the state name; any other name is ignored. When both .py and .js exist for one state, .py wins. Hooks are loaded when a task starts; a script removed mid-task is skipped (no block), and one added mid-task takes effect from the next task.

States


StateFiresstdin fields
before_user_sendBefore a new user message runssession, task_hash, input, time
before_tool_callBefore each tool callsession, task_hash, tool_name, tool_args, input_totals, output_totals, hit_totals, time
after_tool_callAfter a tool call succeedssession, task_hash, tool_name, tool_args, tool_result, input_tokens, output_tokens, hit, input_totals, output_totals, hit_totals, during_ms, time
after_tool_errorAfter a tool call failssession, task_hash, tool_name, tool_args, error, time
after_ask_userAfter ask_user is answered, including when a task paused on a question resumessession, task_hash, answers ([{question, answer}]), time
after_task_doneAfter a task finishessession, task_hash, input, result, input_totals, output_totals, hit_totals, during_ms, time
after_task_cancelAfter the user cancels a task (not on pause, error or a pending question)session, task_hash, input, error (always user cancel it), input_totals, output_totals, hit_totals, time

input_totals / output_totals are the task's token totals so far; input_tokens / output_tokens cover the request that produced the tool call; hit / hit_totals are cache-hit percentages; during_ms is that tool call's duration (after_tool_call) or the whole task's (after_task_done); time is RFC 3339.