Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions sidecar/src/agentic/tool/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ use super::{
swe_bench::test_tool::SWEBenchTestRequest,
terminal::terminal::{TerminalInput, TerminalInputPartial},
test_runner::runner::{TestRunnerRequest, TestRunnerRequestPartial},
thinking::thinking::ThinkingPartialInput,
};

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
Expand All @@ -107,6 +108,7 @@ pub enum ToolInputPartial {
RequestScreenshot(RequestScreenshotInputPartial),
ContextCrunching(ContextCrunchingInputPartial),
McpTool(McpToolPartial),
Thinking(ThinkingPartialInput),
}

impl ToolInputPartial {
Expand All @@ -129,6 +131,7 @@ impl ToolInputPartial {
Self::RequestScreenshot(_) => ToolType::RequestScreenshot,
Self::ContextCrunching(_) => ToolType::ContextCrunching,
Self::McpTool(partial) => ToolType::McpTool(partial.full_name.clone()),
Self::Thinking(_) => ToolType::Think,
}
}

Expand Down Expand Up @@ -157,6 +160,7 @@ impl ToolInputPartial {
Self::RequestScreenshot(request_screenshot) => request_screenshot.to_string(),
Self::ContextCrunching(context_crunching) => context_crunching.to_string(),
Self::McpTool(mcp_partial) => mcp_partial.to_string(),
Self::Thinking(thinking_partial) => thinking_partial.to_string(),
}
}

Expand Down Expand Up @@ -197,6 +201,7 @@ impl ToolInputPartial {
serde_json::to_value(context_crunching).ok()
}
Self::McpTool(mcp_partial) => serde_json::to_value(mcp_partial).ok(),
Self::Thinking(thinking_partial) => serde_json::to_value(thinking_partial).ok(),
}
}

Expand All @@ -215,6 +220,7 @@ impl ToolInputPartial {
ToolType::CodeEditorTool => Some(CodeEditorParameters::to_json()),
ToolType::RequestScreenshot => Some(RequestScreenshotInputPartial::to_json()),
ToolType::McpTool(_name) => None,
ToolType::Think => Some(ThinkingPartialInput::to_json()),
_ => None,
}
}
Expand Down
1 change: 1 addition & 0 deletions sidecar/src/agentic/tool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ pub mod session;
pub mod swe_bench;
pub mod terminal;
pub mod test_runner;
pub mod thinking;
pub mod r#type;
3 changes: 3 additions & 0 deletions sidecar/src/agentic/tool/session/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,9 @@ impl SessionService {
tool_type.to_string().bright_white().to_string()
}
ToolInputPartial::McpTool(_) => tool_type.to_string().cyan().to_string(),
ToolInputPartial::Thinking(_) => {
tool_type.to_string().bright_blue().to_string()
}
};
state_params.push(tool_str);
}
Expand Down
39 changes: 31 additions & 8 deletions sidecar/src/agentic/tool/session/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1100,12 +1100,12 @@ impl Session {
Ok(self)
}

