@@ -380,7 +380,12 @@ impl ExecRunner {
380380 // Execute each tool call
381381 for tool_call in & response. tool_calls {
382382 let record = self
383- . execute_tool_call ( tool_call, & mut files_modified, & mut commands_executed)
383+ . execute_tool_call (
384+ tool_call,
385+ & conversation_id,
386+ & mut files_modified,
387+ & mut commands_executed,
388+ )
384389 . await ;
385390
386391 // Add tool result to conversation
@@ -629,6 +634,7 @@ impl ExecRunner {
629634 async fn execute_tool_call (
630635 & self ,
631636 tool_call : & ToolCall ,
637+ conversation_id : & ConversationId ,
632638 files_modified : & mut Vec < String > ,
633639 commands_executed : & mut Vec < String > ,
634640 ) -> ToolCallRecord {
@@ -654,11 +660,7 @@ impl ExecRunner {
654660 }
655661 } ;
656662
657- // Create tool context
658- let context = ToolContext :: new ( self . options . cwd . clone ( ) )
659- . with_auto_approve ( self . options . full_auto )
660- . with_conversation_id ( ConversationId :: new ( ) . to_string ( ) )
661- . with_call_id ( & tool_call. id ) ;
663+ let context = self . build_tool_context ( tool_call, conversation_id) ;
662664
663665 // Execute the tool
664666 let result = self
@@ -720,6 +722,17 @@ impl ExecRunner {
720722 }
721723 }
722724
725+ fn build_tool_context (
726+ & self ,
727+ tool_call : & ToolCall ,
728+ conversation_id : & ConversationId ,
729+ ) -> ToolContext {
730+ ToolContext :: new ( self . options . cwd . clone ( ) )
731+ . with_auto_approve ( self . options . full_auto )
732+ . with_conversation_id ( conversation_id. to_string ( ) )
733+ . with_call_id ( & tool_call. id )
734+ }
735+
723736 /// Run with a specific prompt.
724737 pub async fn run_prompt ( & mut self , prompt : & str ) -> Result < ExecResult , CortexError > {
725738 self . options . prompt = prompt. to_string ( ) ;
@@ -745,6 +758,7 @@ impl ExecRunner {
745758#[ cfg( test) ]
746759mod tests {
747760 use super :: * ;
761+ use cortex_engine:: client:: FunctionCall ;
748762
749763 #[ tokio:: test]
750764 async fn test_exec_runner_empty_prompt ( ) {
@@ -821,4 +835,23 @@ mod tests {
821835 // Only Read and LS should be present
822836 assert ! ( tools. iter( ) . all( |t| t. name( ) == "Read" || t. name( ) == "LS" ) ) ;
823837 }
838+
839+ #[ test]
840+ fn test_tool_context_uses_session_conversation_id ( ) {
841+ let conversation_id = ConversationId :: new ( ) ;
842+ let tool_call = ToolCall {
843+ id : "call-123" . to_string ( ) ,
844+ call_type : "function" . to_string ( ) ,
845+ function : FunctionCall {
846+ name : "Read" . to_string ( ) ,
847+ arguments : "{}" . to_string ( ) ,
848+ } ,
849+ } ;
850+ let runner = ExecRunner :: new ( Config :: default ( ) , ExecOptions :: default ( ) ) ;
851+
852+ let context = runner. build_tool_context ( & tool_call, & conversation_id) ;
853+
854+ assert_eq ! ( context. conversation_id, conversation_id. to_string( ) ) ;
855+ assert_eq ! ( context. call_id, "call-123" ) ;
856+ }
824857}
0 commit comments