diff options
| author | Ben Sima <ben@bensima.com> | 2025-12-01 10:43:59 -0500 |
|---|---|---|
| committer | Ben Sima <ben@bensima.com> | 2025-12-01 10:43:59 -0500 |
| commit | 046e6d1ca55651379f938b4481570bcb1b122e1e (patch) | |
| tree | 511a0bfaa9f06c58964da24509bb59cc89c954e1 /Omni/Agent/Worker.hs | |
| parent | 661beb3802e3d827febcb163bfb90e4f18ad8127 (diff) | |
Add actor column to agent_events table
- Add 'actor' column to agent_events table (human/junior/system)
- Add System to CommentAuthor type (reused for actor) - Add SQL
FromField/ToField instances for CommentAuthor - Update insertAgentEvent
to accept actor parameter - Update all SELECT queries to include
actor column - Update Worker.hs to pass actor for all event types -
Guardrail events logged with System actor
Migration: ALTER TABLE adds column with default 'junior' for existing
rows.
Task-Id: t-213.1
Diffstat (limited to 'Omni/Agent/Worker.hs')
| -rw-r--r-- | Omni/Agent/Worker.hs | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/Omni/Agent/Worker.hs b/Omni/Agent/Worker.hs index bbdba9d..5fa169f 100644 --- a/Omni/Agent/Worker.hs +++ b/Omni/Agent/Worker.hs @@ -267,10 +267,11 @@ runWithEngine worker repo task = do -- Helper to log events to DB -- For text content, store as-is; for structured data, JSON-encode - let logEventText = TaskCore.insertAgentEvent tid sessionId - logEventJson eventType value = do + let logJuniorEvent eventType content = TaskCore.insertAgentEvent tid sessionId eventType content TaskCore.Junior + logJuniorJson eventType value = do let contentJson = TE.decodeUtf8 (BSL.toStrict (Aeson.encode value)) - TaskCore.insertAgentEvent tid sessionId eventType contentJson + TaskCore.insertAgentEvent tid sessionId eventType contentJson TaskCore.Junior + logSystemEvent eventType content = TaskCore.insertAgentEvent tid sessionId eventType content TaskCore.System -- Build Engine config with callbacks totalCostRef <- newIORef (0 :: Double) @@ -285,29 +286,30 @@ runWithEngine worker repo task = do Engine.engineOnCost = \tokens cost -> do modifyIORef' totalCostRef (+ cost) sayLog <| "Cost: " <> tshow cost <> " cents (" <> tshow tokens <> " tokens)" - logEventJson "Cost" (Aeson.object [("tokens", Aeson.toJSON tokens), ("cents", Aeson.toJSON cost)]), + logJuniorJson "Cost" (Aeson.object [("tokens", Aeson.toJSON tokens), ("cents", Aeson.toJSON cost)]), Engine.engineOnActivity = \activity -> do sayLog <| "[engine] " <> activity, Engine.engineOnToolCall = \toolName args -> do sayLog <| "[tool] " <> toolName - logEventText "ToolCall" (toolName <> ": " <> args), + logJuniorEvent "ToolCall" (toolName <> ": " <> args), Engine.engineOnAssistant = \msg -> do sayLog <| "[assistant] " <> Text.take 200 msg - logEventText "Assistant" msg, + logJuniorEvent "Assistant" msg, Engine.engineOnToolResult = \toolName success output -> do let statusStr = if success then "ok" else "failed" sayLog <| "[result] " <> toolName <> " (" <> statusStr <> "): " <> Text.take 100 output - logEventText "ToolResult" output, + logJuniorEvent "ToolResult" output, Engine.engineOnComplete = do sayLog "[engine] Complete" - logEventText "Complete" "", + logJuniorEvent "Complete" "", Engine.engineOnError = \err -> do sayLog <| "[error] " <> err - logEventText "Error" err, + logJuniorEvent "Error" err, Engine.engineOnGuardrail = \guardrailResult -> do let guardrailMsg = formatGuardrailResult guardrailResult + contentJson = TE.decodeUtf8 (BSL.toStrict (Aeson.encode guardrailResult)) sayLog <| "[guardrail] " <> guardrailMsg - logEventJson "Guardrail" (Aeson.toJSON guardrailResult) + logSystemEvent "Guardrail" contentJson } -- Build Agent config with guardrails |
