microsoft/autogen

Support model APIs that require strict alternating user-assistant roles

Aperta

#5965 aperta il 16 mar 2025

 (2 commenti) (1 reazione) (0 assegnatari)Python (8759 fork)batch import
help wantedproj-agentchat

Metriche repository

Star
 (58.033 stelle)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

          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.

Guida contributor