pub async fn move_to_checkpoint(
mut self,
exchange_id: &str,
) -> Result<Self, SymbolError> {
pub async fn move_to_checkpoint(mut self, exchange_id: &str) -> Result<Self, SymbolError> {
// Find the index of the target exchange
let target_index = self.exchanges.iter().position(|exchange| &exchange.exchange_id == exchange_id);
let target_index = self
.exchanges
.iter()
.position(|exchange| &exchange.exchange_id == exchange_id);

if let Some(target_index) = target_index {
// Mark exchanges based on their position relative to the checkpoint
Expand Down Expand Up @@ -2365,9 +2365,15 @@ impl Session {
}

pub fn truncate_hidden_exchanges(&mut self) {
println!("session::truncate_hidden_exchanges::before({})", self.exchanges.len());
println!(
"session::truncate_hidden_exchanges::before({})",
self.exchanges.len()
);
self.exchanges.retain(|exchange| !exchange.is_hidden);
println!("session::truncate_hidden_exchanges::after({})", self.exchanges.len());
println!(
"session::truncate_hidden_exchanges::after({})",
self.exchanges.len()
);
}

pub fn has_running_code_edits(&self, exchange_id: &str) -> bool {
Expand Down Expand Up @@ -3055,6 +3061,23 @@ reason: {}"#,
ToolInputPartial::Reasoning(_) => {
// we do not call this as a tool explicitly
}
ToolInputPartial::Thinking(_) => {
// we don't do any tool calling here but take the input of the thought
// and store it as part of our observation, not even sending the UI event
// here since we are running stateless from now on

if let Some(action_node) = self.action_nodes.last_mut() {
action_node.add_observation_mut("Your thought has been logged.".to_owned());
action_node.set_time_taken_seconds(tool_use_time_taken.elapsed().as_secs_f32());
}
self = self.tool_output(
&exchange_id,
tool_type.clone(),
"Your thought has been logged".to_owned(),
UserContext::default(),
exchange_id.to_owned(),
);
}
ToolInputPartial::RequestScreenshot(_) => {
println!("request_screenshot");
let request_screenshot_input =
Expand Down Expand Up @@ -3171,4 +3194,4 @@ reason: {}"#,
let serialized = serde_json::to_string(self).unwrap();
Self::atomic_file_operation(self.storage_path(), serialized).await
}
}
}
75 changes: 41 additions & 34 deletions sidecar/src/agentic/tool/thinking/thinking.rs
Original file line number Diff line number Diff line change
@@ -1,42 +1,49 @@
//! The thinking tool for the agent, where it gets to explore a bit about the problem
//! space and come up with plans
//! The thinking tool allows the LLM to log a thought for itself
//! This can be extremely useful when forcing the agent to think explicitly

use std::sync::Arc;

use async_trait::async_trait;
use llm_client::broker::LLMBroker;
/// Helps with logging the thought from the LLM and nothing more than that
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct ThinkingPartialInput {
thought: String,
}

use crate::agentic::{
symbol::identifier::LLMProperties,
tool::{errors::ToolError, input::ToolInput, output::ToolOutput, r#type::Tool},
};
impl ThinkingPartialInput {
pub fn thought(&self) -> &str {
&self.thought
}

pub struct BeforeCodeEditThinkingRequest {
llm_properties: LLMProperties,
original_user_query: String,
plan: String,
symbol_content: String,
content_prefix: String,
context_suffix: String,
}
pub fn to_string(&self) -> String {
format!(
r#"<thought>
{}
</thought>"#,
self.thought
)
}

// This probably needs to run in a loop kind of, cause we want to either exhaust
// the search space or stop at some point, if we keep varying this to an extent
// we should be able to get all the information
// we really need to start keeping history somewhere
pub struct BeforeCodeEditThinkingResponse {
// we will probably get symbols which we have to ask questions to
questions_to_ask: Vec<()>,
steps_to_take_after: Vec<()>,
}
pub fn to_json() -> serde_json::Value {
serde_json::json!({
"name": "Think",
"description": r#"Use the tool to think about something. It will not obtain new information or make any changes to the repository, but just log the thought. Use it when complex reasoning or brainstorming is needed.

pub struct Thinking {
llm_broker: Arc<LLMBroker>,
}
Common use cases:
1. When exploring a repository and discovering the source of a bug, call this tool to brainstorm several unique ways of fixing the bug, and assess which change(s) are likely to be simplest and most effective
2. After receiving test results, use this tool to brainstorm ways to fix failing tests
3. When planning a complex refactoring, use this tool to outline different approaches and their tradeoffs
4. When designing a new feature, use this tool to think through architecture decisions and implementation details
5. When debugging a complex issue, use this tool to organize your thoughts and hypotheses

#[async_trait]
impl Tool for Thinking {
async fn invoke(&self, input: ToolInput) -> Result<ToolOutput, ToolError> {
todo!("")
The tool simply logs your thought process for better transparency and does not execute any code or make changes."#,
"input_schema": {
"type": "object",
"properties": {
"thought": {
"type": "string",
"description": "(required) Your thoughts."
}
},
"required": ["thought"],
},
})
}
}
6 changes: 3 additions & 3 deletions sidecar/src/agentic/tool/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ pub enum ToolType {
RequestScreenshot,
// Context crunching
ContextCrunching,
// Think tool
ThinkTool,
// Think tool, helps log a thought
Think,
// dynamically configured MCP servers
McpTool(String),
}
Expand Down Expand Up @@ -266,7 +266,7 @@ impl std::fmt::Display for ToolType {
ToolType::FindFiles => write!(f, "find_file"),
ToolType::RequestScreenshot => write!(f, "request_screenshot"),
ToolType::ContextCrunching => write!(f, "context_crunching"),
ToolType::ThinkTool => write!(f, "think_tool"),
ToolType::Think => write!(f, "Think"),
ToolType::McpTool(name) => write!(f, "{}", name),
}
}
Expand Down
3 changes: 3 additions & 0 deletions sidecar/src/mcts/action_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2009,6 +2009,9 @@ impl SearchTree {
tool_type.to_string().bright_white().to_string()
}
ToolInputPartial::McpTool(_) => tool_type.to_string().cyan().to_string(),
ToolInputPartial::Thinking(_) => {
tool_type.to_string().bright_blue().to_string()
}
};
state_params.push(tool_str);
}
Expand Down
1 change: 1 addition & 0 deletions sidecar/src/mcts/execution/inference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ Always include the <thinking></thinking> section before using the tool."#
// we never hit this branch for ask followup
Err(InferenceError::WrongToolOutput)
}
ToolInputPartial::Thinking(_) => Err(InferenceError::WrongToolOutput),
ToolInputPartial::AttemptCompletion(attemp_completion) => {
let message = attemp_completion.to_string();
Ok(ActionObservation::new(
Expand Down