From fb019f46c3adcf772df2dacf688cc75c30ed6e8e Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Mon, 1 Dec 2025 10:02:12 -0500 Subject: Add guardrails and progress tracking to Jr agent Implement runtime guardrails in Engine.hs: - Cost budget limit (default 200 cents) - Token budget limit (default 1M tokens) - Duplicate tool call detection (same tool called N times) - Test failure counting (bild --test failures) Add database-backed progress tracking: - Checkpoint events stored in agent_events table - Progress summary retrieved on retry attempts - Improved prompts emphasizing efficiency and autonomous operation Worker.hs improvements: - Uses guardrails configuration - Reports guardrail violations via callbacks - Better prompt structure for autonomous operation Task-Id: t-203 --- Omni/Task/Core.hs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'Omni/Task/Core.hs') diff --git a/Omni/Task/Core.hs b/Omni/Task/Core.hs index f54cf81..1212a56 100644 --- a/Omni/Task/Core.hs +++ b/Omni/Task/Core.hs @@ -1702,3 +1702,26 @@ getEventsSince sessionId lastId = "SELECT id, task_id, session_id, timestamp, event_type, content \ \FROM agent_events WHERE session_id = ? AND id > ? ORDER BY id ASC" (sessionId, lastId) + +-- | Insert a checkpoint event (for progress tracking) +insertCheckpoint :: Text -> Text -> Text -> IO () +insertCheckpoint taskId sessionId = + insertAgentEvent taskId sessionId "Checkpoint" + +-- | Get all checkpoints for a task (across all sessions) +getCheckpointsForTask :: Text -> IO [StoredEvent] +getCheckpointsForTask taskId = + withDb <| \conn -> + SQL.query + conn + "SELECT id, task_id, session_id, timestamp, event_type, content \ + \FROM agent_events WHERE task_id = ? AND event_type = 'Checkpoint' ORDER BY id ASC" + (SQL.Only taskId) + +-- | Get progress summary for a task (concatenated checkpoint contents) +getProgressSummary :: Text -> IO (Maybe Text) +getProgressSummary taskId = do + checkpoints <- getCheckpointsForTask taskId + if null checkpoints + then pure Nothing + else pure <| Just <| T.intercalate "\n\n---\n\n" [storedEventContent e | e <- checkpoints] -- cgit v1.2.3