-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix: count all tool tokens in budget including deferred tools #4990
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -170,7 +170,7 @@ export class ConversationHistorySummarizationPrompt extends PromptElement<Conver | |
| </SystemMessage> | ||
| {history} | ||
| {this.props.workingNotebook && <WorkingNotebookSummary priority={this.props.priority - 2} notebook={this.props.workingNotebook} />} | ||
| <UserMessage> | ||
| <UserMessage priority={this.props.priority}> | ||
| Summarize the conversation history so far, paying special attention to the most recent agent commands and tool results that triggered this summarization. Structure your summary using the enhanced format provided in the system message.<br /> | ||
| {isOpus && <> | ||
| <br /> | ||
|
|
@@ -664,7 +664,18 @@ class ConversationHistorySummarizer { | |
|
|
||
| private async getSummary(mode: SummaryMode, propsInfo: ISummarizedConversationHistoryInfo): Promise<SummarizationResult> { | ||
| const stopwatch = new StopWatch(false); | ||
| const endpoint = this.props.endpoint; | ||
|
|
||
| // In Full mode, tools are sent alongside the summarization prompt with | ||
| // tool_choice: 'none'. Reserve budget for them so the rendered messages | ||
| // plus tools don't exceed the model's context window. | ||
| const tools = this.props.tools; | ||
| const toolTokens = mode === SummaryMode.Full && tools?.length | ||
| ? await this.props.endpoint.acquireTokenizer().countToolTokens(tools) | ||
| : 0; | ||
| const endpoint = toolTokens > 0 | ||
| ? this.props.endpoint.cloneWithTokenOverride( | ||
| Math.max(1, Math.floor((this.props.endpoint.modelMaxPromptTokens - toolTokens) * 0.9))) | ||
| : this.props.endpoint; | ||
|
Comment on lines
+668
to
+678
|
||
|
|
||
| let summarizationPrompt: ChatMessage[]; | ||
| const associatedRequestId = this.props.promptContext.conversation?.getLatestTurn().id; | ||
|
|
@@ -865,7 +876,8 @@ class ConversationHistorySummarizer { | |
| "promptTokenCount": { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth", "comment": "Number of prompt tokens, server side counted", "isMeasurement": true }, | ||
| "promptCacheTokenCount": { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth", "comment": "Number of prompt tokens hitting cache as reported by server", "isMeasurement": true }, | ||
| "responseTokenCount": { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth", "comment": "Number of generated tokens", "isMeasurement": true }, | ||
| "source": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "Whether the summarization was triggered as a background or foreground operation." } | ||
| "source": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "Whether the summarization was triggered as a background or foreground operation." }, | ||
| "modelMaxPromptTokens": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "comment": "The modelMaxPromptTokens budget used for the summarization prompt rendering." } | ||
| } | ||
| */ | ||
| this.telemetryService.sendMSFTTelemetryEvent('summarizedConversationHistory', { | ||
|
|
@@ -891,6 +903,7 @@ class ConversationHistorySummarizer { | |
| promptTokenCount: usage?.prompt_tokens, | ||
| promptCacheTokenCount: usage?.prompt_tokens_details?.cached_tokens, | ||
| responseTokenCount: usage?.completion_tokens, | ||
| modelMaxPromptTokens: this.props.endpoint.modelMaxPromptTokens, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AgentIntentInvocation’s constructor no longer accepts
IToolDeferralService, but several subclasses (e.g. AskAgentIntentInvocation/EditCode2IntentInvocation/NotebookEditorIntentInvocation) still injecttoolDeferralServiceand pass it tosuper(...). This will fail TypeScript compilation due to an argument count mismatch. Update those subclasses to remove the extra DI parameter + super argument (and remove now-unused imports) to keep constructors consistent.