summaryrefslogtreecommitdiff
path: root/Omni/Task
diff options
context:
space:
mode:
authorBen Sima <ben@bensima.com>2025-12-01 10:02:12 -0500
committerBen Sima <ben@bensima.com>2025-12-01 10:02:12 -0500
commitfb019f46c3adcf772df2dacf688cc75c30ed6e8e (patch)
tree1b365bac2cfd513852f73355893ffb9501ece18f /Omni/Task
parentffeb13fb9f2543dfc9cdecf8ed6778226267b403 (diff)
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
Diffstat (limited to 'Omni/Task')
-rw-r--r--Omni/Task/Core.hs23
1 files changed, 23 insertions, 0 deletions
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]