mirror of
https://github.com/microsoft/autogen.git
synced 2025-08-22 15:41:56 +00:00

## Why are these changes needed? This PR fixes a `400 - invalid_request_error` that occurs when using Anthropic models and the **final message is from the assistant and ends with trailing whitespace**. Example error: ``` Error code: 400 - {'error': {'code': 'invalid_request_error', 'message': 'messages: final assistant content cannot end with trailing whitespace', ...}} ``` To unblock ongoing internal usage, this patch introduces an **ad-hoc fix** that strips trailing whitespace if the model is Anthropic and the last message is from the assistant. ## Related issue number Ad-hoc fix for issue discussed here: https://github.com/microsoft/autogen/issues/6167 Follow-up structural proposal here: https://github.com/microsoft/autogen/issues/6167 https://github.com/microsoft/autogen/issues/6167#issuecomment-2768592840