@@ -427,7 +427,7 @@ impl Agent {
427427 self . add_message ( Message :: Assistant {
428428 content : OneOrMany :: one ( AssistantContent :: ToolCall ( tool_call. clone ( ) ) ) ,
429429 } ) ;
430- let ( tool_result, is_error) = match self
430+ let ( mut tool_result, is_error) = match self
431431 . agent
432432 . as_mut ( )
433433 . unwrap ( )
@@ -456,60 +456,55 @@ impl Agent {
456456 } ;
457457
458458 tracing:: trace!( "tool_result: '{}'" , tool_result) ;
459- if ( tool_result. is_empty ( ) || tool_result == "\" \" " )
460- && tool_call. function . name != AttemptCompletionTool :: NAME
461- {
462- tracing:: info!(
463- "Stop processing because empty result from tool: {}" ,
459+ if tool_result. is_empty ( ) || tool_result == "\" \" " {
460+ tool_result = format ! (
461+ "The [{}] tool executed successfully but returned no results." ,
464462 tool_call. function. name
465463 ) ;
466- self . set_state ( AgentState :: WaitingUserPrompt ) ;
467- } else {
468- if !is_error {
469- match tool_call. function . name . as_str ( ) {
470- ReadFileTool :: NAME
471- | WriteToFileTool :: NAME
472- | ListFilesTool :: NAME
473- | ReplaceInFileTool :: NAME => {
474- if let Some ( path) = tool_call
475- . function
476- . arguments
477- . as_object ( )
478- . unwrap ( )
479- . get ( "path" )
480- {
481- self . sender
482- . send ( AgentOutputEvent :: HighlightFile (
483- path. as_str ( ) . unwrap ( ) . to_string ( ) ,
484- tool_call. function . name
485- == WriteToFileTool :: NAME ,
486- ) )
487- . unwrap ( ) ;
488- }
464+ }
465+ if !is_error {
466+ match tool_call. function . name . as_str ( ) {
467+ ReadFileTool :: NAME
468+ | WriteToFileTool :: NAME
469+ | ListFilesTool :: NAME
470+ | ReplaceInFileTool :: NAME => {
471+ if let Some ( path) = tool_call
472+ . function
473+ . arguments
474+ . as_object ( )
475+ . unwrap ( )
476+ . get ( "path" )
477+ {
478+ self . sender
479+ . send ( AgentOutputEvent :: HighlightFile (
480+ path. as_str ( ) . unwrap ( ) . to_string ( ) ,
481+ tool_call. function . name == WriteToFileTool :: NAME ,
482+ ) )
483+ . unwrap ( ) ;
489484 }
490- _ => { }
491485 }
486+ _ => { }
492487 }
493- let mut result_message = Message :: User {
494- content : OneOrMany :: one ( UserContent :: tool_result (
495- tool_call . id . clone ( ) ,
496- OneOrMany :: one ( ToolResultContent :: text ( tool_result ) ) ,
497- ) ) ,
498- } ;
499- if tool_call . function . name == AttemptCompletionTool :: NAME {
500- self . set_state ( AgentState :: Completed ( false ) ) ;
501- tracing :: info! ( "Stop task with success" ) ;
502- persist_history ( & self . messages ) ;
503- } else {
504- add_env_message (
505- & mut result_message ,
506- self . memory_index . as_ref ( ) ,
507- & self . config . workspace ,
508- self . process_registry . clone ( ) ,
509- )
510- . await ;
511- self . add_message ( result_message ) ;
512- }
488+ }
489+ let mut result_message = Message :: User {
490+ content : OneOrMany :: one ( UserContent :: tool_result (
491+ tool_call . id . clone ( ) ,
492+ OneOrMany :: one ( ToolResultContent :: text ( tool_result ) ) ,
493+ ) ) ,
494+ } ;
495+ if tool_call . function . name == AttemptCompletionTool :: NAME {
496+ self . set_state ( AgentState :: Completed ( false ) ) ;
497+ tracing :: info! ( "Stop task with success" ) ;
498+ persist_history ( & self . messages ) ;
499+ } else {
500+ add_env_message (
501+ & mut result_message ,
502+ self . memory_index . as_ref ( ) ,
503+ & self . config . workspace ,
504+ self . process_registry . clone ( ) ,
505+ )
506+ . await ;
507+ self . add_message ( result_message ) ;
513508 }
514509 }
515510 Err ( e) => {
0 commit comments