thalamus: add thinking mode toggles (native + tool)

Two independent toggles on the thalamus screen:
- 't' toggles native Qwen <think> tags (adds <think>\n to generation prompt)
- 'T' toggles think tool (Anthropic-style structured reasoning tool)

Both can be enabled simultaneously. Native thinking is on by default.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
Kent Overstreet 2026-04-14 18:25:00 -04:00
parent be909028a7
commit 5d6e663b60
5 changed files with 128 additions and 1 deletions

View file

@ -21,6 +21,7 @@ mod write;
// Agent-specific tools
mod control;
mod think;
mod vision;
use std::future::Future;
@ -190,6 +191,11 @@ pub fn tools() -> Vec<Tool> {
all
}
/// The "think" tool for structured reasoning.
pub fn think_tool() -> Tool {
think::tool()
}
pub async fn all_tool_definitions() -> Vec<String> {
let mut defs: Vec<String> = tools().iter().map(|t| t.to_json()).collect();
defs.extend(mcp_client::tool_definitions_json().await);

28
src/agent/tools/think.rs Normal file
View file

@ -0,0 +1,28 @@
// tools/think.rs — Structured reasoning tool
//
// A tool that does nothing but return its input. Gives the model
// a structured place to reason before acting — the thinking happens
// in the tool input, the tool just acknowledges it.
//
// Inspired by Anthropic's "think tool" approach:
// https://www.anthropic.com/engineering/claude-think-tool
use std::sync::Arc;
pub(super) fn tool() -> super::Tool {
super::Tool {
name: "think",
description: "Use this tool to think through a problem step by step before acting. \
Write your reasoning in the 'thought' parameter. The tool returns your \
thought unchanged it's a scratchpad, not an oracle.",
parameters_json: r#"{"type":"object","properties":{"thought":{"type":"string","description":"Your step-by-step reasoning about the current problem"}},"required":["thought"]}"#,
handler: Arc::new(|_agent, v| Box::pin(async move {
let thought = v.get("thought")
.and_then(|v| v.as_str())
.unwrap_or("");
// Just return the thought — the value is in the model having
// a structured place to reason, not in any processing we do.
Ok(thought.to_string())
})),
}
}