agent: Fix "tool cancelled" status being overapplied to failed tool calls (#30021)
Release Notes: - Agent Beta: Fixed a bug that caused past failed tool calls to incorrectly display as cancelled by the user.
This commit is contained in:
parent
7a9165d5ce
commit
b83d00d69b
1 changed files with 21 additions and 14 deletions
|
@ -110,20 +110,27 @@ impl ToolUseState {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cancel_pending(&mut self) -> Vec<PendingToolUse> {
|
pub fn cancel_pending(&mut self) -> Vec<PendingToolUse> {
|
||||||
let mut pending_tools = Vec::new();
|
let mut cancelled_tool_uses = Vec::new();
|
||||||
for (tool_use_id, tool_use) in self.pending_tool_uses_by_id.drain() {
|
self.pending_tool_uses_by_id
|
||||||
self.tool_results.insert(
|
.retain(|tool_use_id, tool_use| {
|
||||||
tool_use_id.clone(),
|
if matches!(tool_use.status, PendingToolUseStatus::Error { .. }) {
|
||||||
LanguageModelToolResult {
|
return true;
|
||||||
tool_use_id,
|
}
|
||||||
tool_name: tool_use.name.clone(),
|
|
||||||
content: "Tool canceled by user".into(),
|
let content = "Tool canceled by user".into();
|
||||||
is_error: true,
|
self.tool_results.insert(
|
||||||
},
|
tool_use_id.clone(),
|
||||||
);
|
LanguageModelToolResult {
|
||||||
pending_tools.push(tool_use.clone());
|
tool_use_id: tool_use_id.clone(),
|
||||||
}
|
tool_name: tool_use.name.clone(),
|
||||||
pending_tools
|
content,
|
||||||
|
is_error: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
cancelled_tool_uses.push(tool_use.clone());
|
||||||
|
false
|
||||||
|
});
|
||||||
|
cancelled_tool_uses
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pending_tool_uses(&self) -> Vec<&PendingToolUse> {
|
pub fn pending_tool_uses(&self) -> Vec<&PendingToolUse> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue