(
&self,
provider: &crate::models::Provider,
model: &str,
agent_run_id: &str,
agent_type: &str,
project_path: &str,
tool_executor: &ToolExecutor
| 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 | } |
no test coverage detected