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
95 changes: 95 additions & 0 deletions src/agent/agent_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ use crate::safety::SafetyLayer;
use crate::tools::ToolRegistry;
use crate::workspace::Workspace;

/// Collapse a tool output string into a single-line preview for display.
fn truncate_for_preview(output: &str, max_chars: usize) -> String {
let collapsed: String = output
.chars()
.take(max_chars + 50)
.map(|c| if c == '\n' { ' ' } else { c })
.collect::<String>()
.split_whitespace()
.collect::<Vec<_>>()
.join(" ");
if collapsed.len() > max_chars {
format!("{}...", &collapsed[..max_chars])
} else {
collapsed
}
}

/// Result of the agentic loop execution.
enum AgenticLoopResult {
/// Completed with a response.
Expand Down Expand Up @@ -877,10 +894,49 @@ impl Agent {
}
}

let _ = self
.channels
.send_status(
&message.channel,
StatusUpdate::ToolStarted {
name: tc.name.clone(),
},
&message.metadata,
)
.await;

let tool_result = self
.execute_chat_tool(&tc.name, &tc.arguments, &job_ctx)
.await;

let _ = self
.channels
.send_status(
&message.channel,
StatusUpdate::ToolCompleted {
name: tc.name.clone(),
success: tool_result.is_ok(),
},
&message.metadata,
)
.await;

if let Ok(ref output) = tool_result {
if !output.is_empty() {
let _ = self
.channels
.send_status(
&message.channel,
StatusUpdate::ToolResult {
name: tc.name.clone(),
preview: truncate_for_preview(output, 200),
},
&message.metadata,
)
.await;
}
}

// Record result in thread
{
let mut sess = session.lock().await;
Expand Down Expand Up @@ -1256,10 +1312,49 @@ impl Agent {
let job_ctx =
JobContext::with_user(&message.user_id, "chat", "Interactive chat session");

let _ = self
.channels
.send_status(
&message.channel,
StatusUpdate::ToolStarted {
name: pending.tool_name.clone(),
},
&message.metadata,
)
.await;

let tool_result = self
.execute_chat_tool(&pending.tool_name, &pending.parameters, &job_ctx)
.await;

let _ = self
.channels
.send_status(
&message.channel,
StatusUpdate::ToolCompleted {
name: pending.tool_name.clone(),
success: tool_result.is_ok(),
},
&message.metadata,
)
.await;

if let Ok(ref output) = tool_result {
if !output.is_empty() {
let _ = self
.channels
.send_status(
&message.channel,
StatusUpdate::ToolResult {
name: pending.tool_name.clone(),
preview: truncate_for_preview(output, 200),
},
&message.metadata,
)
.await;
}
}

// Build context including the tool result
let mut context_messages = pending.context_messages;

Expand Down
2 changes: 2 additions & 0 deletions src/channels/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ pub enum StatusUpdate {
ToolStarted { name: String },
/// Tool execution completed.
ToolCompleted { name: String, success: bool },
/// Brief preview of tool execution output.
ToolResult { name: String, preview: String },
/// Streaming text chunk.
StreamChunk(String),
/// General status message.
Expand Down
Loading