From 6df7a6403d88a4492ab6ea1c519dcae3a202be96 Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 18 Nov 2026 12:01:38 +0100 Subject: 0.9.0: distinguishable tool errors, separated stderr, configurable limits From a field report porting a Neovim config to Helix: - validate() now separates 'empty value', 'wrong key (here is what you sent)' and 'no arguments at all, retry' instead of one false message for all four causes - named calls with no arguments are answered rather than dropped silently - bash keeps stdout and stderr in labelled sections when both produce output - bash gains timeout_seconds (1-600) and max_bytes, and says when output was cut - tool lines/results carry [step.call] labels when a step has several calls - invalid JSON errors include a preview of what arrived --- src/agent.rs | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) (limited to 'src/agent.rs') diff --git a/src/agent.rs b/src/agent.rs index 7d4c4ef..afd662c 100644 --- a/src/agent.rs +++ b/src/agent.rs @@ -217,14 +217,16 @@ pub fn run_turn( Err(error) => return Err(error), }; - // Placeholders are dropped before the assistant message is written: - // recording a call we refuse to run would leave it unanswered. + // A call with no name cannot be replayed to the provider at all, so it + // is dropped. A *named* call with no arguments is kept: the model is told + // what arrived and can retry, which is better than silence. let before = outcome.tool_calls.len(); - outcome - .tool_calls - .retain(|call| !tools::is_placeholder(&call.arguments)); + outcome.tool_calls.retain(|call| !call.name.trim().is_empty()); if outcome.tool_calls.len() < before { - eprintln!("agent686: ignored {} empty tool call(s) from the model", before - outcome.tool_calls.len()); + eprintln!( + "agent686: ignored {} tool call(s) with no name", + before - outcome.tool_calls.len() + ); } // A missing id would make the tool result unattachable. @@ -247,7 +249,15 @@ pub fn run_turn( let calls = outcome.tool_calls.clone(); last = Some(outcome); - for call in calls { + let multiple = calls.len() > 1; + for (offset, call) in calls.into_iter().enumerate() { + // Thousands of steps are possible in a long turn; the label keeps + // each call's lines attributable when several run in one step. + let label = if multiple { + format!("{steps}.{}", offset + 1) + } else { + steps.to_string() + }; // Cancelling between calls still has to answer every tool call the // assistant message announced: an unanswered id makes the session // permanently unusable, because history is never rewritten. @@ -257,7 +267,7 @@ pub fn run_turn( let result = if aborted { ToolOutcome::Failed("aborted by the user before this call ran".into()) } else { - execute(&call, approver, cancel, steps) + execute(&call, approver, cancel, &label) }; if result.denied() { denied += 1; @@ -269,7 +279,7 @@ pub fn run_turn( _ => {} } } - ui::tool_result(&result.summary(), aborted); + ui::tool_result(&label, &result.summary(), aborted); let message = json!({ "role": "tool", "tool_call_id": call.id, @@ -350,21 +360,22 @@ fn execute( call: &provider::ToolCall, approver: &mut Approver, cancel: &AtomicBool, - step: usize, + label: &str, ) -> ToolOutcome { let args: Value = match serde_json::from_str(&call.arguments) { Ok(args) => args, Err(error) => { + let raw = crate::provider::truncate(call.arguments.trim(), 200); return ToolOutcome::Failed(format!( - "arguments were not valid JSON ({error}); issue the call again with the \ - complete arguments" - )) + "arguments were not valid JSON ({error}). Received: {raw:?}. \ + Issue the call again with complete arguments" + )); } }; // The bash approval prompt prints the command; do not print it here too. let repeat_detail = !(tools::approval(&call.name) == Approval::EveryCall && approver.will_prompt_bash()); - ui::tool_line(step, &call.name, &args, repeat_detail); + ui::tool_line(label, &call.name, &args, repeat_detail); if let Err(error) = tools::validate(&call.name, &args) { return ToolOutcome::Failed(format!("{error}; the call was not run")); } -- cgit v1.2.3