feat: agent heartbeat system — periodic proactive check-ins (#245)

Phase 1 (Core):
- Migration 000022: agent_heartbeats, heartbeat_run_logs, agent_config_permissions tables
- HeartbeatStore + ConfigPermissionStore interfaces with PG implementations
- HeartbeatTicker: background poll → active hours filter → queue-aware skip → run → smart suppression → deliver/log
- Heartbeat tool: status/get/set/toggle/set_checklist/get_checklist/test/logs actions
- Permission check with wildcard scope matching + TTL cache (60s)
- RPC methods: heartbeat.get/set/toggle/test/logs/checklist.get/checklist.set
- HEARTBEAT.md routed via context file interceptor (read/write for both open + predefined agents)
- Session keys: agent:{id}:heartbeat or agent:{id}💓{ts} (isolated)
- PromptMinimal for heartbeat sessions (like cron/subagent)
- Event broadcasting + cache invalidation via bus (heartbeat + config_perms)
- Gateway wiring: ticker init, event wiring, graceful shutdown

Phase 2 (Integration):
- wakeMode: CronPayload.WakeHeartbeat triggers heartbeat after cron job completes
- Queue-aware: Scheduler.HasActiveSessionsForAgent() skips busy agents
- Stagger: deterministic FNV offset spreads heartbeats across interval
- lightContext: RunRequest.LightContext skips context files, only injects checklist
- System prompt distinguishes cron (user-scheduled tasks) vs heartbeat (autonomous monitoring)
This commit is contained in:
viettranx committed 2026-03-18 13:11:44 +07:00
1 parent da59377387
commit 08a2d95c0c
25 files changed
+2088 -16

No files matched your search

+11
View File
@@ -83,6 +83,17 @@ const (
MethodSend = "send"
)
// Agent heartbeat
const (
MethodHeartbeatGet = "heartbeat.get"
MethodHeartbeatSet = "heartbeat.set"
MethodHeartbeatToggle = "heartbeat.toggle"
MethodHeartbeatTest = "heartbeat.test"
MethodHeartbeatLogs = "heartbeat.logs"
MethodHeartbeatChecklistGet = "heartbeat.checklist.get"
MethodHeartbeatChecklistSet = "heartbeat.checklist.set"
)
// Channel instances management
const (
MethodChannelInstancesList = "channels.instances.list"