microsoft/autogen

Support model APIs that require strict alternating user-assistant roles

Open

#5,965 创建于 2025年3月16日

在 GitHub 查看
 (2 评论) (1 反应) (0 负责人)Python (58,033 star) (8,759 fork)batch import
help wantedproj-agentchat

描述

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.

贡献者指南