Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/extension/intents/node/agentIntent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import { IAutomodeService } from '../../../platform/endpoint/node/automodeServic
import { IEnvService } from '../../../platform/env/common/envService';
import { ILogService } from '../../../platform/log/common/logService';
import { IEditLogService } from '../../../platform/multiFileEdit/common/editLogService';
import { CUSTOM_TOOL_SEARCH_NAME, isAnthropicCustomToolSearchEnabled } from '../../../platform/networking/common/anthropic';
import { CUSTOM_TOOL_SEARCH_NAME, isAnthropicCustomToolSearchEnabled, isAnthropicToolSearchEnabled } from '../../../platform/networking/common/anthropic';
import { IToolDeferralService } from '../../../platform/networking/common/toolDeferralService';
import { IChatEndpoint } from '../../../platform/networking/common/networking';
import { modelsWithoutResponsesContextManagement } from '../../../platform/networking/common/openai';
import { INotebookService } from '../../../platform/notebook/common/notebookService';
Expand Down Expand Up @@ -363,6 +364,7 @@ export class AgentIntentInvocation extends EditCodeIntentInvocation implements I
@IExperimentationService private readonly expService: IExperimentationService,
@IAutomodeService private readonly automodeService: IAutomodeService,
@IOTelService override readonly otelService: IOTelService,
@IToolDeferralService private readonly toolDeferralService: IToolDeferralService,
) {
super(intent, location, endpoint, request, intentOptions, instantiationService, codeMapperService, envService, promptPathRepresentationService, endpointProvider, workspaceService, toolsService, configurationService, editLogService, commandService, telemetryService, notebookService, otelService);
}
Expand All @@ -388,7 +390,15 @@ export class AgentIntentInvocation extends EditCodeIntentInvocation implements I
}

const tools = promptContext.tools?.availableTools;
const toolTokens = tools?.length ? await this.endpoint.acquireTokenizer().countToolTokens(tools) : 0;
// When Anthropic tool search is enabled, deferred tools are sent with
// defer_loading: true and don't count against the context window until
// the model loads them via tool_search. Only count non-deferred tools
// so the budget isn't artificially reduced.
const toolSearchEnabled = isAnthropicToolSearchEnabled(this.endpoint, this.configurationService);
const effectiveTools = tools && toolSearchEnabled
? tools.filter(t => this.toolDeferralService.isNonDeferredTool(t.name))
: tools;
const toolTokens = effectiveTools?.length ? await this.endpoint.acquireTokenizer().countToolTokens(effectiveTools) : 0;
Comment thread
bhavyaus marked this conversation as resolved.

