(
&self,
agent_run_id: &str,
ctx: &InternalRunContext<'_>,
token_sink: &S,
)
| 731 | |
| 732 | #[allow(dead_code)] |
| 733 | async fn execute_agent_leaf<S: TokenSink + Sync>( |
| 734 | &self, |
| 735 | agent_run_id: &str, |
| 736 | ctx: &InternalRunContext<'_>, |
| 737 | token_sink: &S, |
| 738 | ) -> AppResult<String> { |
| 739 | let system_prompt = get_prompt(ctx.agent_type).ok_or_else(|| { |
| 740 | AppError::Validation(format!("Unknown agent type for prompt lookup: {}", ctx.agent_type)) |
| 741 | })?; |
| 742 | |
| 743 | let provider = provider_service::get_provider_for_chat(&self.db, ctx.provider_id).await?; |
| 744 | let model = ctx.model_id.unwrap_or(&provider.model); |
| 745 | let tool_executor = ToolExecutor::new(PathBuf::from(ctx.project_path)); |
| 746 | |
| 747 | let system_content = if ctx.flux_enabled { |
| 748 | if needs_full_preview_guide(ctx.task) { |
| 749 | format!("{}\n\n{}\n\n{}", system_prompt, LANGUAGE_GUARD, PREVIEW_GUIDE) |
| 750 | } else { |
| 751 | format!("{}\n\n{}\n\n{}", system_prompt, LANGUAGE_GUARD, PREVIEW_HINT) |
| 752 | } |
| 753 | } else { |
| 754 | format!("{}\n\n{}", system_prompt, LANGUAGE_GUARD) |
| 755 | }; |
| 756 | |
| 757 | // Load conversation history for context |
| 758 | let history = self.load_conversation_history(ctx.session_id).await?; |
| 759 | |
| 760 | let mut messages = vec![ConversationMessage::system(&system_content)]; |
| 761 | if history.len() > 1 { |
| 762 | let history_without_last = &history[..history.len() - 1]; |
| 763 | messages.extend_from_slice(history_without_last); |
| 764 | } |
| 765 | messages.push(ConversationMessage::user(ctx.task)); |
| 766 | |
| 767 | self.run_react_loop( |
| 768 | &provider, |
| 769 | model, |
| 770 | agent_run_id, |
| 771 | ctx.agent_type, |
| 772 | ctx.project_path, |
| 773 | &tool_executor, |
| 774 | &mut messages, |
| 775 | MAX_REACT_ITERATIONS, |
| 776 | token_sink, |
| 777 | ) |
| 778 | .await |
| 779 | } |
| 780 | |
| 781 | #[allow(clippy::too_many_arguments)] |
| 782 | async fn run_react_loop<S: TokenSink + Sync>( |
nothing calls this directly
no test coverage detected