@@ -170,6 +170,7 @@ export abstract class ToolCallingLoop<TOptions extends IToolCallingLoopOptions =
170
170
public async run ( outputStream : ChatResponseStream | undefined , token : CancellationToken | PauseController ) : Promise < IToolCallLoopResult > {
171
171
let i = 0 ;
172
172
let lastResult : IToolCallSingleResult | undefined ;
173
+ let lastRequestMessagesStartingIndexForRun : number | undefined ;
173
174
174
175
while ( true ) {
175
176
if ( lastResult && i ++ >= this . options . toolCallLimit ) {
@@ -179,6 +180,9 @@ export abstract class ToolCallingLoop<TOptions extends IToolCallingLoopOptions =
179
180
180
181
try {
181
182
const result = await this . runOne ( outputStream , i , token ) ;
183
+ if ( lastRequestMessagesStartingIndexForRun === undefined ) {
184
+ lastRequestMessagesStartingIndexForRun = result . lastRequestMessages . length - 1 ;
185
+ }
182
186
lastResult = {
183
187
...result ,
184
188
hadIgnoredFiles : lastResult ?. hadIgnoredFiles || result . hadIgnoredFiles
@@ -203,9 +207,11 @@ export abstract class ToolCallingLoop<TOptions extends IToolCallingLoopOptions =
203
207
this . _logService . error ( 'Error emitting read file trajectories' , err ) ;
204
208
} ) ;
205
209
206
- for ( const result of Object . keys ( this . toolCallResults ) ) {
207
- if ( this . toolCallResults [ result ] instanceof LanguageModelToolResult2 ) {
208
- for ( const part of this . toolCallResults [ result ] . content ) {
210
+ const toolCallRoundsToDisplay = lastResult . lastRequestMessages . slice ( lastRequestMessagesStartingIndexForRun ?? 0 ) . filter ( ( m ) : m is Raw . ToolChatMessage => m . role === Raw . ChatRole . Tool ) ;
211
+ for ( const toolRound of toolCallRoundsToDisplay ) {
212
+ const result = this . toolCallResults [ toolRound . toolCallId ] ;
213
+ if ( result instanceof LanguageModelToolResult2 ) {
214
+ for ( const part of result . content ) {
209
215
if ( part instanceof LanguageModelDataPart2 && part . mimeType === 'application/pull-request+json' && part . audience ?. includes ( ToolResultAudience . User ) ) {
210
216
const data : { uri : string ; title : string ; description : string ; author : string ; linkTag : string } = JSON . parse ( part . data . toString ( ) ) ;
211
217
outputStream ?. push ( new ChatResponsePullRequestPart ( URI . parse ( data . uri ) , data . title , data . description , data . author , data . linkTag ) ) ;
0 commit comments