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:
Agus Zubiaga 2025-04-22 00:41:47 -03:00 committed by GitHub
parent 19ef56ba7c
commit b14356d1d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 45 deletions

View file

@ -221,23 +221,16 @@ impl LanguageModelRequestMessage {
}
pub fn contents_empty(&self) -> bool {
self.content.is_empty()
|| self
.content
.first()
.map(|content| match content {
MessageContent::Text(text) => text.chars().all(|c| c.is_whitespace()),
MessageContent::Thinking { text, .. } => {
text.chars().all(|c| c.is_whitespace())
}
MessageContent::ToolResult(tool_result) => {
tool_result.content.chars().all(|c| c.is_whitespace())
}
MessageContent::RedactedThinking(_)
| MessageContent::ToolUse(_)
| MessageContent::Image(_) => true,
})
.unwrap_or(false)
self.content.iter().all(|content| match content {
MessageContent::Text(text) => text.chars().all(|c| c.is_whitespace()),
MessageContent::Thinking { text, .. } => text.chars().all(|c| c.is_whitespace()),
MessageContent::ToolResult(tool_result) => {
tool_result.content.chars().all(|c| c.is_whitespace())
}
MessageContent::RedactedThinking(_)
| MessageContent::ToolUse(_)
| MessageContent::Image(_) => false,
})
}
}