Skip to content

Commit fa88fc2

Browse files
author
Yetibot
committed
fix: format small agent costs with higher precision instead of rounding to /usr/bin/bash.00
1 parent 641d534 commit fa88fc2

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

src/yetibot/core/commands/agent.clj

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,21 @@
129129
[]
130130
"🐵 Bonzi Buddy is swinging into action! Please wait a moment…")
131131

132+
(defn format-cost
133+
"Format cost to 4 decimal places if it's less than $0.01, otherwise 2 decimal places."
134+
[cost]
135+
(cond
136+
(nil? cost) "0.00"
137+
(zero? cost) "0.00"
138+
(< cost 0.01) (format "%.4f" cost)
139+
:else (format "%.2f" cost)))
140+
132141
(defn say-final
133142
"The clean final reply: Gemini's summary plus links to any relevant PRs."
134143
([summary pr-urls] (say-final summary pr-urls nil))
135144
([summary pr-urls actual-cost]
136145
(let [cost (or actual-cost (gemini/agent-cost-per-session))
137-
footer (format "\n\nSent via %s | Cost: $%.2f" (model) cost)]
146+
footer (format "\n\nSent via %s | Cost: $%s" (model) (format-cost cost))]
138147
(str (if (string/blank? summary) "✅ done." (str "" summary))
139148
(when (seq pr-urls)
140149
(str "\n\n🔗 " (string/join "" (distinct pr-urls))))

test/yetibot/core/test/commands/agent.clj

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,27 @@
8787
(agent/say-final "Added features" nil) => (contains "Sent via gemini-3.1-pro-preview | Cost: $1.00"))
8888
(fact "say-final accepts actual-cost and prints it correctly in the footer"
8989
(agent/say-final "Added features" nil 0.12) => (contains "Sent via gemini-3.1-pro-preview | Cost: $0.12")
90-
(agent/say-final "Added features" nil 1.234) => (contains "Sent via gemini-3.1-pro-preview | Cost: $1.23"))
90+
(agent/say-final "Added features" nil 1.234) => (contains "Sent via gemini-3.1-pro-preview | Cost: $1.23")
91+
(agent/say-final "Added features" nil 0.000475) => (contains "Sent via gemini-3.1-pro-preview | Cost: $0.0005")
92+
(agent/say-final "Added features" nil 0.004) => (contains "Sent via gemini-3.1-pro-preview | Cost: $0.0040")
93+
(agent/say-final "Added features" nil 0.0) => (contains "Sent via gemini-3.1-pro-preview | Cost: $0.00"))
9194
(fact "say-timeout names the limit"
9295
(agent/say-timeout 5) => (contains "5 min")))
9396

97+
(facts "about format-cost"
98+
(fact "nil or zero costs return 0.00"
99+
(agent/format-cost nil) => "0.00"
100+
(agent/format-cost 0) => "0.00"
101+
(agent/format-cost 0.0) => "0.00")
102+
(fact "costs under 0.01 are formatted to 4 decimal places"
103+
(agent/format-cost 0.000475) => "0.0005"
104+
(agent/format-cost 0.004) => "0.0040"
105+
(agent/format-cost 0.0099) => "0.0099")
106+
(fact "costs 0.01 or above are formatted to 2 decimal places"
107+
(agent/format-cost 0.01) => "0.01"
108+
(agent/format-cost 0.12) => "0.12"
109+
(agent/format-cost 1.234) => "1.23"))
110+
94111
(facts "about agent limits config defaults"
95112
(fact "default timeout is 15 minutes"
96113
(agent/agent-timeout-ms) => 900000)

0 commit comments

Comments
 (0)