diff options
| author | Ben Sima <ben@bensima.com> | 2025-12-19 23:13:46 -0500 |
|---|---|---|
| committer | Ben Sima <ben@bensima.com> | 2025-12-19 23:13:46 -0500 |
| commit | 7724895ef03013f27d43d90ea5acaf2e2e038b9f (patch) | |
| tree | d24c0a1d5ac8bcc64aa185b7260c946d2bfb0d14 /Omni/Agent/Engine.hs | |
| parent | ba466ffdba886d1a30b8fd7c6727ad69a6d40f2c (diff) | |
Omni/Agent: make token explosion impossible
Tools.hs:
- run_bash now uses mkSuccess (applies truncation)
- read_file requires line ranges for files >500 lines
- read_file rejects ranges >400 lines
Engine.hs:
- Added engine-level truncateToolResult (10k char cap)
- Fixed test detection: bash -> run_bash
Diffstat (limited to 'Omni/Agent/Engine.hs')
| -rw-r--r-- | Omni/Agent/Engine.hs | 19 |
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. |
