feat: inject user comments into agent conversation in real-time (try_recv between LLM calls)
This commit is contained in:
17
src/agent.rs
17
src/agent.rs
@@ -683,6 +683,15 @@ pub async fn run_step_loop(
|
|||||||
let step_order = step.order;
|
let step_order = step.order;
|
||||||
|
|
||||||
for iteration in 0..50 {
|
for iteration in 0..50 {
|
||||||
|
// Drain any pending user comments and inject as feedback
|
||||||
|
while let Ok(event) = event_rx.try_recv() {
|
||||||
|
if let AgentEvent::Comment { content, .. } = event {
|
||||||
|
tracing::info!("[workflow {}] Step {} received user feedback: {}", workflow_id, step_order, &content[..content.len().min(100)]);
|
||||||
|
step_chat_history.push(ChatMessage::user(&format!("【用户反馈】{}", content)));
|
||||||
|
send_execution(update_tx, workflow_id, step_order, "user_feedback", &content, "已注入到对话上下文", "done").await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Build messages: system + user context + chat history
|
// Build messages: system + user context + chat history
|
||||||
let mut messages = vec![
|
let mut messages = vec![
|
||||||
ChatMessage::system(&system_prompt),
|
ChatMessage::system(&system_prompt),
|
||||||
@@ -1087,6 +1096,14 @@ pub async fn run_agent_loop(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Drain pending user comments
|
||||||
|
while let Ok(event) = event_rx.try_recv() {
|
||||||
|
if let AgentEvent::Comment { content, .. } = event {
|
||||||
|
tracing::info!("[workflow {}] Planning received user feedback: {}", workflow_id, &content[..content.len().min(100)]);
|
||||||
|
state.current_step_chat_history.push(ChatMessage::user(&format!("【用户反馈】{}", content)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let system_prompt = build_planning_prompt(project_id, instructions);
|
let system_prompt = build_planning_prompt(project_id, instructions);
|
||||||
let messages = state.build_messages(&system_prompt, requirement);
|
let messages = state.build_messages(&system_prompt, requirement);
|
||||||
let msg_count = messages.len() as i32;
|
let msg_count = messages.len() as i32;
|
||||||
|
|||||||
Reference in New Issue
Block a user