diff options
| author | salmonik <salmonik@tuta.io> | 2026-11-18 12:01:38 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-11-18 12:01:38 +0100 |
| commit | 6df7a6403d88a4492ab6ea1c519dcae3a202be96 (patch) | |
| tree | 216f5d009881c2bccff122a6779397c502fb228b /src/agent.rs | |
| parent | 0.8.2: comp.sh defaults to this CPU, --portable for travel (diff) | |
| download | agent686-6df7a6403d88a4492ab6ea1c519dcae3a202be96.tar.gz agent686-6df7a6403d88a4492ab6ea1c519dcae3a202be96.zip | |
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
Diffstat (limited to 'src/agent.rs')
| -rw-r--r-- | src/agent.rs | 39 |
1 files changed, 25 insertions, 14 deletions
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( | |||
| 217 | Err(error) => return Err(error), | 217 | Err(error) => return Err(error), |
| 218 | }; | 218 | }; |
| 219 | 219 | ||
| 220 | // Placeholders are dropped before the assistant message is written: | 220 | // A call with no name cannot be replayed to the provider at all, so it |
| 221 | // recording a call we refuse to run would leave it unanswered. | 221 | // is dropped. A *named* call with no arguments is kept: the model is told |
| 222 | // what arrived and can retry, which is better than silence. | ||
| 222 | let before = outcome.tool_calls.len(); | 223 | let before = outcome.tool_calls.len(); |
| 223 | outcome | 224 | outcome.tool_calls.retain(|call| !call.name.trim().is_empty()); |
| 224 | .tool_calls | ||
| 225 | .retain(|call| !tools::is_placeholder(&call.arguments)); | ||
| 226 | if outcome.tool_calls.len() < before { | 225 | if outcome.tool_calls.len() < before { |
| 227 | eprintln!("agent686: ignored {} empty tool call(s) from the model", before - outcome.tool_calls.len()); | 226 | eprintln!( |
| 227 | "agent686: ignored {} tool call(s) with no name", | ||
| 228 | before - outcome.tool_calls.len() | ||
| 229 | ); | ||
| 228 | } | 230 | } |
| 229 | 231 | ||
| 230 | // A missing id would make the tool result unattachable. | 232 | // A missing id would make the tool result unattachable. |
| @@ -247,7 +249,15 @@ pub fn run_turn( | |||
| 247 | let calls = outcome.tool_calls.clone(); | 249 | let calls = outcome.tool_calls.clone(); |
| 248 | last = Some(outcome); | 250 | last = Some(outcome); |
| 249 | 251 | ||
| 250 | for call in calls { | 252 | let multiple = calls.len() > 1; |
| 253 | for (offset, call) in calls.into_iter().enumerate() { | ||
| 254 | // Thousands of steps are possible in a long turn; the label keeps | ||
| 255 | // each call's lines attributable when several run in one step. | ||
| 256 | let label = if multiple { | ||
| 257 | format!("{steps}.{}", offset + 1) | ||
| 258 | } else { | ||
| 259 | steps.to_string() | ||
| 260 | }; | ||
| 251 | // Cancelling between calls still has to answer every tool call the | 261 | // Cancelling between calls still has to answer every tool call the |
| 252 | // assistant message announced: an unanswered id makes the session | 262 | // assistant message announced: an unanswered id makes the session |
| 253 | // permanently unusable, because history is never rewritten. | 263 | // permanently unusable, because history is never rewritten. |
| @@ -257,7 +267,7 @@ pub fn run_turn( | |||
| 257 | let result = if aborted { | 267 | let result = if aborted { |
| 258 | ToolOutcome::Failed("aborted by the user before this call ran".into()) | 268 | ToolOutcome::Failed("aborted by the user before this call ran".into()) |
| 259 | } else { | 269 | } else { |
| 260 | execute(&call, approver, cancel, steps) | 270 | execute(&call, approver, cancel, &label) |
| 261 | }; | 271 | }; |
| 262 | if result.denied() { | 272 | if result.denied() { |
| 263 | denied += 1; | 273 | denied += 1; |
| @@ -269,7 +279,7 @@ pub fn run_turn( | |||
| 269 | _ => {} | 279 | _ => {} |
| 270 | } | 280 | } |
| 271 | } | 281 | } |
| 272 | ui::tool_result(&result.summary(), aborted); | 282 | ui::tool_result(&label, &result.summary(), aborted); |
| 273 | let message = json!({ | 283 | let message = json!({ |
| 274 | "role": "tool", | 284 | "role": "tool", |
| 275 | "tool_call_id": call.id, | 285 | "tool_call_id": call.id, |
| @@ -350,21 +360,22 @@ fn execute( | |||
| 350 | call: &provider::ToolCall, | 360 | call: &provider::ToolCall, |
| 351 | approver: &mut Approver, | 361 | approver: &mut Approver, |
| 352 | cancel: &AtomicBool, | 362 | cancel: &AtomicBool, |
| 353 | step: usize, | 363 | label: &str, |
| 354 | ) -> ToolOutcome { | 364 | ) -> ToolOutcome { |
| 355 | let args: Value = match serde_json::from_str(&call.arguments) { | 365 | let args: Value = match serde_json::from_str(&call.arguments) { |
| 356 | Ok(args) => args, | 366 | Ok(args) => args, |
| 357 | Err(error) => { | 367 | Err(error) => { |
| 368 | let raw = crate::provider::truncate(call.arguments.trim(), 200); | ||
| 358 | return ToolOutcome::Failed(format!( | 369 | return ToolOutcome::Failed(format!( |
| 359 | "arguments were not valid JSON ({error}); issue the call again with the \ | 370 | "arguments were not valid JSON ({error}). Received: {raw:?}. \ |
| 360 | complete arguments" | 371 | Issue the call again with complete arguments" |
| 361 | )) | 372 | )); |
| 362 | } | 373 | } |
| 363 | }; | 374 | }; |
| 364 | // The bash approval prompt prints the command; do not print it here too. | 375 | // The bash approval prompt prints the command; do not print it here too. |
| 365 | let repeat_detail = !(tools::approval(&call.name) == Approval::EveryCall | 376 | let repeat_detail = !(tools::approval(&call.name) == Approval::EveryCall |
| 366 | && approver.will_prompt_bash()); | 377 | && approver.will_prompt_bash()); |
| 367 | ui::tool_line(step, &call.name, &args, repeat_detail); | 378 | ui::tool_line(label, &call.name, &args, repeat_detail); |
| 368 | if let Err(error) = tools::validate(&call.name, &args) { | 379 | if let Err(error) = tools::validate(&call.name, &args) { |
| 369 | return ToolOutcome::Failed(format!("{error}; the call was not run")); | 380 | return ToolOutcome::Failed(format!("{error}; the call was not run")); |
| 370 | } | 381 | } |
