microsoft / autogen

A programming framework for agentic AI 🤖
https://microsoft.github.io/autogen/
Creative Commons Attribution 4.0 International
30.79k stars 4.49k forks source link

[Issue]: Error When Resuming GroupChat: Invalid Parameter for 'tool' Role Messages #3164

Open Vithusha-T opened 1 month ago

Vithusha-T commented 1 month ago

Describe the issue

I am encountering an error when using the "Resuming a GroupChat" feature. When I initialize the group chat for the first time, it works perfectly. However, after resuming the chat by passing the chat_history and attempting to call a function within the group chat, I receive the following error:

BadRequestError: Error code: 400 - {'error': {'message': "Invalid parameter: messages with role 'tool' must be a response to a preceding message with 'tool_calls'.", 'type': 'invalid_request_error', 'param': 'messages.[2].role', 'code': None}}

here is the code snippet i'm trying

groupchat = autogen.GroupChat(agents=LIST_OF_AGENTS, messages=[])
manager = autogen.GroupChatManager(
    groupchat=groupchat,
    llm_config=llm_config,
    is_termination_msg=lambda x: "TERMINATE" in x.get("content", "")
    )

# start the conversation for the first time
result=user_proxy.initiate_chat(
    manager,
    message = question,
    clear_history=False,

)

# resume the group chat
last_agent, last_message = manager.resume(messages=result.chat_history, remove_termination_string="TERMINATE")

# getting error in this place
manager.initiate_chat(
    recipient=user_proxy,
    message="""can you get the previous task id and assign the task to john wick """,
    clear_history=False,
    )

the agent is using the fuction calls

Steps to reproduce

  1. Initialize a group chat and use the "Resuming a GroupChat" feature.
  2. Use a function call agent within the group chat.
  3. Resume the group chat using chat_history messages and attempt to call the same function.

Screenshots and logs

No response

Additional Information

AutoGen Version: 0.2.32 Operating System: Wndows11 /ubuntu 20.04 Python Version: 3.11.2

marklysze commented 1 month ago

Hi @Vithusha-T, thanks for noting this - would you be able to show what's in the chat_history?