diff options
Diffstat (limited to '')
| -rw-r--r-- | src/agent.rs | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/src/agent.rs b/src/agent.rs index f575908..b30c876 100644 --- a/src/agent.rs +++ b/src/agent.rs | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | /* | ||
| 2 | * This file is part of agent686 | ||
| 3 | * Copyright (C) 2026 Salmonik <salmon@2137697.xyz> | ||
| 4 | * SPDX-License-Identifier: GPL-3.0-or-later | ||
| 5 | * https://git.2137697.xyz/agent686 | ||
| 6 | */ | ||
| 7 | |||
| 1 | use std::path::PathBuf; | 8 | use std::path::PathBuf; |
| 2 | use std::process::Command; | 9 | use std::process::Command; |
| 3 | use std::sync::atomic::AtomicBool; | 10 | use std::sync::atomic::AtomicBool; |
| @@ -201,27 +208,23 @@ pub fn run_turn( | |||
| 201 | 208 | ||
| 202 | steps += 1; | 209 | steps += 1; |
| 203 | let mut renderer = Renderer::new(); | 210 | let mut renderer = Renderer::new(); |
| 204 | let mut outcome = match provider::chat_with( | 211 | let mut outcome = |
| 205 | &client, | 212 | match provider::chat_with(&client, cfg, history, &schemas, cancel, &mut renderer) { |
| 206 | cfg, | 213 | Ok(outcome) => outcome, |
| 207 | history, | 214 | Err(Error::Aborted) => { |
| 208 | &schemas, | 215 | aborted = true; |
| 209 | cancel, | 216 | break; |
| 210 | &mut renderer, | 217 | } |
| 211 | ) { | 218 | Err(error) => return Err(error), |
| 212 | Ok(outcome) => outcome, | 219 | }; |
| 213 | Err(Error::Aborted) => { | ||
| 214 | aborted = true; | ||
| 215 | break; | ||
| 216 | } | ||
| 217 | Err(error) => return Err(error), | ||
| 218 | }; | ||
| 219 | 220 | ||
| 220 | // A call with no name cannot be replayed to the provider at all, so it | 221 | // A call with no name cannot be replayed to the provider at all, so it |
| 221 | // is dropped. A *named* call with no arguments is kept: the model is told | 222 | // 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. | 223 | // what arrived and can retry, which is better than silence. |
| 223 | let before = outcome.tool_calls.len(); | 224 | let before = outcome.tool_calls.len(); |
| 224 | outcome.tool_calls.retain(|call| !call.name.trim().is_empty()); | 225 | outcome |
| 226 | .tool_calls | ||
| 227 | .retain(|call| !call.name.trim().is_empty()); | ||
| 225 | if outcome.tool_calls.len() < before { | 228 | if outcome.tool_calls.len() < before { |
| 226 | eprintln!( | 229 | eprintln!( |
| 227 | "agent686: ignored {} tool call(s) with no name", | 230 | "agent686: ignored {} tool call(s) with no name", |
| @@ -240,7 +243,12 @@ pub fn run_turn( | |||
| 240 | truncated = Some("the model hit its output limit; the answer is cut off".into()); | 243 | truncated = Some("the model hit its output limit; the answer is cut off".into()); |
| 241 | } | 244 | } |
| 242 | let assistant = assistant_message(&outcome); | 245 | let assistant = assistant_message(&outcome); |
| 243 | push(session, history, assistant, Some(outcome.reasoning.as_str())); | 246 | push( |
| 247 | session, | ||
| 248 | history, | ||
| 249 | assistant, | ||
| 250 | Some(outcome.reasoning.as_str()), | ||
| 251 | ); | ||
| 244 | 252 | ||
| 245 | if outcome.tool_calls.is_empty() { | 253 | if outcome.tool_calls.is_empty() { |
| 246 | last = Some(outcome); | 254 | last = Some(outcome); |
| @@ -389,8 +397,8 @@ fn execute( | |||
| 389 | args | 397 | args |
| 390 | }; | 398 | }; |
| 391 | // The bash approval prompt prints the command; do not print it here too. | 399 | // The bash approval prompt prints the command; do not print it here too. |
| 392 | let repeat_detail = !(tools::approval(&call.name) == Approval::EveryCall | 400 | let repeat_detail = |
| 393 | && approver.will_prompt_bash()); | 401 | !(tools::approval(&call.name) == Approval::EveryCall && approver.will_prompt_bash()); |
| 394 | ui::tool_line(label, &call.name, &args, repeat_detail); | 402 | ui::tool_line(label, &call.name, &args, repeat_detail); |
| 395 | if let Err(error) = tools::validate(&call.name, &args) { | 403 | if let Err(error) = tools::validate(&call.name, &args) { |
| 396 | return ToolOutcome::Failed(format!("{error}; the call was not run")); | 404 | return ToolOutcome::Failed(format!("{error}; the call was not run")); |
