Skip to main content

tinyharness_lib/tools/
auto_compact.rs

1use std::collections::HashMap;
2
3use crate::tools::tool::{BoxFuture, ToolCategory, build_string_params_schema, make_tool};
4
5pub fn auto_compact_tool_entry() -> crate::tools::tool::Tool {
6    make_tool(
7        "auto_compact",
8        "Compact the conversation history by summarizing older messages. Use this when the conversation is getting long and you need to free up context space. The recent messages will be preserved, while older messages will be summarized into a concise summary.",
9        ToolCategory::Signal,
10        build_string_params_schema(
11            &[],
12            &[(
13                "focus",
14                "Specific topics, decisions, or details to preserve in the summary",
15                "",
16            )],
17        ),
18        |args| Box::pin(auto_compact_tool(args)),
19    )
20}
21
22pub fn auto_compact_tool(args: HashMap<String, String>) -> BoxFuture<'static, String> {
23    Box::pin(async move {
24        let focus = args.get("focus").cloned().unwrap_or_default();
25
26        // Signal to the agent that compaction is requested
27        // The actual compaction will be handled specially in agent.rs
28        // (similar to how switch_mode and question tools are handled)
29        if focus.is_empty() {
30            "AUTO_COMPACT_REQUESTED: The model has requested to compact the conversation history. No specific focus provided.".to_string()
31        } else {
32            format!(
33                "AUTO_COMPACT_REQUESTED: The model has requested to compact the conversation history with focus on: {}",
34                focus
35            )
36        }
37    })
38}