@@ -33,7 +33,7 @@ import type { Logger } from '@codebuff/common/types/contracts/logger'
3333import type { ToolMessage } from '@codebuff/common/types/messages/codebuff-message'
3434import type { ToolResultOutput } from '@codebuff/common/types/messages/content-part'
3535import type { PrintModeEvent } from '@codebuff/common/types/print-mode'
36- import type { AgentTemplateType , AgentState , Subgoal } from '@codebuff/common/types/session-state'
36+ import type { AgentTemplateType , AgentState , Subgoal } from '@codebuff/common/types/session-state'
3737import type {
3838 CustomToolDefinitions ,
3939 ProjectFileContext ,
@@ -119,6 +119,7 @@ export type ExecuteToolCallParams<T extends string = ToolName> = {
119119 tools : ToolSet
120120 toolCallId : string | undefined
121121 toolCalls : ( CodebuffToolCall | CustomToolCall ) [ ]
122+ toolCallsToAddToMessageHistory : ( CodebuffToolCall | CustomToolCall ) [ ]
122123 toolResults : ToolMessage [ ]
123124 toolResultsToAddToMessageHistory : ToolMessage [ ]
124125 userId : string | undefined
@@ -144,6 +145,7 @@ export async function executeToolCall<T extends ToolName>(
144145 logger,
145146 previousToolCallFinished,
146147 toolCalls,
148+ toolCallsToAddToMessageHistory,
147149 toolResults,
148150 toolResultsToAddToMessageHistory,
149151 userInputId,
@@ -298,8 +300,6 @@ export async function executeToolCall<T extends ToolName>(
298300 includeToolCall : ! excludeToolFromMessageHistory ,
299301 } )
300302
301- toolCalls . push ( toolCall )
302-
303303 // Cast to any to avoid type errors
304304 const handler = codebuffToolHandlers [
305305 toolName
@@ -311,6 +311,12 @@ export async function executeToolCall<T extends ToolName>(
311311 ? { ...toolCall , input : effectiveInput }
312312 : toolCall
313313
314+ toolCalls . push ( finalToolCall )
315+ if ( ! excludeToolFromMessageHistory ) {
316+ toolCallsToAddToMessageHistory . push ( finalToolCall )
317+ }
318+
319+
314320 const toolResultPromise = handler ( {
315321 ...params ,
316322 toolCall : finalToolCall ,
@@ -448,6 +454,7 @@ export async function executeCustomToolCall(
448454 requestToolCall,
449455 toolCallId,
450456 toolCalls,
457+ toolCallsToAddToMessageHistory,
451458 toolResults,
452459 toolResultsToAddToMessageHistory,
453460 userInputId,
@@ -512,6 +519,9 @@ export async function executeCustomToolCall(
512519 } )
513520
514521 toolCalls . push ( toolCall )
522+ if ( ! excludeToolFromMessageHistory ) {
523+ toolCallsToAddToMessageHistory . push ( toolCall )
524+ }
515525
516526 return previousToolCallFinished
517527 . then ( async ( ) => {
0 commit comments