MCPcopy Create free account
hub / github.com/enowdev/enowX-Coder / run_react_loop

Method run_react_loop

src-tauri/src/agents/runner.rs:782–863  ·  view source on GitHub ↗
(
        &self,
        provider: &crate::models::Provider,
        model: &str,
        agent_run_id: &str,
        agent_type: &str,
        project_path: &str,
        tool_executor: &ToolExecutor

Source from the content-addressed store, hash-verified

780
781 #[allow(clippy::too_many_arguments)]
782 async fn run_react_loop<S: TokenSink + Sync>(
783 &self,
784 provider: &crate::models::Provider,
785 model: &str,
786 agent_run_id: &str,
787 agent_type: &str,
788 project_path: &str,
789 tool_executor: &ToolExecutor,
790 messages: &mut Vec<ConversationMessage>,
791 max_iterations: usize,
792 token_sink: &S,
793 ) -> AppResult<String> {
794 let mut final_text = String::new();
795
796 for _ in 0..max_iterations {
797 // Check cancellation before each iteration
798 if self.cancel_token.is_cancelled() {
799 return Err(AppError::Cancelled);
800 }
801
802 let turn = if provider.uses_anthropic_format() {
803 self.send_anthropic_with_tools(
804 &provider.base_url,
805 &provider.api_key,
806 &provider.provider_type,
807 model,
808 messages,
809 agent_run_id,
810 token_sink,
811 )
812 .await?
813 } else {
814 self.send_openai_compatible_with_tools(
815 &provider.base_url,
816 &provider.api_key,
817 model,
818 messages,
819 agent_run_id,
820 token_sink,
821 )
822 .await?
823 };
824
825 messages.push(ConversationMessage::assistant(
826 turn.text.clone(),
827 turn.tool_calls.clone(),
828 ));
829
830 if turn.tool_calls.is_empty() {
831 final_text = turn.text.trim().to_string();
832 break;
833 }
834
835 for tool_call in turn.tool_calls {
836 // Check cancellation before each tool execution
837 if self.cancel_token.is_cancelled() {
838 return Err(AppError::Cancelled);
839 }

Callers 2

execute_agentMethod · 0.80
execute_agent_leafMethod · 0.80

Calls 5

truncate_tool_resultFunction · 0.85
uses_anthropic_formatMethod · 0.80
execute_tool_callMethod · 0.80

Tested by

no test coverage detected