agent: Do not add <using_tool>
placeholder (#29194)
Our provider code in `language_models` filters out messages for which `LanguageModelRequestMessage::contents_empty` returns `false`. This doesn't seem wrong by itself, but `contents_empty` was returning `false` for messages whose first segment didn't contain non-whitespace text even if they contained other non-empty segments. This caused requests to fail when a message with a tool call didn't contain any preceding text. Release Notes: - N/A
This commit is contained in:
parent
19ef56ba7c
commit
b14356d1d3
3 changed files with 13 additions and 45 deletions
|
@ -27,8 +27,6 @@ pub struct ToolUse {
|
|||
pub needs_confirmation: bool,
|
||||
}
|
||||
|
||||
pub const USING_TOOL_MARKER: &str = "<using_tool>";
|
||||
|
||||
pub struct ToolUseState {
|
||||
tools: Entity<ToolWorkingSet>,
|
||||
tool_uses_by_assistant_message: HashMap<MessageId, Vec<LanguageModelToolUse>>,
|
||||
|
@ -452,28 +450,8 @@ impl ToolUseState {
|
|||
request_message: &mut LanguageModelRequestMessage,
|
||||
) {
|
||||
if let Some(tool_uses) = self.tool_uses_by_assistant_message.get(&message_id) {
|
||||
let mut found_tool_use = false;
|
||||
|
||||
for tool_use in tool_uses {
|
||||
if self.tool_results.contains_key(&tool_use.id) {
|
||||
if !found_tool_use {
|
||||
// The API fails if a message contains a tool use without any (non-whitespace) text around it
|
||||
match request_message.content.last_mut() {
|
||||
Some(MessageContent::Text(txt)) => {
|
||||
if txt.is_empty() {
|
||||
txt.push_str(USING_TOOL_MARKER);
|
||||
}
|
||||
}
|
||||
None | Some(_) => {
|
||||
request_message
|
||||
.content
|
||||
.push(MessageContent::Text(USING_TOOL_MARKER.into()));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
found_tool_use = true;
|
||||
|
||||
// Do not send tool uses until they are completed
|
||||
request_message
|
||||
.content
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue