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
|
|
@ -70,9 +70,9 @@ fn notify(method: &str, params: Value) {
|
|||
fn tool_definitions() -> Vec<Value> {
|
||||
poc_memory::agent::tools::tools().into_iter()
|
||||
.map(|t| json!({
|
||||
"name": t.def.function.name,
|
||||
"description": t.def.function.description,
|
||||
"inputSchema": t.def.function.parameters,
|
||||
"name": t.name,
|
||||
"description": t.description,
|
||||
"inputSchema": serde_json::from_str::<Value>(t.parameters_json).unwrap_or(json!({})),
|
||||
}))
|
||||
.collect()
|
||||
}
|
||||
|
|
@ -81,7 +81,7 @@ fn tool_definitions() -> Vec<Value> {
|
|||
|
||||
fn dispatch_tool(name: &str, args: &Value) -> Result<String, String> {
|
||||
let tools = poc_memory::agent::tools::tools();
|
||||
let tool = tools.iter().find(|t| t.def.function.name == name);
|
||||
let tool = tools.iter().find(|t| t.name == name);
|
||||
let Some(tool) = tool else {
|
||||
return Err(format!("unknown tool: {name}"));
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue