@@ -221,7 +221,11 @@ fn repair_tool_call_context(context: &mut Vec<crate::utils::ChatMessage>) {
221221 for id in missing {
222222 context. insert (
223223 j,
224- crate :: utils:: ChatMessage :: tool ( "[Cancelled — tool execution interrupted]" , & id) ,
224+ crate :: utils:: ChatMessage :: tool (
225+ "[Cancelled — tool execution interrupted]" ,
226+ & id,
227+ None ,
228+ ) ,
225229 ) ;
226230 j += 1 ;
227231 }
@@ -1604,9 +1608,28 @@ impl AgentLogic {
16041608 // 2. Inject tool response into memory
16051609 if let Some ( id) = tool_call_id {
16061610 if let Ok ( mut mem) = self . session_manager . get_session ( session_key) . await {
1607- mem. add_message ( crate :: utils:: ChatMessage :: tool ( & inbound. content , id) )
1608- . await
1609- . map_err ( |e| format ! ( "Failed to inject tool response into memory: {}" , e) ) ?;
1611+ // Determine tool name from memory
1612+ let mut tool_name_for_resume = None ;
1613+ if let Ok ( context) = mem. get_context ( ) . await {
1614+ for msg in context. iter ( ) . rev ( ) {
1615+ if msg. role == "assistant" {
1616+ if let Some ( calls) = & msg. tool_calls {
1617+ if let Some ( tc) = calls. iter ( ) . find ( |c| c. id == id) {
1618+ tool_name_for_resume = Some ( tc. function . name . clone ( ) ) ;
1619+ break ;
1620+ }
1621+ }
1622+ }
1623+ }
1624+ }
1625+
1626+ mem. add_message ( crate :: utils:: ChatMessage :: tool (
1627+ & inbound. content ,
1628+ id,
1629+ tool_name_for_resume. as_deref ( ) ,
1630+ ) )
1631+ . await
1632+ . map_err ( |e| format ! ( "Failed to inject tool response into memory: {}" , e) ) ?;
16101633 } else {
16111634 return Err ( format ! ( "Failed to get session {}" , session_key) ) ;
16121635 }
@@ -2251,14 +2274,18 @@ impl AgentLogic {
22512274 hook_observe_telemetry ( hook_tool_ctx. as_ref ( ) , & inbound, is_subagent, tr) ;
22522275 let tfin = TelemetryEvent :: ToolCallFinished {
22532276 chat_id : inbound. chat_id . clone ( ) ,
2254- tool_name,
2277+ tool_name : tool_name . clone ( ) ,
22552278 result : tool_result_text. clone ( ) ,
22562279 background_job_id : crate :: bus:: get_background_job_id ( & inbound. metadata ) ,
22572280 } ;
22582281 let _ = outbound_tx. send ( BusMessage :: Telemetry ( tfin. clone ( ) ) ) . await ;
22592282 hook_observe_telemetry ( hook_tool_ctx. as_ref ( ) , & inbound, is_subagent, tfin) ;
2260- mem. add_message ( crate :: utils:: ChatMessage :: tool ( & tool_result_text, & tc. id ) )
2261- . await ?;
2283+ mem. add_message ( crate :: utils:: ChatMessage :: tool (
2284+ & tool_result_text,
2285+ & tc. id ,
2286+ Some ( tool_name. as_str ( ) ) ,
2287+ ) )
2288+ . await ?;
22622289 }
22632290 tool_invoked = true ;
22642291 } else {
@@ -2356,8 +2383,12 @@ impl AgentLogic {
23562383 let _ = outbound_tx. send ( BusMessage :: Telemetry ( tfin. clone ( ) ) ) . await ;
23572384 hook_observe_telemetry ( hook_tool_ctx. as_ref ( ) , & inbound, is_subagent, tfin) ;
23582385
2359- mem. add_message ( crate :: utils:: ChatMessage :: tool ( & tool_result_text, & tc. id ) )
2360- . await ?;
2386+ mem. add_message ( crate :: utils:: ChatMessage :: tool (
2387+ & tool_result_text,
2388+ & tc. id ,
2389+ Some ( tool_name. as_str ( ) ) ,
2390+ ) )
2391+ . await ?;
23612392 tool_invoked = true ;
23622393 }
23632394 }
0 commit comments