You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Bug]: When using .NET version of Autogen, if an agent makes parallels function calls using OpenAI, the next response throws an exception about invalid message ordering with tools calls
#2722
Closed
arelath opened this issue
May 19, 2024
· 3 comments
When using Autogen.NET, ChatGPT will occasionally make multiple function calls in the same message. This causes an exception when history with these messages is sent back to the server since it always expects a single message with an array of results, not a message per result. Function calls work fine when there is only one per message.
Steps to reproduce
In the example file dotnet\sample\AutoGen.BasicSamples\Example03_Agent_FunctionCall.cs change the tax calculator to this code:
` varhistory=newList<IMessage>();varrequestTaxRate=new TextMessage(Role.User,"calculate tax of both: 100, 0.1 and 100, 0.2");//var requestTaxRate = new TextMessage(Role.User, "calculate tax of 100, 0.1");varcalculateTax2=await agent.SendAsync(requestTaxRate, history);
history.Add(requestTaxRate);
history.Add(calculateTax2);
calculateTax2.Should().BeOfType<AggregateMessage<ToolCallMessage,ToolCallResultMessage>>();vargoodbye=await agent.SendAsync(new TextMessage(Role.User,"Say Goodbye"), history);`
When the second message is sent, an exception is throw Invalid parameter: messages with role 'tool' must be a response to a preceeding message with 'tool_calls'.
Status: 400 (Bad Request)
It should format the message in the way OpenAI's server expects?
Screenshots and logs
No response
Additional Information
I noticed the function id sent in the response is the function name, not the id for the function call request. This seems to be different than the curl examples in the documentation, but I don't know if it matters because other than this case, function calls work just fine.
The text was updated successfully, but these errors were encountered:
@arelath Thanks for creating this issue, this is a bug in the OpenAIChatRequestMessageConnector, where it put functionName as tool call id when converting message from ToolCall and ToolCallResult to ChatRequestToolMessage and ChatRequestAssistantMessage. When there is only one function call, the conversion works fine because the tool call id is identical. However in parallel function call, there will be two identical tool call ids right after the original function call and that causes a bad request in openai end.
The fix is to add ToolCallId to ToolCall class, and make it default to functionName_{i} if the llm returns a null Id, or using the Id from llm.
Describe the bug
When using Autogen.NET, ChatGPT will occasionally make multiple function calls in the same message. This causes an exception when history with these messages is sent back to the server since it always expects a single message with an array of results, not a message per result. Function calls work fine when there is only one per message.
Steps to reproduce
In the example file dotnet\sample\AutoGen.BasicSamples\Example03_Agent_FunctionCall.cs change the tax calculator to this code:
When the second message is sent, an exception is throw Invalid parameter: messages with role 'tool' must be a response to a preceeding message with 'tool_calls'.
Status: 400 (Bad Request)
debugging the code, there is a single tools request message with 2 functions, but this generates 2 response messages, one for each function. As far as I can tell, they want all tool responses in the same message as an array, not in the content field. (from this example code: https://github.com/openai/openai-cookbook/blob/main/examples/How_to_call_functions_with_chat_models.ipynb?short_path=ff3f9f2)
Model Used
ChatGPT versions. A GPT3.5 and GPT4o version.
Expected Behavior
It should format the message in the way OpenAI's server expects?
Screenshots and logs
No response
Additional Information
I noticed the function id sent in the response is the function name, not the id for the function call request. This seems to be different than the curl examples in the documentation, but I don't know if it matters because other than this case, function calls work just fine.
The text was updated successfully, but these errors were encountered: