Skip to content

Commit f8d1854

Browse files
authored
Advertise full context not just prompt (#3674)
1 parent 0ef3521 commit f8d1854

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

src/extension/intents/node/toolCallingLoop.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,7 @@ export abstract class ToolCallingLoop<TOptions extends IToolCallingLoopOptions =
922922
messages: buildPromptResult.messages,
923923
tokenizer,
924924
tools: availableTools,
925+
maxOutputTokens: endpoint.maxOutputTokens,
925926
});
926927
fetchStreamSource?.resolve();
927928
const chatResult = await processResponsePromise ?? undefined;

src/extension/prompts/node/agent/summarizedConversationHistory.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@ class ConversationHistorySummarizer {
604604
tokenizer,
605605
tools: this.props.tools ?? undefined,
606606
totalPromptTokens: summaryResponse.type === ChatFetchResponseType.Success ? summaryResponse.usage?.prompt_tokens : undefined,
607+
maxOutputTokens: endpoint.maxOutputTokens,
607608
});
608609

609610
return {

src/platform/tokenizer/node/promptTokenDetails.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const PromptTokenLabel = {
2222
// System category
2323
SystemInstructions: 'System Instructions',
2424
Tools: 'Tool Definitions',
25+
ReservedOutput: 'Reserved Output',
2526

2627
// User Context category
2728
Messages: 'Messages',
@@ -222,6 +223,8 @@ export interface IPromptTokenDetailOptions {
222223
totalPromptTokens?: number;
223224
/** The tools available to the model */
224225
tools?: readonly LanguageModelToolInformation[];
226+
/** The maximum output tokens for the model, shown as reserved output in the breakdown */
227+
maxOutputTokens?: number;
225228
}
226229

227230
/**
@@ -353,6 +356,11 @@ export async function computePromptTokenDetails(
353356
counts[PromptTokenCategory.System][PromptTokenLabel.Tools] = toolTokens;
354357
}
355358

359+
// Count reserved output tokens
360+
if (options.maxOutputTokens && options.maxOutputTokens > 0) {
361+
counts[PromptTokenCategory.System][PromptTokenLabel.ReservedOutput] = options.maxOutputTokens;
362+
}
363+
356364
// Calculate total tokens
357365
let totalTokens = options.totalPromptTokens;
358366
if (totalTokens === undefined) {
@@ -361,6 +369,9 @@ export async function computePromptTokenDetails(
361369
totalTokens += await tokenizer.countToolTokens(tools);
362370
}
363371
}
372+
if (options.maxOutputTokens && options.maxOutputTokens > 0) {
373+
totalTokens += options.maxOutputTokens;
374+
}
364375

365376
// Convert counts to percentages
366377
const details: ChatResultPromptTokenDetail[] = [];

0 commit comments

Comments
 (0)