The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(agent): actually ask the user on ask_user_clarification
M3gA-Mind342466bf3b69
diff --git a/src/openhuman/agent/harness/graph.rs b/src/openhuman/agent/harness/graph.rsindex f6faadf4ef..31e98b5325 100644--- a/src/openhuman/agent/harness/graph.rs+++ b/src/openhuman/agent/harness/graph.rs@@ -17,7 +17,9 @@//! **Available tools.** Reuses the bus handler's `Arc`-shared tool sets//! (`tools_registry: Arc<Vec<Box<dyn Tool>>>` + per-turn `extra_tools`),//! advertised via `SharedToolAdapter`-//! and filtered by `visible_tool_names`. No early-exit tools on this path.+//! and filtered by `visible_tool_names`. `ask_user_clarification` is the+//! early-exit tool: it pauses the turn and returns its question as the turn's+//! text, which the channel relays as the reply.//!//! **Summarization.** [`run_channel_turn_via_graph`] resolves the model's//! effective context window before dispatch so the shared seam runs the@@ -130,8 +132,11 @@ pub(crate) async fn run_channel_turn_via_graph(context_window,// No mid-flight steering on the channel path.None,- // No early-exit pause on the channel path.- &[],+ // Same pause as the chat path: a channel turn's continuation is the+ // user's next message, so ending the turn on the question is the whole+ // mechanism. Without this the model answers its own question (see+ // `session/turn/graph.rs`).+ &["ask_user_clarification"],// Channels surface the cap as an error (legacy `ErrorCheckpoint`), so no// graceful cap pause/summary here.false,@@ -173,6 +178,13 @@ pub(crate) async fn run_channel_turn_via_graph(.to_provider_messages(&outcome.conversation)};history.extend(suffix);+ if outcome.early_exit_tool.is_some() {+ // Paused on `ask_user_clarification`: the suffix ends on the tool result+ // and there is no final assistant turn, so `outcome.text` (the question)+ // stands in for one. Without this the next turn's history would not show+ // that the agent had asked anything.+ history.push(ChatMessage::assistant(outcome.text.clone()));+ }Ok(outcome.text)}diff --git a/src/openhuman/agent/harness/graph_tests.rs b/src/openhuman/agent/harness/graph_tests.rsindex b6a187049d..f7ed4286c2 100644--- a/src/openhuman/agent/harness/graph_tests.rs+++ b/src/openhuman/agent/harness/graph_tests.rs@@ -65,3 +65,69 @@ async fn channel_turn_runs_through_the_graph() {assert_eq!(text, "channel done");assert!(history.iter().any(|m| m.content.contains("pong")));}++/// Regression: the channel path must PAUSE on `ask_user_clarification`, not feed+/// the tool's output back to the model.+///+/// The scripted model offers a second response ("built it without asking"). A+/// run that consumes it is the bug this fixes: `early_exit_tools` was `&[]`, so+/// the question came back as an ordinary successful tool result and the model+/// answered its own question. With the pause wired up the second response is+/// never reached and the turn ends on the question itself.+#[tokio::test]+async fn channel_turn_pauses_on_ask_user_clarification() {+ let registry: Arc<Vec<Box<dyn Tool>>> = Arc::new(vec![Box::new(+ crate::openhuman::agent::tools::AskClarificationTool::new(),+ )]);+ let mut history = vec![ChatMessage::user("build me a workflow")];+ let scripted: Arc<dyn ChatModel<()>> = Arc::new(ScriptedModel::new(vec![+ ModelResponse {+ message: AssistantMessage {+ id: None,+ content: Vec::new(),+ tool_calls: vec![ToolCall::new(+ "c",+ "ask_user_clarification",+ serde_json::json!({ "question": "Which three sources?" }),+ )],+ usage: None,+ },+ usage: None,+ finish_reason: Some("tool_calls".to_string()),+ raw: None,+ resolved_model: None,+ continue_turn: None,+ served_from_cache: false,+ },+ ModelResponse::assistant("built it without asking"),+ ]));+ let mut profile = ModelProfile::default();+ profile.tool_calling = true;+ profile.parallel_tool_calls = true;+ let text = run_channel_turn_via_graph(+ TurnModelSource::from_model_with_profile(scripted, profile),+ &mut history,+ registry,+ vec![],+ None,+ "mock-model",+ 0.0,+ 10,+ MultimodalConfig::default(),+ MultimodalFileConfig::default(),+ None,+ )+ .await+ .expect("channel graph turn runs");++ assert_eq!(+ text, "Which three sources?",+ "the turn must end on the question; got the model's own follow-up, so the pause did not fire"+ );+ let last = history.last().expect("history is not empty");+ assert_eq!(last.role, "assistant");+ assert_eq!(+ last.content, "Which three sources?",+ "the question stands in for the final assistant turn the paused run never produced"+ );+}diff --git a/src/openhuman/agent/harness/session/turn/core_session.rs b/src/openhuman/agent/harness/session/turn/core_session.rsindex 8b81785260..f324a7af90 100644--- a/src/openhuman/agent/harness/session/turn/core_session.rs+++ b/src/openhuman/agent/harness/session/turn/core_session.rs@@ -371,6 +371,20 @@ impl Agent {final_answer.clone(),)));final_answer+ } else if outcome.early_exit_tool.is_some() {+ // Paused on `ask_user_clarification`. The run stopped right after the+ // tool round, so `outcome.conversation` ends on a tool result and+ // carries no final assistant turn — `outcome.text` (the question) is+ // standing in for one. Push it, or the reply the user is looking at+ // would be missing from the next request's prefix and the model would+ // have to infer that it asked anything from its own tool result.+ // The sub-agent path makes the same substitution when it persists a+ // paused child's transcript (`subagent_runner/ops/graph_part_01.rs`).+ self.history+ .push(ConversationMessage::Chat(ChatMessage::assistant(+ outcome.text.clone(),+ )));+ outcome.text.clone()} else {outcome.text.clone()};diff --git a/src/openhuman/agent/harness/session/turn/graph.rs b/src/openhuman/agent/harness/session/turn/graph.rsindex 8860545c98..4782de0203 100644--- a/src/openhuman/agent/harness/session/turn/graph.rs+++ b/src/openhuman/agent/harness/session/turn/graph.rs@@ -133,9 +133,19 @@ pub(crate) async fn run_chat_turn_graph(graph: ChatTurnGraph) -> Result<Tinyagengraph.context_window,// Mid-flight steering from the session's run queue.graph.run_queue,- // The top-level chat turn surfaces clarifying questions inline rather- // than pausing the loop, so no early-exit tools here.- &[],+ // `ask_user_clarification` pauses this turn: the seam returns the+ // question as `outcome.text`, the caller ends the turn on it, and the+ // user's next message is the answer. No resume plumbing is needed at+ // the top level — unlike a delegated child, a chat turn's natural+ // continuation IS the next user message.+ //+ // This was `&[]` with a comment claiming the chat turn "surfaces+ // clarifying questions inline". It does not, and nothing else did+ // either: the tool's output went back to the model as a successful+ // result, so the model read its own question as answered and carried+ // on. Users watched an "Ask User Clarification" step succeed without+ // ever being asked anything.+ &["ask_user_clarification"],// Pause gracefully at the model-call cap so the turn emits a resumable// checkpoint instead of erroring or returning a dangling tool cycle.true,diff --git a/src/openhuman/agent/tools/ask_clarification.rs b/src/openhuman/agent/tools/ask_clarification.rsindex a926da2eb5..9dc30eb478 100644--- a/src/openhuman/agent/tools/ask_clarification.rs+++ b/src/openhuman/agent/tools/ask_clarification.rs@@ -6,8 +6,18 @@ use serde_json::json;/// Pauses the current execution to ask the user for clarification.///-/// In the orchestrator flow, this surfaces the question to the user via the-/// event channel and waits for a response before continuing.+/// The pause is NOT implemented here — this tool only returns the question as+/// its output. The turn stops because `ask_user_clarification` is registered as+/// an *early-exit tool* on the harness seam+/// (`tinyagents::run_turn_via_tinyagents_shared`'s `early_exit_tools`): on a+/// successful call the hook records the output as the pause question and steers+/// the loop to `Pause`, so the caller ends the turn with that question as its+/// text instead of feeding this result back to the model.+///+/// Every caller that exposes this tool MUST name it in `early_exit_tools`.+/// A caller that does not gets a tool that answers its own question: the model+/// reads this output as a successful result and carries on without ever asking+/// (the chat and channel paths did exactly that until this was wired up).pub struct AskClarificationTool;impl Default for AskClarificationTool {@@ -69,16 +79,17 @@ impl Tool for AskClarificationTool {.join(", ")});- let mut output = format!("[CLARIFICATION NEEDED]\n{question}");+ // Plain question text, no marker: this output IS the message the user+ // reads. The early-exit hook captures it verbatim as the pause question,+ // which the chat path returns as the turn's reply and the sub-agent path+ // carries on `SubagentRunStatus::AwaitingUser`. Nothing anywhere parsed+ // the old `[CLARIFICATION NEEDED]` prefix — it only ever leaked into the+ // user's face.+ let mut output = question.to_string();if let Some(opts) = options {output.push_str(&format!("\n\nOptions: {opts}"));}- // In a full implementation, this would:- // 1. Emit an event to the frontend/CLI.- // 2. Block on a response channel.- // 3. Return the user's answer.- // For now, return the question as output so the orchestrator can surface it.tracing::info!("[ask_clarification] question: {question}");Ok(ToolResult::success(output))diff --git a/src/openhuman/agent/tools/ask_clarification_tests.rs b/src/openhuman/agent/tools/ask_clarification_tests.rsindex 5418df5939..da77015dc5 100644--- a/src/openhuman/agent/tools/ask_clarification_tests.rs+++ b/src/openhuman/agent/tools/ask_clarification_tests.rs@@ -64,5 +64,18 @@ async fn execute_without_question_uses_fallback() {let tool = AskClarificationTool::new();let result = tool.execute(json!({})).await.unwrap();assert!(!result.is_error);- assert!(result.output().contains("CLARIFICATION NEEDED"));+ assert!(result.output().contains("clarify"));+}++/// The output is the message the user reads (the early-exit hook captures it+/// verbatim as the pause question), so it must not carry a machine marker no+/// reader parses.+#[tokio::test]+async fn output_is_the_bare_question_with_no_marker() {+ let tool = AskClarificationTool::new();+ let result = tool+ .execute(json!({ "question": "Which branch should I target?" }))+ .await+ .unwrap();+ assert_eq!(result.output(), "Which branch should I target?");}