tools: delete ToolDef and FunctionDef

ToolDef and FunctionDef are gone. Tool definitions are static strings
on the Tool struct. The API layer builds JSON from Tool::to_json().

- ChatRequest.tools is now Option<serde_json::Value>
- start_stream takes &[Tool] instead of Option<&[ToolDef]>
- openai::stream_events takes &serde_json::Value for tools
- memory_and_journal_tools() returns Vec<Tool> for subconscious agents
- Subconscious agents filter by t.name instead of t.function.name

No more runtime JSON construction for tool definitions.
No more ToolDef::new(). No more FunctionDef.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
ProofOfConcept 2026-04-04 16:39:04 -04:00 committed by Kent Overstreet
parent d195160b1e
commit 51e632c997
7 changed files with 33 additions and 78 deletions

View file

@ -18,7 +18,7 @@ mod write;
// Agent-specific tools
mod control;
mod vision;
pub mod working_stack;
mod working_stack;
use serde::{Serialize, Deserialize};
use std::future::Future;
@ -55,19 +55,6 @@ impl Tool {
self.parameters_json,
)
}
/// Build a ToolDef (for backward compat where ToolDef is still used).
pub fn to_tool_def(&self) -> ToolDef {
ToolDef {
tool_type: "function".to_string(),
function: FunctionDef {
name: self.name.to_string(),
description: self.description.to_string(),
parameters: serde_json::from_str(self.parameters_json)
.expect("invalid JSON in tool parameters"),
},
}
}
}
/// Function call within a tool call — name + JSON arguments.
@ -77,15 +64,6 @@ pub struct FunctionCall {
pub arguments: String,
}
/// Function definition for tool schema.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FunctionDef {
pub name: String,
pub description: String,
pub parameters: serde_json::Value,
}
/// Partial function call within a streaming delta.
#[derive(Debug, Deserialize)]
pub struct FunctionCallDelta {
@ -93,27 +71,6 @@ pub struct FunctionCallDelta {
pub arguments: Option<String>,
}
/// Tool definition sent to the model.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ToolDef {
#[serde(rename = "type")]
pub tool_type: String,
pub function: FunctionDef,
}
impl ToolDef {
pub fn new(name: &str, description: &str, parameters: serde_json::Value) -> Self {
Self {
tool_type: "function".to_string(),
function: FunctionDef {
name: name.to_string(),
description: description.to_string(),
parameters,
},
}
}
}
/// A tool call requested by the model.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ToolCall {
@ -135,7 +92,6 @@ pub struct ToolCallDelta {
pub function: Option<FunctionCallDelta>,
}
/// A tool call in flight — metadata for TUI + JoinHandle for
/// result collection and cancellation.
pub struct ActiveToolCall {
@ -220,17 +176,11 @@ pub fn tools() -> Vec<Tool> {
all
}
/// Return all tool definitions for the API.
pub fn definitions() -> Vec<ToolDef> {
tools().into_iter().map(|t| t.to_tool_def()).collect()
}
/// Return memory + journal tool definitions only.
pub fn memory_and_journal_definitions() -> Vec<ToolDef> {
memory::memory_tools().into_iter()
.chain(memory::journal_tools())
.map(|t| t.to_tool_def())
.collect()
/// Memory + journal tools only — for subconscious agents.
pub fn memory_and_journal_tools() -> Vec<Tool> {
let mut all = memory::memory_tools().to_vec();
all.extend(memory::journal_tools());
all
}
/// Create a short summary of tool args for the tools pane header.