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
parent ed150df628
commit 53ad8cc9df
13 changed files with 205 additions and 561 deletions

View file

@ -5,45 +5,29 @@
use anyhow::{Context, Result};
use serde::Deserialize;
use serde_json::json;
use super::{Tool, ToolDef};
use super::Tool;
// ── Tool registry ──────────────────────────────────────────────
pub fn tools() -> Vec<Tool> {
vec![
Tool {
def: ToolDef::new("channel_list",
"List all available channels and their status (connected, unread count).",
json!({"type": "object", "properties": {}})),
handler: |_a, _v| Box::pin(async { channel_list().await }),
},
Tool {
def: ToolDef::new("channel_recv",
"Read messages from a channel.",
json!({"type": "object", "properties": {
"channel": {"type": "string", "description": "Channel path (e.g. irc.#bcachefs, telegram.kent)"},
"all_new": {"type": "boolean", "description": "If true, return all unconsumed messages. If false, return scrollback.", "default": true},
"min_count": {"type": "integer", "description": "Minimum number of lines to return", "default": 20}
}, "required": ["channel"]})),
handler: |_a, v| Box::pin(async move { channel_recv(&v).await }),
},
Tool {
def: ToolDef::new("channel_send",
"Send a message to a channel.",
json!({"type": "object", "properties": {
"channel": {"type": "string", "description": "Channel path (e.g. irc.#bcachefs, irc.pm.nick, telegram.kent)"},
"message": {"type": "string", "description": "Message to send"}
}, "required": ["channel", "message"]})),
handler: |_a, v| Box::pin(async move { channel_send(&v).await }),
},
Tool {
def: ToolDef::new("channel_notifications",
"Get pending channel notifications (unread signals). Does not consume messages — use channel_recv for that.",
json!({"type": "object", "properties": {}})),
handler: |_a, _v| Box::pin(async { channel_notifications().await }),
},
pub fn tools() -> [Tool; 4] {
[
Tool { name: "channel_list",
description: "List all available channels and their status (connected, unread count).",
parameters_json: r#"{"type":"object","properties":{}}"#,
handler: |_a, _v| Box::pin(async { channel_list().await }) },
Tool { name: "channel_recv",
description: "Read messages from a channel.",
parameters_json: r#"{"type":"object","properties":{"channel":{"type":"string","description":"Channel path (e.g. irc.#bcachefs, telegram.kent)"},"all_new":{"type":"boolean","description":"If true, return all unconsumed messages","default":true},"min_count":{"type":"integer","description":"Minimum number of lines to return","default":20}},"required":["channel"]}"#,
handler: |_a, v| Box::pin(async move { channel_recv(&v).await }) },
Tool { name: "channel_send",
description: "Send a message to a channel.",
parameters_json: r#"{"type":"object","properties":{"channel":{"type":"string","description":"Channel path (e.g. irc.#bcachefs, irc.pm.nick, telegram.kent)"},"message":{"type":"string","description":"Message to send"}},"required":["channel","message"]}"#,
handler: |_a, v| Box::pin(async move { channel_send(&v).await }) },
Tool { name: "channel_notifications",
description: "Get pending channel notifications (unread signals). Does not consume messages — use channel_recv for that.",
parameters_json: r#"{"type":"object","properties":{}}"#,
handler: |_a, _v| Box::pin(async { channel_notifications().await }) },
]
}