@@ -14,7 +14,7 @@ import {
1414 executeToolCall ,
1515 tryTransformAgentToolCall ,
1616} from './tool-executor'
17- import { expireMessages , withSystemTags } from '../util/messages'
17+ import { withSystemTags } from '../util/messages'
1818
1919import type { CustomToolCall , ExecuteToolCallParams } from './tool-executor'
2020import type { AgentTemplate } from '../templates/types'
@@ -60,7 +60,7 @@ export async function processStream(
6060 | 'toolCalls'
6161 | 'toolName'
6262 | 'toolResults'
63- | 'toolResultsToAddAfterStream '
63+ | 'toolResultsToAddToMessageHistory '
6464 > &
6565 ParamsExcluding <
6666 typeof processStreamWithTools ,
@@ -84,14 +84,11 @@ export async function processStream(
8484 userId,
8585 } = params
8686 const fullResponseChunks : string [ ] = [ fullResponse ]
87- const messageHistoryBeforeStream = expireMessages (
88- agentState . messageHistory ,
89- 'agentStep' ,
90- )
87+ const messageHistoryBeforeStream = [ ...agentState . messageHistory ]
9188
9289 // === MUTABLE STATE ===
9390 const toolResults : ToolMessage [ ] = [ ]
94- const toolResultsToAddAfterStream : ToolMessage [ ] = [ ]
91+ const toolResultsToAddToMessageHistory : ToolMessage [ ] = [ ]
9592 const toolCalls : ( CodebuffToolCall | CustomToolCall ) [ ] = [ ]
9693 const assistantMessages : Message [ ] = [ ]
9794 let hadToolCallError = false
@@ -149,7 +146,7 @@ export async function processStream(
149146 // isXmlMode=false: defer execution, results added at end (for native tool calls)
150147 function createToolExecutionCallback ( toolName : string , isXmlMode : boolean ) {
151148 const responseHandler = createResponseHandler ( isXmlMode )
152- const resultsArray = isXmlMode ? [ ] : toolResultsToAddAfterStream
149+ const resultsArray = isXmlMode ? [ ] : toolResultsToAddToMessageHistory
153150
154151 return {
155152 onTagStart : ( ) => { } ,
@@ -188,14 +185,14 @@ export async function processStream(
188185 : ( toolName as ToolName ) ,
189186 input : transformed ? transformed . input : input ,
190187 fromHandleSteps : false ,
191- skipDirectResultPush : true ,
188+
192189 fileProcessingState,
193190 fullResponse : fullResponseChunks . join ( '' ) ,
194191 previousToolCallFinished : previousPromise ,
195192 toolCallId,
196193 toolCalls,
197194 toolResults,
198- toolResultsToAddAfterStream : resultsArray ,
195+ toolResultsToAddToMessageHistory : resultsArray ,
199196 onCostCalculated,
200197 onResponseChunk : responseHandler ,
201198 } )
@@ -205,14 +202,14 @@ export async function processStream(
205202 ...params ,
206203 toolName,
207204 input,
208- skipDirectResultPush : true ,
205+
209206 fileProcessingState,
210207 fullResponse : fullResponseChunks . join ( '' ) ,
211208 previousToolCallFinished : previousPromise ,
212209 toolCallId,
213210 toolCalls,
214211 toolResults,
215- toolResultsToAddAfterStream : resultsArray ,
212+ toolResultsToAddToMessageHistory : resultsArray ,
216213 onResponseChunk : responseHandler ,
217214 } )
218215 }
@@ -250,7 +247,7 @@ export async function processStream(
250247 content : jsonToolResult ( { errorMessage : error } ) ,
251248 }
252249 toolResults . push ( cloneDeep ( toolResult ) )
253- toolResultsToAddAfterStream . push ( cloneDeep ( toolResult ) )
250+ toolResultsToAddToMessageHistory . push ( cloneDeep ( toolResult ) )
254251 } ,
255252 loggerOptions : {
256253 userId,
@@ -344,7 +341,7 @@ export async function processStream(
344341 agentState . messageHistory = buildArray < Message > ( [
345342 ...messageHistoryBeforeStream ,
346343 ...assistantMessages ,
347- ...toolResultsToAddAfterStream ,
344+ ...toolResultsToAddToMessageHistory ,
348345 ...errorMessages ,
349346 ] )
350347
0 commit comments