summaryrefslogtreecommitdiff
path: root/Omni
diff options
context:
space:
mode:
Diffstat (limited to 'Omni')
-rw-r--r--Omni/Agent/Worker.hs18
1 files changed, 10 insertions, 8 deletions
diff --git a/Omni/Agent/Worker.hs b/Omni/Agent/Worker.hs
index 869a5b3..a34270c 100644
--- a/Omni/Agent/Worker.hs
+++ b/Omni/Agent/Worker.hs
@@ -248,8 +248,10 @@ runWithEngine worker repo task = do
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))
+ -- For text content, store as-is; for structured data, JSON-encode
+ let logEventText = TaskCore.insertAgentEvent tid sessionId
+ logEventJson eventType value = do
+ let contentJson = TE.decodeUtf8 (BSL.toStrict (Aeson.encode value))
TaskCore.insertAgentEvent tid sessionId eventType contentJson
-- Build Engine config with callbacks
@@ -265,25 +267,25 @@ runWithEngine worker repo task = do
Engine.engineOnCost = \tokens cost -> do
modifyIORef' totalCostRef (+ cost)
sayLog <| "Cost: " <> tshow cost <> " cents (" <> tshow tokens <> " tokens)"
- logEvent "Cost" (Aeson.object [("tokens", Aeson.toJSON tokens), ("cents", Aeson.toJSON cost)]),
+ logEventJson "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
- logEvent "ToolCall" (Aeson.String (toolName <> ": " <> args)),
+ logEventText "ToolCall" (toolName <> ": " <> args),
Engine.engineOnAssistant = \msg -> do
sayLog <| "[assistant] " <> Text.take 200 msg
- logEvent "Assistant" (Aeson.String msg),
+ logEventText "Assistant" msg,
Engine.engineOnToolResult = \toolName success output -> do
let statusStr = if success then "ok" else "failed"
sayLog <| "[result] " <> toolName <> " (" <> statusStr <> "): " <> Text.take 100 output
- logEvent "ToolResult" (Aeson.String output),
+ logEventText "ToolResult" output,
Engine.engineOnComplete = do
sayLog "[engine] Complete"
- logEvent "Complete" Aeson.Null,
+ logEventText "Complete" "",
Engine.engineOnError = \err -> do
sayLog <| "[error] " <> err
- logEvent "Error" (Aeson.String err)
+ logEventText "Error" err
}
-- Build Agent config