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:
parent
ed150df628
commit
53ad8cc9df
13 changed files with 205 additions and 561 deletions
|
|
@ -8,11 +8,10 @@
|
|||
|
||||
use anyhow::{Context, Result};
|
||||
use serde::Deserialize;
|
||||
use serde_json::json;
|
||||
use std::process::Stdio;
|
||||
use tokio::io::AsyncReadExt;
|
||||
|
||||
use super::{ToolDef, default_timeout};
|
||||
use super::default_timeout;
|
||||
|
||||
/// RAII guard that SIGTERMs the process group on drop.
|
||||
/// Ensures child processes are cleaned up when a task is aborted.
|
||||
|
|
@ -34,29 +33,12 @@ struct Args {
|
|||
}
|
||||
|
||||
pub fn tool() -> super::Tool {
|
||||
super::Tool { def: definition(), handler: |_a, v| Box::pin(async move { run_bash(&v).await }) }
|
||||
}
|
||||
|
||||
fn definition() -> ToolDef {
|
||||
ToolDef::new(
|
||||
"bash",
|
||||
"Execute a bash command and return its output. \
|
||||
Use for git operations, building, running tests, and other terminal tasks.",
|
||||
json!({
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"command": {
|
||||
"type": "string",
|
||||
"description": "The bash command to execute"
|
||||
},
|
||||
"timeout_secs": {
|
||||
"type": "integer",
|
||||
"description": "Timeout in seconds (default 120)"
|
||||
}
|
||||
},
|
||||
"required": ["command"]
|
||||
}),
|
||||
)
|
||||
super::Tool {
|
||||
name: "bash",
|
||||
description: "Execute a bash command and return its output. Use for git operations, building, running tests, and other terminal tasks.",
|
||||
parameters_json: r#"{"type":"object","properties":{"command":{"type":"string","description":"The bash command to execute"},"timeout_secs":{"type":"integer","description":"Timeout in seconds (default 120)"}},"required":["command"]}"#,
|
||||
handler: |_a, v| Box::pin(async move { run_bash(&v).await }),
|
||||
}
|
||||
}
|
||||
|
||||
async fn run_bash(args: &serde_json::Value) -> Result<String> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue