Repository navigation
Description
Summary
Add pre_run_config and post_run_config hook arrays to agent schedules, allowing arbitrary setup and teardown steps to run before and after each scheduled task execution.
Inspired by Sympozium's lifecycle hook design, which uses init containers for preRun and follow-up Jobs for postRun. Trinity's equivalent will use lightweight HTTP callbacks or agent-internal script invocations.
Context
Schedules currently fire a single chat message at the agent and record the result. Many automation patterns require work before or after that message:
- preRun examples: fetch fresh context from an API, clone a repo, warm a cache, inject dynamic parameters into the message prompt
- postRun examples: send a Slack notification with the result, upload artifacts, trigger a downstream webhook, clean up temp files
Without hooks, users must bake all setup/teardown logic into the agent's CLAUDE.md or the schedule message itself — polluting the agent's core instructions and making schedules fragile.
Sympozium's design also supports a response gate variant of postRun (a hook with gate: true) that blocks the agent's output from reaching users until an operator approves, rejects, or rewrites it. That gate feature will be tracked separately in a companion issue.
Acceptance Criteria
-
agent_schedulestable gainspre_run_configandpost_run_configJSON columns (nullable, versioned migration) -
pre_run_configschema:{ type: "webhook" | "script", url?: string, command?: string, timeout_seconds?: int, env?: Record<string,string> } -
post_run_configschema: same as above, plus{ inject_result: bool }to passAGENT_RESULTto the hook -
task_execution_service.pyexecutes pre_run hook before sending the chat message; on hook failure the execution is markedfailedwitherror: "pre_run_hook_failed: ..." -
task_execution_service.pyexecutes post_run hook after receiving the agent response; hook failure is logged but does not retroactively fail the execution (fire-and-forget) - Schedule create/update API (
POST/PUT /api/agents/{name}/schedules) accepts and validates hook config - UI: Schedule form shows collapsible "Advanced: Lifecycle Hooks" section with webhook URL + timeout inputs
- Existing schedules without hooks are unaffected (fully backward-compatible)
- Unit tests cover: pre_run failure stops execution, post_run failure is non-fatal, result injection into post_run env
Technical Notes
- Schema change: add to
db/schema.pyAGENT_SCHEDULES table; versioned migration indb/migrations.py - Implementation seam:
services/task_execution_service.pyaround theagent_client.chat()call - Webhook execution: use
httpx.AsyncClientwith configurable timeout; pass{"agent_name", "schedule_id", "execution_id", "message"}as JSON body - Keep hook execution out of the critical path for slot accounting — release the capacity slot after post_run, not before
- Related: Sympozium
docs/concepts/lifecycle-hooks.md,internal/controller/agentrun_controller.go
Activity
docs(aauth): person-token binding flow, §32.9, bind.sh, debt entries …
feat(aauth): person-token binding through a person server — an agent …
feat(aauth): outbound resource client + call_aauth_resource — an agen…