summaryrefslogtreecommitdiff
path: root/Omni/Agent/Engine.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Omni/Agent/Engine.hs')
-rw-r--r--Omni/Agent/Engine.hs19
1 files changed, 17 insertions, 2 deletions
diff --git a/Omni/Agent/Engine.hs b/Omni/Agent/Engine.hs
index 0dc7c50..343ccc3 100644
--- a/Omni/Agent/Engine.hs
+++ b/Omni/Agent/Engine.hs
@@ -799,8 +799,9 @@ executeToolCallsWithTracking engineCfg toolMap tcs initialTestFailures initialEd
resultValue <- toolExecute tool args
endTime <- Time.getCurrentTime
let durationMs = round (Time.diffUTCTime endTime startTime * 1000)
- resultText = TE.decodeUtf8 (BL.toStrict (Aeson.encode resultValue))
- isTestCall = name == "bash" && ("bild --test" `Text.isInfixOf` argsText || "bild -t" `Text.isInfixOf` argsText)
+ rawResultText = TE.decodeUtf8 (BL.toStrict (Aeson.encode resultValue))
+ resultText = truncateToolResult rawResultText
+ isTestCall = name == "run_bash" && ("bild --test" `Text.isInfixOf` argsText || "bild -t" `Text.isInfixOf` argsText)
isTestFailure = isTestCall && isFailureResult resultValue
testDelta = if isTestFailure then 1 else 0
isEditFailure = name == "edit_file" && isOldStrNotFoundError resultValue
@@ -830,6 +831,20 @@ executeToolCallsWithTracking engineCfg toolMap tcs initialTestFailures initialEd
_ -> False
isOldStrNotFoundError _ = False
+-- | Maximum characters for any tool result (engine-level safety net)
+maxToolResultChars :: Int
+maxToolResultChars = 10000
+
+-- | Truncate tool result if too long (engine-level safety net)
+truncateToolResult :: Text -> Text
+truncateToolResult t
+ | Text.length t <= maxToolResultChars = t
+ | otherwise =
+ Text.take maxToolResultChars t
+ <> "\n\n[TOOL RESULT TRUNCATED by engine - "
+ <> tshow (Text.length t - maxToolResultChars)
+ <> " chars omitted]"
+
-- | Estimate cost in cents from token count.
-- Uses blended input/output rates (roughly 2:1 output:input ratio).
-- Prices as of Dec 2024 from OpenRouter.