summaryrefslogtreecommitdiff
path: root/Omni/Agent/Worker.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Omni/Agent/Worker.hs')
-rw-r--r--Omni/Agent/Worker.hs30
1 files changed, 27 insertions, 3 deletions
diff --git a/Omni/Agent/Worker.hs b/Omni/Agent/Worker.hs
index 61c392b..1c69b15 100644
--- a/Omni/Agent/Worker.hs
+++ b/Omni/Agent/Worker.hs
@@ -243,6 +243,15 @@ runWithEngine repo task = do
-- Select model based on task complexity (simple heuristic)
let model = selectModel task
+ -- Generate session ID for event logging
+ sessionId <- TaskCore.generateSessionId
+ let tid = TaskCore.taskId task
+
+ -- Helper to log events to DB
+ let logEvent eventType content = do
+ let contentJson = TE.decodeUtf8 (BSL.toStrict (Aeson.encode content))
+ TaskCore.insertAgentEvent tid sessionId eventType contentJson
+
-- Build Engine config with callbacks
totalCostRef <- newIORef (0 :: Int)
let engineCfg =
@@ -253,11 +262,26 @@ runWithEngine repo task = do
},
Engine.engineOnCost = \tokens cost -> do
modifyIORef' totalCostRef (+ cost)
- AgentLog.log <| "Cost: " <> tshow cost <> " cents (" <> tshow tokens <> " tokens)",
+ AgentLog.log <| "Cost: " <> tshow cost <> " cents (" <> tshow tokens <> " tokens)"
+ logEvent "cost" (Aeson.object [("tokens", Aeson.toJSON tokens), ("cents", Aeson.toJSON cost)]),
Engine.engineOnActivity = \activity -> do
AgentLog.log <| "[engine] " <> activity,
- Engine.engineOnToolCall = \toolName result -> do
- AgentLog.log <| "[tool] " <> toolName <> ": " <> Text.take 100 result
+ Engine.engineOnToolCall = \toolName args -> do
+ AgentLog.log <| "[tool] " <> toolName
+ logEvent "tool_call" (Aeson.object [("tool", Aeson.toJSON toolName), ("args", Aeson.toJSON args)]),
+ Engine.engineOnAssistant = \msg -> do
+ AgentLog.log <| "[assistant] " <> Text.take 200 msg
+ logEvent "assistant" (Aeson.String msg),
+ Engine.engineOnToolResult = \toolName success output -> do
+ let statusStr = if success then "ok" else "failed"
+ AgentLog.log <| "[result] " <> toolName <> " (" <> statusStr <> "): " <> Text.take 100 output
+ logEvent "tool_result" (Aeson.object [("tool", Aeson.toJSON toolName), ("success", Aeson.toJSON success), ("output", Aeson.toJSON output)]),
+ Engine.engineOnComplete = do
+ AgentLog.log "[engine] Complete"
+ logEvent "complete" Aeson.Null,
+ Engine.engineOnError = \err -> do
+ AgentLog.log <| "[error] " <> err
+ logEvent "error" (Aeson.String err)
}
-- Build Agent config