const summarizeThresholdOverride = this.configurationService.getConfig<number | undefined>(ConfigKey.Advanced.SummarizeAgentConversationHistoryThreshold);
if (typeof summarizeThresholdOverride === 'number' && summarizeThresholdOverride < 100 && summarizeThresholdOverride > 0) {
Expand All @@ -414,7 +424,7 @@ export class AgentIntentInvocation extends EditCodeIntentInvocation implements I
const safeBudget = useTruncation ? Number.MAX_SAFE_INTEGER : messageBudget;
const endpoint = toolTokens > 0 ? this.endpoint.cloneWithTokenOverride(safeBudget) : this.endpoint;

this.logService.debug(`AgentIntent: rendering with budget=${safeBudget} (baseBudget: ${baseBudget}, toolTokens: ${toolTokens}), summarizationEnabled=${summarizationEnabled}`);
this.logService.debug(`AgentIntent: rendering with budget=${safeBudget} (baseBudget: ${baseBudget}, toolTokens: ${toolTokens}${toolSearchEnabled ? `, totalTools: ${tools?.length ?? 0}, nonDeferredTools: ${effectiveTools?.length ?? 0}` : ''}), summarizationEnabled=${summarizationEnabled}`);
let result: RenderPromptResult;
const props: AgentPromptProps = {
endpoint,
Expand Down
4 changes: 3 additions & 1 deletion src/extension/intents/node/askAgentIntent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { IEnvService } from '../../../platform/env/common/envService';
import { ILogService } from '../../../platform/log/common/logService';
import { IEditLogService } from '../../../platform/multiFileEdit/common/editLogService';
import { IChatEndpoint } from '../../../platform/networking/common/networking';
import { IToolDeferralService } from '../../../platform/networking/common/toolDeferralService';
import { INotebookService } from '../../../platform/notebook/common/notebookService';
import { IOTelService } from '../../../platform/otel/common/otelService';
import { IPromptPathRepresentationService } from '../../../platform/prompts/common/promptPathRepresentationService';
Expand Down Expand Up @@ -128,8 +129,9 @@ export class AskAgentIntentInvocation extends AgentIntentInvocation {
@IExperimentationService expService: IExperimentationService,
@IAutomodeService automodeService: IAutomodeService,
@IOTelService otelService: IOTelService,
@IToolDeferralService toolDeferralService: IToolDeferralService,
) {
super(intent, location, endpoint, request, { processCodeblocks: true }, instantiationService, codeMapperService, envService, promptPathRepresentationService, endpointProvider, workspaceService, toolsService, configurationService, editLogService, commandService, telemetryService, notebookService, logService, expService, automodeService, otelService);
super(intent, location, endpoint, request, { processCodeblocks: true }, instantiationService, codeMapperService, envService, promptPathRepresentationService, endpointProvider, workspaceService, toolsService, configurationService, editLogService, commandService, telemetryService, notebookService, logService, expService, automodeService, otelService, toolDeferralService);
}

public override async getAvailableTools(): Promise<vscode.LanguageModelToolInformation[]> {
Expand Down
4 changes: 3 additions & 1 deletion src/extension/intents/node/editCodeIntent2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { IEnvService } from '../../../platform/env/common/envService';
import { ILogService } from '../../../platform/log/common/logService';
import { IEditLogService } from '../../../platform/multiFileEdit/common/editLogService';
import { IChatEndpoint } from '../../../platform/networking/common/networking';
import { IToolDeferralService } from '../../../platform/networking/common/toolDeferralService';
import { requestHasNotebookRefs } from '../../../platform/notebook/common/helpers';
import { INotebookService } from '../../../platform/notebook/common/notebookService';
import { IOTelService } from '../../../platform/otel/common/otelService';
Expand Down Expand Up @@ -89,8 +90,9 @@ export class EditCode2IntentInvocation extends AgentIntentInvocation {
@IExperimentationService expService: IExperimentationService,
@IAutomodeService automodeService: IAutomodeService,
@IOTelService otelService: IOTelService,
@IToolDeferralService toolDeferralService: IToolDeferralService,
) {
super(intent, location, endpoint, request, intentOptions, instantiationService, codeMapperService, envService, promptPathRepresentationService, endpointProvider, workspaceService, toolsService, configurationService, editLogService, commandService, telemetryService, notebookService, logService, expService, automodeService, otelService);
super(intent, location, endpoint, request, intentOptions, instantiationService, codeMapperService, envService, promptPathRepresentationService, endpointProvider, workspaceService, toolsService, configurationService, editLogService, commandService, telemetryService, notebookService, logService, expService, automodeService, otelService, toolDeferralService);
}

public override async getAvailableTools(): Promise<vscode.LanguageModelToolInformation[]> {
Expand Down
4 changes: 3 additions & 1 deletion src/extension/intents/node/notebookEditorIntent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { IEnvService } from '../../../platform/env/common/envService';
import { ILogService } from '../../../platform/log/common/logService';
import { IEditLogService } from '../../../platform/multiFileEdit/common/editLogService';
import { IChatEndpoint } from '../../../platform/networking/common/networking';
import { IToolDeferralService } from '../../../platform/networking/common/toolDeferralService';
import { IAlternativeNotebookContentService } from '../../../platform/notebook/common/alternativeContent';
import { getCellId } from '../../../platform/notebook/common/helpers';
import { INotebookService } from '../../../platform/notebook/common/notebookService';
Expand Down Expand Up @@ -107,8 +108,9 @@ export class NotebookEditorIntentInvocation extends EditCode2IntentInvocation {
@IExperimentationService expService: IExperimentationService,
@IAutomodeService automodeService: IAutomodeService,
@IOTelService otelService: IOTelService,
@IToolDeferralService toolDeferralService: IToolDeferralService,
) {
super(intent, location, endpoint, request, intentOptions, instantiationService, codeMapperService, envService, promptPathRepresentationService, endpointProvider, workspaceService, toolsService, configurationService, editLogService, commandService, telemetryService, notebookService, logService, expService, automodeService, otelService);
super(intent, location, endpoint, request, intentOptions, instantiationService, codeMapperService, envService, promptPathRepresentationService, endpointProvider, workspaceService, toolsService, configurationService, editLogService, commandService, telemetryService, notebookService, logService, expService, automodeService, otelService, toolDeferralService);
}

protected override prompt = NotebookInlinePrompt;
Expand Down
Loading