Skip to content

Commit 90318ce

Browse files
changin token count wording
1 parent 9cffd3c commit 90318ce

3 files changed

Lines changed: 5 additions & 10 deletions

File tree

lib/messages/inject.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ const buildContextPressureTools = (state: SessionState, config: PluginConfig): s
141141
const paramKey = extractParameterKey(entry.tool, entry.parameters)
142142
const description = paramKey ? `${entry.tool}, ${paramKey}` : entry.tool
143143
const tokens = entry.tokenCount ?? 0
144-
const tokenSuffix = entry.tokenCount !== undefined ? ` (~${entry.tokenCount} tokens)` : ""
144+
const tokenSuffix = entry.tokenCount !== undefined ? ` (${entry.tokenCount} tokens)` : ""
145145
lines.push({ tokens, text: `- ${description}${tokenSuffix}` })
146146
})
147147

lib/messages/utils.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -269,24 +269,19 @@ export const findMessageIndex = (messages: WithParts[], messageId: string): numb
269269
return messages.findIndex((msg) => msg.info.id === messageId)
270270
}
271271

272-
function formatTokenCount(n: number): string {
273-
if (n >= 1000) return `${(n / 1000).toFixed(1)}k tokens`
274-
return `${n} tokens`
275-
}
276-
277272
export function annotateContext(messages: WithParts[]): void {
278273
for (const msg of messages) {
279274
const parts = Array.isArray(msg.parts) ? msg.parts : []
280275
for (const part of parts) {
281276
if (part.type !== "tool") continue
282277
const tokens = countToolTokens(part)
283278
if (tokens <= 0) continue
284-
const tag = `[${formatTokenCount(tokens)}]`
279+
const tag = `[This tool added ${tokens} tokens to the context]\n---\n`
285280
if (part.state?.status === "completed" && typeof part.state.output === "string") {
286-
part.state.output = `${tag}\n${part.state.output}`
281+
part.state.output = `${tag}${part.state.output}`
287282
}
288283
if (part.state?.status === "error" && typeof part.state.error === "string") {
289-
part.state.error = `${tag}\n${part.state.error}`
284+
part.state.error = `${tag}${part.state.error}`
290285
}
291286
}
292287
}

lib/state/tool-cache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export function syncToolCache(
7676
tokenCount,
7777
})
7878
logger.info(
79-
`Cached tool id: ${part.callID} (turn ${turnCounter}${tokenCount !== undefined ? `, ~${tokenCount} tokens` : ""})`,
79+
`Cached tool id: ${part.callID} (turn ${turnCounter}${tokenCount !== undefined ? `, ${tokenCount} tokens` : ""})`,
8080
)
8181
}
8282
}

0 commit comments

Comments
 (0)