@@ -59,7 +59,7 @@ describe('tool validation error handling', () => {
5959
6060 const responseChunks : ( string | PrintModeEvent ) [ ] = [ ]
6161
62- await processStream ( {
62+ const result = await processStream ( {
6363 ...agentRuntimeImpl ,
6464 agentContext : { } ,
6565 agentState,
@@ -96,6 +96,9 @@ describe('tool validation error handling', () => {
9696 expect ( errorEvents . length ) . toBe ( 1 )
9797 expect ( errorEvents [ 0 ] . message ) . toContain ( 'Invalid parameters for spawn_agents' )
9898
99+ // Verify hadToolCallError is true so the agent loop continues
100+ expect ( result . hadToolCallError ) . toBe ( true )
101+
99102 // Verify NO tool_call event was emitted (since validation failed before that point)
100103 const toolCallEvents = responseChunks . filter (
101104 ( chunk ) : chunk is Extract < PrintModeEvent , { type : 'tool_call' } > =>
@@ -125,6 +128,18 @@ describe('tool validation error handling', () => {
125128 expect ( toolMessages . length ) . toBe ( 0 )
126129 // And no assistant tool calls either
127130 expect ( assistantToolCalls . length ) . toBe ( 0 )
131+
132+ // Verify error message was added to message history for the LLM to see
133+ const userMessages = agentState . messageHistory . filter (
134+ ( m ) => m . role === 'user' ,
135+ )
136+ const errorUserMessage = userMessages . find ( ( m ) => {
137+ const contentStr = Array . isArray ( m . content )
138+ ? m . content . map ( ( p ) => ( 'text' in p ? p . text : '' ) ) . join ( '' )
139+ : typeof m . content === 'string' ? m . content : ''
140+ return contentStr . includes ( 'Error during tool call' ) && contentStr . includes ( 'Invalid parameters for spawn_agents' )
141+ } )
142+ expect ( errorUserMessage ) . toBeDefined ( )
128143 } )
129144
130145 it ( 'should still emit tool_call and tool_result for valid tool calls' , async ( ) => {
0 commit comments