Skip to content

Commit 7994880

Browse files
committed
fix(usage): suppress unknown total-only cost
1 parent afe75b3 commit 7994880

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

src/auto-reply/reply/agent-runner.misc.runreplyagent.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2744,11 +2744,21 @@ describe("runReplyAgent response usage footer", () => {
27442744
const res = await createRun({
27452745
responseUsage: "full",
27462746
sessionKey: "agent:main:whatsapp:dm:+1000",
2747+
config: {
2748+
models: {
2749+
providers: {
2750+
anthropic: {
2751+
models: [{ id: "claude", cost: { input: 3, output: 15 } }],
2752+
},
2753+
},
2754+
},
2755+
},
27472756
});
27482757
const payload = Array.isArray(res) ? res[0] : res;
27492758
const text = payload?.text ?? "";
27502759
expect(text).toContain("↕️ 1.3k");
27512760
expect(text).not.toContain("↕️ ?/?");
2761+
expect(text).not.toContain("💰");
27522762
expect(text).not.toContain("Usage:");
27532763
});
27542764

src/auto-reply/reply/agent-runner.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,6 +1738,12 @@ export async function runReplyAgent(params: {
17381738
}
17391739

17401740
const usage = runResult.meta?.agentMeta?.usage;
1741+
const hasBillableUsageBuckets =
1742+
usage &&
1743+
(usage.input !== undefined ||
1744+
usage.output !== undefined ||
1745+
usage.cacheRead !== undefined ||
1746+
usage.cacheWrite !== undefined);
17411747
const promptTokens = runResult.meta?.agentMeta?.promptTokens;
17421748
const modelUsed = runResult.meta?.agentMeta?.model ?? fallbackModel ?? defaultModel;
17431749
const providerUsed =
@@ -1773,7 +1779,7 @@ export async function runReplyAgent(params: {
17731779
followupRun.run.provider && followupRun.run.model
17741780
? `${followupRun.run.provider}/${followupRun.run.model}`
17751781
: undefined,
1776-
turnUsd: usage
1782+
turnUsd: hasBillableUsageBuckets
17771783
? estimateUsageCost({
17781784
usage,
17791785
cost: resolveModelCostConfig({
@@ -2130,7 +2136,9 @@ export async function runReplyAgent(params: {
21302136
model: modelUsed,
21312137
config: cfg,
21322138
});
2133-
const costUsd = estimateUsageCost({ usage, cost: costConfig });
2139+
const costUsd = hasBillableUsageBuckets
2140+
? estimateUsageCost({ usage, cost: costConfig })
2141+
: undefined;
21342142
emitTrustedDiagnosticEvent({
21352143
type: "model.usage",
21362144
...(runResult.diagnosticTrace

0 commit comments

Comments
 (0)