tools: delete ToolOutput, dispatch returns String

ToolOutput was just { text: String } — replaced with plain String.
dispatch() and dispatch_shared() return String directly.
ActiveToolCall handle is (ToolCall, String).
Error results are prefixed with "Error: " by convention.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
ProofOfConcept 2026-04-04 16:08:59 -04:00 committed by Kent Overstreet
parent a24a6605b8
commit 37fad63ba9
3 changed files with 23 additions and 35 deletions

View file

@ -134,20 +134,6 @@ pub struct ToolCallDelta {
pub function: Option<FunctionCallDelta>,
}
/// Result of dispatching a tool call.
pub struct ToolOutput {
pub text: String,
}
impl ToolOutput {
pub fn error(e: impl std::fmt::Display) -> Self {
Self { text: format!("Error: {}", e) }
}
pub fn text(s: String) -> Self {
Self { text: s }
}
}
/// A tool call in flight — metadata for TUI + JoinHandle for
/// result collection and cancellation.
@ -157,7 +143,7 @@ pub struct ActiveToolCall {
pub detail: String,
pub started: Instant,
pub background: bool,
pub handle: tokio::task::JoinHandle<(ToolCall, ToolOutput)>,
pub handle: tokio::task::JoinHandle<(ToolCall, String)>,
}
/// Truncate output if it exceeds max length, appending a truncation notice.
@ -170,10 +156,12 @@ pub fn truncate_output(mut s: String, max: usize) -> String {
}
/// Dispatch a tool call by name through the registry.
/// Dispatch a tool call by name. Returns the result text,
/// or an error string prefixed with "Error: ".
pub async fn dispatch(
name: &str,
args: &serde_json::Value,
) -> ToolOutput {
) -> String {
dispatch_with_agent(name, args, None).await
}
@ -182,16 +170,16 @@ pub async fn dispatch_with_agent(
name: &str,
args: &serde_json::Value,
agent: Option<std::sync::Arc<tokio::sync::Mutex<super::Agent>>>,
) -> ToolOutput {
) -> String {
for tool in tools() {
if tool.name == name {
return match (tool.handler)(agent, args.clone()).await {
Ok(s) => ToolOutput::text(s),
Err(e) => ToolOutput::error(e),
Ok(s) => s,
Err(e) => format!("Error: {}", e),
};
}
}
ToolOutput::error(format!("Unknown tool: {}", name))
format!("Error: Unknown tool: {}", name)
}
/// Dispatch shared tools — used by subconscious agents.
@ -199,12 +187,12 @@ pub async fn dispatch_shared(
name: &str,
args: &serde_json::Value,
_provenance: Option<&str>,
) -> Option<ToolOutput> {
) -> Option<String> {
for tool in tools() {
if tool.name == name {
return Some(match (tool.handler)(None, args.clone()).await {
Ok(s) => ToolOutput::text(s),
Err(e) => ToolOutput::error(e),
Ok(s) => s,
Err(e) => format!("Error: {}", e),
});
}
}