tools: static string definitions, no runtime JSON construction

Tool definitions are now &'static str (name, description,
parameters_json) instead of runtime-constructed serde_json::Value.
No more json!() macro, no more ToolDef::new() for tool definitions.

The JSON schema strings are written directly as string literals.
When sent to the API, they can be interpolated without
serialization/deserialization.

Multi-tool modules return fixed-size arrays instead of Vecs:
- memory: [Tool; 12], journal: [Tool; 3]
- channels: [Tool; 4]
- control: [Tool; 3]
- web: [Tool; 2]

ToolDef/FunctionDef remain for backward compat (API wire format,
summarize_args) but are no longer used in tool definitions.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
ProofOfConcept 2026-04-04 15:50:14 -04:00 committed by Kent Overstreet
commit 53ad8cc9df
13 changed files with 205 additions and 561 deletions

View file

@ -9,7 +9,6 @@ use base64::Engine;
use serde::Deserialize;
use super::ToolOutput;
use super::ToolDef;
#[derive(Deserialize)]
struct Args {
@ -21,35 +20,13 @@ struct Args {
fn default_lines() -> usize { 50 }
fn definition() -> ToolDef {
ToolDef::new(
"view_image",
"View an image file or capture a tmux pane screenshot. \
Returns the image to your visual input so you can see it. \
Supports PNG, JPEG, GIF, WebP files. \
Use pane_id (e.g. '0:1.0') to capture a tmux pane instead.",
serde_json::json!({
"type": "object",
"properties": {
"file_path": {
"type": "string",
"description": "Path to an image file (PNG, JPEG, GIF, WebP)"
},
"pane_id": {
"type": "string",
"description": "Tmux pane ID to capture (e.g. '0:1.0'). Alternative to file_path."
},
"lines": {
"type": "integer",
"description": "Number of lines to capture from tmux pane (default: 50)"
}
}
}),
)
}
pub fn tool() -> super::Tool {
super::Tool { def: definition(), handler: |_a, v| Box::pin(async move { view_image_text(&v) }) }
super::Tool {
name: "view_image",
description: "View an image file or capture a tmux pane screenshot. Supports PNG, JPEG, GIF, WebP. Use pane_id to capture a tmux pane instead.",
parameters_json: r#"{"type":"object","properties":{"file_path":{"type":"string","description":"Path to an image file"},"pane_id":{"type":"string","description":"Tmux pane ID to capture (e.g. '0:1.0')"},"lines":{"type":"integer","description":"Lines to capture from tmux pane (default 50)"}}}"#,
handler: |_a, v| Box::pin(async move { view_image_text(&v) }),
}
}
/// Text-only version for the Tool registry.