Skip to content

fix: prompt user explicitly for reason upon denying tool request #145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
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
27 changes: 25 additions & 2 deletions crates/chat-cli/src/cli/chat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,7 @@ impl ChatContext {
Ok(match command {
Command::Ask { prompt } => {
// Check for a pending tool approval
let mut reason_prompt = String::from("Tool denied: ");
if let Some(index) = pending_tool_index {
let tool_use = &mut tool_uses[index];

Expand All @@ -1347,6 +1348,23 @@ impl ChatContext {
tool_use.accepted = true;

return Ok(ChatState::ExecuteTools(tool_uses));
// Prompt reason if no selected
} else if ["n", "N"].contains(&prompt.as_str()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you instead just define a variable like tool_use_denied_without_reason or something for the ["n", "N"].contains(&prompt.as_str()) check? In case we also add other cases like "no" etc.

tool_use.accepted = false;
execute!(
self.output,
style::SetForegroundColor(Color::DarkGrey),
style::Print("\nPlease provide a reason for denying this tool use:\n\n"),
style::SetForegroundColor(Color::Reset),
)?;
let reason: String = match self.read_user_input("> ".yellow().to_string().as_str(), true) {
Some(input) if !input.trim().is_empty() => input,
_ => "No reason provided".to_string(),
};
reason_prompt.push_str(&reason);
reason_prompt.push_str(
". Take user feedback and try again if reason provided, else continue conversation.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only way to provide no reason seems to be ctrl+c - in which case, let's not send the request to the model since its response seems to be junk.

Instead, I think the flow should be:

# model requests a tool use

> n

Please provide a reason for denying this tool use, or otherwise continue your conversation:\n\n

# user hits ctrl+c, and gets into the exit flow where we check two consecutive ctrl+c's before exiting

(To exit the CLI, press Ctrl+C or Ctrl+D again or type /quit)

> n

Please provide a reason for denying this tool use, or otherwise continue your conversation:\n\n

# we give the same message if they enter "n" again.

> i instead want this tool use....

# send the response with the abandoned tool use and this new prompt

);
}
} else if !self.pending_prompts.is_empty() {
let prompts = self.pending_prompts.drain(0..).collect();
Expand All @@ -1358,9 +1376,12 @@ impl ChatContext {

// Otherwise continue with normal chat on 'n' or other responses
self.tool_use_status = ToolUseStatus::Idle;

if pending_tool_index.is_some() {
self.conversation_state.abandon_tool_use(tool_uses, user_input);
if ["n", "N"].contains(&prompt.as_str()) {
self.conversation_state.abandon_tool_use(tool_uses, reason_prompt);
} else {
self.conversation_state.abandon_tool_use(tool_uses, user_input);
}
} else {
self.conversation_state.set_next_user_message(user_input).await;
}
Expand Down Expand Up @@ -3973,11 +3994,13 @@ mod tests {
"/tools untrust fs_write".to_string(),
"create a file".to_string(), // prompt again due to untrust
"n".to_string(), // cancel
"No reason".to_string(), // provide reason for cancel
"/tools trust fs_write".to_string(),
"create a file".to_string(), // again without prompting due to '/tools trust'
"/tools reset".to_string(),
"create a file".to_string(), // prompt again due to reset
"n".to_string(), // cancel
"No reason".to_string(), // provide reason for cancel
"exit".to_string(),
]),
true,
Expand Down
Loading