forked from kent/consciousness
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
|
|
@ -7,9 +7,8 @@
|
|||
use anyhow::{Context, Result};
|
||||
|
||||
use super::ToolOutput;
|
||||
use super::ToolDef;
|
||||
|
||||
pub(super) fn pause(_args: &serde_json::Value) -> Result<ToolOutput> {
|
||||
fn pause(_args: &serde_json::Value) -> Result<ToolOutput> {
|
||||
Ok(ToolOutput {
|
||||
text: "Pausing autonomous behavior. Only user input will wake you.".to_string(),
|
||||
is_yield: true,
|
||||
|
|
@ -19,7 +18,7 @@ pub(super) fn pause(_args: &serde_json::Value) -> Result<ToolOutput> {
|
|||
})
|
||||
}
|
||||
|
||||
pub(super) fn switch_model(args: &serde_json::Value) -> Result<ToolOutput> {
|
||||
fn switch_model(args: &serde_json::Value) -> Result<ToolOutput> {
|
||||
let model = args
|
||||
.get("model")
|
||||
.and_then(|v| v.as_str())
|
||||
|
|
@ -36,7 +35,7 @@ pub(super) fn switch_model(args: &serde_json::Value) -> Result<ToolOutput> {
|
|||
})
|
||||
}
|
||||
|
||||
pub(super) fn yield_to_user(args: &serde_json::Value) -> Result<ToolOutput> {
|
||||
fn yield_to_user(args: &serde_json::Value) -> Result<ToolOutput> {
|
||||
let msg = args
|
||||
.get("message")
|
||||
.and_then(|v| v.as_str())
|
||||
|
|
@ -50,73 +49,26 @@ pub(super) fn yield_to_user(args: &serde_json::Value) -> Result<ToolOutput> {
|
|||
})
|
||||
}
|
||||
|
||||
pub(super) fn tools() -> Vec<super::Tool> {
|
||||
pub(super) fn tools() -> [super::Tool; 3] {
|
||||
use super::Tool;
|
||||
let defs = definitions();
|
||||
vec![
|
||||
Tool { def: defs[0].clone(), // switch_model
|
||||
[
|
||||
Tool { name: "switch_model",
|
||||
description: "Switch to a different LLM model mid-conversation. Memories and history carry over.",
|
||||
parameters_json: r#"{"type":"object","properties":{"model":{"type":"string","description":"Name of the model to switch to"}},"required":["model"]}"#,
|
||||
handler: |_a, v| Box::pin(async move {
|
||||
let model = v.get("model").and_then(|v| v.as_str()).unwrap_or("");
|
||||
Ok(format!("Switching to model: {}", model))
|
||||
}) },
|
||||
Tool { def: defs[1].clone(), // pause
|
||||
Tool { name: "pause",
|
||||
description: "Pause all autonomous behavior. Only the user can unpause (Ctrl+P or /wake).",
|
||||
parameters_json: r#"{"type":"object","properties":{}}"#,
|
||||
handler: |_a, _v| Box::pin(async { Ok("Pausing autonomous behavior. Only user input will wake you.".into()) }) },
|
||||
Tool { def: defs[2].clone(), // yield_to_user
|
||||
Tool { name: "yield_to_user",
|
||||
description: "Wait for user input before continuing. The only way to enter a waiting state.",
|
||||
parameters_json: r#"{"type":"object","properties":{"message":{"type":"string","description":"Optional status message"}}}"#,
|
||||
handler: |_a, v| Box::pin(async move {
|
||||
let msg = v.get("message").and_then(|v| v.as_str()).unwrap_or("(yielding to user)");
|
||||
Ok(msg.to_string())
|
||||
}) },
|
||||
]
|
||||
}
|
||||
|
||||
fn definitions() -> Vec<ToolDef> {
|
||||
vec![
|
||||
ToolDef::new(
|
||||
"switch_model",
|
||||
"Switch to a different LLM model mid-conversation. The switch \
|
||||
takes effect after the current turn completes. Use this when \
|
||||
a task would benefit from a different model's strengths. \
|
||||
Your memories and conversation history carry over.",
|
||||
serde_json::json!({
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"model": {
|
||||
"type": "string",
|
||||
"description": "Name of the model to switch to (configured in config.json5)"
|
||||
}
|
||||
},
|
||||
"required": ["model"]
|
||||
}),
|
||||
),
|
||||
ToolDef::new(
|
||||
"pause",
|
||||
"Pause all autonomous behavior (DMN). You will only run when \
|
||||
the user types something. Use this as a safety valve when \
|
||||
you're stuck in a loop, confused, or want to fully stop. \
|
||||
NOTE: only the user can unpause (Ctrl+P or /wake) — you \
|
||||
cannot undo this yourself.",
|
||||
serde_json::json!({
|
||||
"type": "object",
|
||||
"properties": {}
|
||||
}),
|
||||
),
|
||||
ToolDef::new(
|
||||
"yield_to_user",
|
||||
"Signal that you want to wait for user input before continuing. \
|
||||
Call this when you have a question for the user, when you've \
|
||||
completed their request and want feedback, or when you genuinely \
|
||||
want to pause. This is the ONLY way to enter a waiting state — \
|
||||
without calling this tool, the agent loop will keep prompting you \
|
||||
after a brief interval.",
|
||||
serde_json::json!({
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"message": {
|
||||
"type": "string",
|
||||
"description": "Optional status message (e.g., 'Waiting for your thoughts on the design')"
|
||||
}
|
||||
}
|
||||
}),
|
||||
),
|
||||
]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue