@@ -62,7 +62,6 @@ pub struct Agent {
6262 assistant_content : Option < String > ,
6363 memory : Arc < RwLock < MemoryManager > > ,
6464 memory_index : Option < InMemoryVectorIndex < rig_fastembed:: EmbeddingModel , Entity > > ,
65- pending_tool_id : Option < String > ,
6665 current_tokens : u32 ,
6766 state : AgentState ,
6867}
@@ -90,7 +89,6 @@ impl Agent {
9089 messages,
9190 stream : None ,
9291 assistant_content : None ,
93- pending_tool_id : None ,
9492 current_tokens : 0 ,
9593 memory : Arc :: new ( RwLock :: new ( MemoryManager :: new ( false ) ) ) ,
9694 memory_index : None ,
@@ -295,6 +293,15 @@ impl Agent {
295293 }
296294 }
297295
296+ fn pending_tool_id ( & self ) -> Option < String > {
297+ self . messages . last ( ) . and_then ( |message| match message {
298+ Message :: User { .. } => None ,
299+ Message :: Assistant { content } => match content. first ( ) {
300+ AssistantContent :: Text ( _) => None ,
301+ AssistantContent :: ToolCall ( tool_call) => Some ( tool_call. id . clone ( ) ) ,
302+ } ,
303+ } )
304+ }
298305 fn add_message ( & mut self , message : Message ) {
299306 self . sender
300307 . send ( AgentOutputEvent :: AddMessage ( message. clone ( ) ) )
@@ -416,7 +423,6 @@ impl Agent {
416423 "Stop processing because empty result from tool: {}" ,
417424 tool_call. function. name
418425 ) ;
419- self . pending_tool_id = Some ( tool_call. id ) ;
420426 self . set_state ( AgentState :: WaitingUserPrompt ) ;
421427 } else {
422428 if !is_error {
@@ -451,7 +457,6 @@ impl Agent {
451457 ) ) ,
452458 } ;
453459 if tool_call. function . name == AttemptCompletionTool :: NAME {
454- self . pending_tool_id = Some ( tool_call. id . clone ( ) ) ;
455460 self . set_state ( AgentState :: Completed ( false ) ) ;
456461 tracing:: info!( "Stop task with success" ) ;
457462 persist_history ( & self . messages ) ;
@@ -556,7 +561,7 @@ impl Agent {
556561 }
557562
558563 async fn send_message ( & mut self , message : String ) {
559- let mut message = if let Some ( tool_id) = self . pending_tool_id . take ( ) {
564+ let mut message = if let Some ( tool_id) = self . pending_tool_id ( ) {
560565 Message :: User {
561566 content : OneOrMany :: one ( UserContent :: tool_result (
562567 tool_id,
0 commit comments