microsoft/autogen

Support model APIs that require strict alternating user-assistant roles

Open

#5965 opened on Mar 16, 2025

View on GitHub
 (2 comments) (1 reaction) (0 assignees)Python (58,033 stars) (8,759 forks)batch import
help wantedproj-agentchat

Description

For the 400 server error about alternating user-assistant roles in messages, we need to handle this outside of model client, i.e., in AssistantAgent and SelectorGroupChat, where the model clients are used. Based on the model family in model_info field, we should inject an empty user message when there are consecutive assistant messages.

Originally posted by @ekzhu in https://github.com/microsoft/autogen/issues/5961#issuecomment-2727207546

Reference of 400 error:

openai.BadRequestError: Error code: 400 - {'error': {'message': 'deepseek-reasoner does not support successive user or assistant messages (messages[1] and messages[2] in your input). You should interleave the user/assistant messages in the message sequence.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_request_error'}}

Steps:

  1. Investigate what are the model families that require this strict alternating user-assistant roles? (DeepSeek R1, Mistral AI)
  2. In AssistantAgent and SelectorGroupChat, where model client is used, ensure the messages are following the strict order when the above model families are involved. We can do this by concatenation of messages with repeated roles, or injecting empty message -- need to test them.

Contributor guide