agent: Fix an issue with messages containing trailing whitespace (#33643)
Bennet Bo Fenner
created
Seeing this come up in our server logs when sending requests to
Anthropic: `final assistant content cannot end with trailing
whitespace`.
Release Notes:
- agent: Fixed an issue where Anthropic requests would sometimes fail
because of malformed assistant messages
@@ -1343,6 +1343,7 @@ impl Thread {
for segment in &message.segments {
match segment {
MessageSegment::Text(text) => {
+ let text = text.trim_end();
if !text.is_empty() {
request_message
.content