tools: control tools set agent state directly, simplify ToolOutput

Control tools (pause, switch_model, yield_to_user) now use the
Arc<Mutex<Agent>> handle to set pending_yield, pending_model_switch,
pending_dmn_pause directly. The turn loop drains these flags into
TurnResult at completion.

ToolOutput simplified to just { text: String } — no more is_yield,
images, model_switch, dmn_pause fields. Vision returns plain strings.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
ProofOfConcept 2026-04-04 16:05:33 -04:00 committed by Kent Overstreet
commit a24a6605b8
4 changed files with 47 additions and 125 deletions

View file

@ -8,8 +8,6 @@ use anyhow::{Context, Result};
use base64::Engine;
use serde::Deserialize;
use super::ToolOutput;
#[derive(Deserialize)]
struct Args {
file_path: Option<String>,
@ -29,14 +27,7 @@ pub fn tool() -> super::Tool {
}
}
/// Text-only version for the Tool registry.
fn view_image_text(args: &serde_json::Value) -> anyhow::Result<String> {
let output = view_image(args)?;
Ok(output.text)
}
/// View an image file or capture a tmux pane.
pub(super) fn view_image(args: &serde_json::Value) -> Result<ToolOutput> {
let a: Args = serde_json::from_value(args.clone())
.context("invalid view_image arguments")?;
@ -69,22 +60,11 @@ pub(super) fn view_image(args: &serde_json::Value) -> Result<ToolOutput> {
let b64 = base64::engine::general_purpose::STANDARD.encode(&data);
let data_uri = format!("data:{};base64,{}", mime, b64);
Ok(ToolOutput {
text: format!(
"Image loaded: {} ({}, {} bytes)",
file_path,
mime,
data.len()
),
is_yield: false,
images: vec![data_uri],
model_switch: None,
dmn_pause: false,
})
Ok(format!("Image loaded: {} ({}, {} bytes)\n{}", file_path, mime, data.len(), data_uri))
}
/// Capture a tmux pane's text content.
fn capture_tmux_pane(pane_id: &str, lines: usize) -> Result<ToolOutput> {
fn capture_tmux_pane(pane_id: &str, lines: usize) -> Result<String> {
// Use tmux capture-pane to get text content, then render to image
// via a simple approach: capture text and return it (the model can
@ -106,16 +86,10 @@ fn capture_tmux_pane(pane_id: &str, lines: usize) -> Result<ToolOutput> {
// Return as text — the model can read terminal output directly.
// This is actually more useful than a screenshot for most tasks.
Ok(ToolOutput {
text: format!(
"Tmux pane {} (last {} lines):\n```\n{}\n```",
pane_id, lines, text.trim_end()
),
is_yield: false,
images: Vec::new(),
model_switch: None,
dmn_pause: false,
})
Ok(format!(
"Tmux pane {} (last {} lines):\n```\n{}\n```",
pane_id, lines, text.trim_end()
))
}
fn mime_from_extension(path: &std::path::Path) -> &'static str {