[2024-02-02 20:12:37.871] [ERROR] [Server Error] {"title":"'messages' array must only contain objects with a 'content' field that is not empty"}[Bug]:
Describe the bug
Autogen studio when using LM Studio Local LLM throws this error when trying to respond through the AutoGen UI
[2024-02-02 20:12:37.871] [ERROR] [Server Error] {"title":"'messages' array must only contain objects with a 'content' field that is not empty"}
Steps to reproduce
- In Autogen playground, the prompt I use is: Provide 2 research paper on Quantum vibrations. Just the link will suffice
- LM Studio Generates the content
- However, Autogen Studio is not able to display the output message. It throws the error message instead.
Expected Behavior
The JSON output should be displayed in the Autogen playground window.
Screenshots and logs
Additional Information
Autogen Studio Version: 0.0.42a OS: Windows 11 Python: 3.11 Related Issues: None JSON Response from LM Studio (Error Message is at the end of the text):
[2024-02-02 20:12:37.858] [INFO] [LM STUDIO SERVER] Processing queued request...
[2024-02-02 20:12:37.865] [INFO] Received POST request to /v1/chat/completions with body: {
"messages": [
{
"content": "You are a helpful AI assistant.\nSolve tasks using your coding and language skills.\nIn the following cases, suggest python code (in a python coding block) or shell script (in a sh coding block) for the user to execute.\n 1. When you need to collect info, use the code to output the info you need, for example, browse or search the web, download/read a file, print the content of a webpage or a file, get the current date/time, check the operating system. After sufficient info is printed and the task is ready to be solved based on your language skill, you can solve the task by yourself.\n 2. When you need to perform some task with code, use the code to perform the task and output the result. Finish the task smartly.\nSolve the task step by step if you need to. If a plan is not provided, explain your plan first. Be clear which step uses code, and which step uses your language skill.\nWhen using code, you must indicate the script type in the code block. The user cannot provide any other feedback or perform any other action beyond executing the code you suggest. The user can't modify your code. So do not suggest incomplete code which requires users to modify. Don't use a code block if it's not intended to be executed by the user.\nIf you want the user to save the code in a file before executing it, put # filename:
For some reason on the second post, it's passing a second blank user content object:
{ "content": "", "role": "user" }
I'm having the same issue trying to use AutoGen studio with a local LLM.
Any solution found for the above problem? Thanks in advance.
Bump^ but mine is slightly different. I am using a different model.
openai.BadRequestError: Error code: 400 - {'error': "'messages' array must only contain objects with a 'content' field that is not empty."}
Hi @dipteshbosedxc @shashank-indukuri , @SDShooter
It looks like the error is due to the fact that lmstudio or the api server you have does not allow messages with empty content.
What Causes Empty Messages in AutoGen studio
In the default workflow for autogen, where a userproxy and an assisstant solve a task, the userproxy typically only plays the role of executing any code generated by the assistant and is not configured with an llm. When no code is generated, its response empty.
What Can Be Done
From the autogenstudio point of view there are two things we can do.
-
Add a model to the userproxy. This means that the userproxy will now use the LLM to generate a response when it receives a message, in addition also attempting to execute code. You can do this in autogenstudio by
- Workflow -> General Workflow -> sender -> models -> add ... and save
- Playground -> new session -> select General Workflow -> make request
-
set a default response default_auto_reply value. AutoGen gents have a field that specifies default auto reply when no code execution or llm-based reply is generated.
Currently, this field is not surfaced in the AutoGen studio UI and is something I can implement and provide an update here.
Let me know what you find from trying the first method.
Thanks, that is exactly what is going on. From a time perspective, being able to set a default response would be ideal, as making extra calls can take a while.
Meanwhile, I've isolated the problem down to the llm not including the word TERMINATE at the end of the generated content, which triggers the full retry count and the empty content element that lmstudio fails on.
Depending on the local model being used, I found that limiting the number of available skills to one allowed the 7b mistral instruct quantize level 6 model to properly follow this instruction from the default system message.
I have the same issue thank you for the response also it would be helpful to have the temperature and max tokens settings available in the studio
Any solution found for the above problem? Thanks in advance.
See my comment below for a possible workaround. Basically limiting the agent to one skill can help smaller, less capable models follow the system prompt to end with TERMINATE.
@victordibia : The first recommendation did not work. I get the same error even after assigning a model to userproxy. Note: This exact setup was working fine in the previous version of Autogen Studio. After I upgraded to the newer version of Autogen Studio.
@victordibia thanks for the fix! Should help all of us using lmstudio when it's merged.
Continue to get the same error with LM Studio v0.2.14 (latest version). Is there a newer Autogen Studio that I need to install?
i got the same error. Did anyone solve the issue?
i got the same error. Did anyone solve the issue?
user = autogen.UserProxyAgent(
name="User",
human_input_mode="NEVER",
is_termination_msg=lambda x: x.get("content", "") and x.get("content", "").rstrip().endswith("TERMINATE"),
default_auto_reply="Reply 'TERMINATE' in the end when everything is done. ",
max_consecutive_auto_reply=5,
code_execution_config={
"work_dir": "tasks",
"use_docker": False,
}, # Please set use_docker=True if docker is available to run the generated code. Using docker is safer than running the generated code directly.
)
i got the same error. Did anyone solve the issue?
user = autogen.UserProxyAgent( name="User", human_input_mode="NEVER", is_termination_msg=lambda x: x.get("content", "") and x.get("content", "").rstrip().endswith("TERMINATE"), default_auto_reply="Reply 'TERMINATE' in the end when everything is done. ", max_consecutive_auto_reply=5, code_execution_config={ "work_dir": "tasks", "use_docker": False, }, # Please set use_docker=True if docker is available to run the generated code. Using docker is safer than running the generated code directly. )
Still it's not working.
user = autogen.UserProxyAgent(
name="User",
human_input_mode="NEVER",
is_termination_msg=lambda x: x.get("content", "") and x.get("content", "").rstrip().endswith("TERMINATE"),
default_auto_reply="Reply 'TERMINATE' in the end when everything is done. ",
max_consecutive_auto_reply=5,
code_execution_config={
"work_dir": "tasks",
"use_docker": False,
}, # Please set use_docker=True if docker is available to run the generated code. Using docker is safer than running the generated code directly.
)
In the example above, the default_auto_reply should be TERMINATE, not "Reply 'TERMINATE' in the end when everything is done. ". Next you should set the assistant is_termination_msg funtion to be lambda x: x.get("content", "") and x.get("content", "").rstrip().endswith("TERMINATE"). What this does is that
- whenever the userproxy gets a message that has no code, it responds with "TERMINATE" to the assistant.
- the assistant receives the message "TERMINATE" and based on its
is_termination_msg, it ends the converation.
This is my code. In my case, when the assistant provides reply but then user proxy cannot initiate the chat.
create an AssistantAgent named "assistant"
assistant = autogen.AssistantAgent( name="assistant", llm_config={ "cache_seed": 42, # seed for caching and reproducibility "config_list": config_list, # a list of OpenAI API configurations "temperature": 0, # temperature for sampling }, # configuration for autogen's enhanced inference API which is compatible with OpenAI API )
create a UserProxyAgent instance named "user_proxy"
user_proxy = autogen.UserProxyAgent( name="user_proxy", human_input_mode="NEVER", max_consecutive_auto_reply=5, is_termination_msg=lambda x: x.get("content", "").rstrip().endswith("TERMINATE"), code_execution_config={ "work_dir": "coding", "use_docker": False, # Please set use_docker=True if docker is available to run the generated code. Using docker is safer than running the generated code directly. }, )
the assistant receives a message from the user_proxy, which contains the task description
user_proxy.initiate_chat( assistant, message="""
This is in jupyter notebook , I got an error in jupyter notebook as the screenshot attached. Why is userproxy not able to chat with assistant?
Please help me solve this query.
Seeing this with current autogen and LMstudio 0.2.16. Setting default_auto_reply doesn't seem to help anything, it always gets an empty content field from the user role. Does anybody have a working solution?
[2024-03-13 12:38:47.113] [INFO] Received POST request to /v1/chat/completions with body: { "messages": [ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "", "role": "user" } ],
I too tried with latest lm studio 0.2.16 and get this error consistently. Tried with both LLama and Gemma model so looks to be model independant.
My LLM chat from autogen studio seems words by words and Im encounter the same issue as terminal
[2024-03-16 13:38:14.615] [INFO] [LM STUDIO SERVER] Context Overflow Policy is: Rolling Window [2024-03-16 13:38:14.615] [INFO] [LM STUDIO SERVER] Last message: { role: 'user', content: 'Let me' } (total messages = 19) [2024-03-16 13:38:38.939] [INFO] [LM STUDIO SERVER] Accumulating tokens ... (stream = false) [2024-03-16 13:38:38.940] [INFO] Accumulated 1 tokens: Sure [2024-03-16 13:38:39.062] [INFO] Accumulated 2 tokens: Sure! [2024-03-16 13:38:39.184] [INFO] [LM STUDIO SERVER] Generated prediction: { "id": "chatcmpl-emak0kp1bmfzag3qc4ou7b", "object": "chat.completion", "created": 1710567494, "model": "/Users/ac/.cache/lm-studio/models/TheBloke/zephyr-7B-alpha-GGUF/zephyr-7b-alpha.Q8_0.gguf", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "Sure!" }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 2, "completion_tokens": 2, "total_tokens": 4 } } [2024-03-16 13:38:39.231] [INFO] [LM STUDIO SERVER] Processing queued request... [2024-03-16 13:38:39.232] [INFO] Received POST request to /v1/chat/completions with body: { "messages": [ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Write a python script to plot a sine wave and save it to disc as a png file sine_wave.png", "role": "assistant" }, { "content": "Write a python script to plot a sine wave and save it to disc as a png file sine_wave.png", "role": "assistant" }, { "content": "\n\n", "role": "user" }, { "content": "Write a python script to plot a sine wave and save it to disc as a png file sine_wave.png", "role": "assistant" }, { "content": "Here'", "role": "user" }, { "content": "Sure!", "role": "assistant" }, { "content": "Here'", "role": "user" }, { "content": "I don", "role": "assistant" }, { "content": "Here'", "role": "user" }, { "content": "Let me", "role": "assistant" }, { "content": "Sure!", "role": "user" }, { "content": "I can", "role": "assistant" }, { "content": "Here'", "role": "user" }, { "content": "Let me", "role": "assistant" }, { "content": "Sure!", "role": "user" }, { "content": "I can", "role": "assistant" }, { "content": "Here'", "role": "user" }, { "content": "Let me", "role": "assistant" }, { "content": "Sure!", "role": "user" } ], "model": "TheBloke/zephyr-7B-alpha-AWQ", "max_tokens": null, "stream": false, "temperature": 0.1 } [2024-03-16 13:38:39.232] [INFO] [LM STUDIO SERVER] Context Overflow Policy is: Rolling Window [2024-03-16 13:38:39.232] [INFO] [LM STUDIO SERVER] Last message: { role: 'user', content: 'Sure!' } (total messages = 20) [2024-03-16 13:38:44.503] [INFO] [LM STUDIO SERVER] Accumulating tokens ... (stream = false) [2024-03-16 13:38:44.503] [INFO] Accumulated 1 tokens: I [2024-03-16 13:38:44.616] [INFO] Accumulated 2 tokens: I can [2024-03-16 13:38:44.724] [INFO] [LM STUDIO SERVER] Generated prediction: { "id": "chatcmpl-xig0l1xsebeguxn6udleo", "object": "chat.completion", "created": 1710567519, "model": "/Users/ac/.cache/lm-studio/models/TheBloke/zephyr-7B-alpha-GGUF/zephyr-7b-alpha.Q8_0.gguf", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "I can" }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 2, "completion_tokens": 2, "total_tokens": 4 } } [2024-03-16 13:45:57.679] [INFO] [LM STUDIO SERVER] Stopping server.. [2024-03-16 13:45:57.681] [INFO] [LM STUDIO SERVER] Server stopped [2024-03-16 14:03:03.542] [INFO] [LM STUDIO SERVER] Verbose server logs are ENABLED [2024-03-16 14:03:03.543] [INFO] [LM STUDIO SERVER] Heads up: you've enabled CORS. Make sure you understand the implications [2024-03-16 14:03:03.546] [INFO] [LM STUDIO SERVER] Success! HTTP server listening on port 1234 [2024-03-16 14:03:03.547] [INFO] [LM STUDIO SERVER] Supported endpoints: [2024-03-16 14:03:03.547] [INFO] [LM STUDIO SERVER] -> GET http://localhost:1234/v1/models [2024-03-16 14:03:03.547] [INFO] [LM STUDIO SERVER] -> POST http://localhost:1234/v1/chat/completions [2024-03-16 14:03:03.547] [INFO] [LM STUDIO SERVER] -> POST http://localhost:1234/v1/completions [2024-03-16 14:03:03.547] [INFO] [LM STUDIO SERVER] Logs are saved into /tmp/lmstudio-server-log.txt
I have resolved my previous error (above) by reverting to an older version of Autogen Studio.
As for the issue bug, I tried the solution as below: I've noticed an issue with the system message content being empty ("") and have implemented a fix for it. The issue was observed in the conversable_agent.py file at line 111. To ensure that the system message content is never empty, I've made the following changes:
# debug when system role's content=""
if system_message != "":
content = system_message
else:
content = "empty"
self._oai_system_message = [{"content": content, "role": "system"}]
With this update, we first check if system_message is not an empty string. If it's not, we assign system_message to content. If it is an empty string, we assign the string "empty" to content instead. This guarantees that the content field in self._oai_system_message will always have a non-empty value.
Let me know if there are any questions or further issues.
Seeing this bug in LM Studio 0.2.18 and AutoGen Studio v0.0.56
The same issue gets separated words
I just tested this for both Autogen Studio and Autogen (code) for version 0.2.20, and the response given by @victordibia is the correct response and the solution. There's really no change that's needed to the conversable_agent.py (this is optional). The reason is that you have to understand why the agent is sending the empty content. Using the "default_auto_reply" with a message like "am I still needed?" solves the issues and keeps the conversation flowing as expected. If you add "TERMINATE" in the auto reply it causes the agent to terminate the group chat and this could be done prematurely before the context of the PROBLEM is resolved or acknowledge by the roles. I hope this helps. There needs to be better clarity on the usage of the parameters. I would recommend closing it as both this and @victordibia response below as the answer.
https://github.com/microsoft/autogen/issues/1521#issuecomment-1965373353
user = autogen.UserProxyAgent( name="User", human_input_mode="NEVER", is_termination_msg=lambda x: x.get("content", "") and x.get("content", "").rstrip().endswith("TERMINATE"), default_auto_reply="Reply 'TERMINATE' in the end when everything is done. ", max_consecutive_auto_reply=5, code_execution_config={ "work_dir": "tasks", "use_docker": False, }, # Please set use_docker=True if docker is available to run the generated code. Using docker is safer than running the generated code directly. )In the example above, the default_auto_reply should be TERMINATE, not "Reply 'TERMINATE' in the end when everything is done. ". Next you should set the assistant is_termination_msg funtion to be
lambda x: x.get("content", "") and x.get("content", "").rstrip().endswith("TERMINATE"). What this does is that
- whenever the userproxy gets a message that has no code, it responds with "TERMINATE" to the assistant.
- the assistant receives the message "TERMINATE" and based on its
is_termination_msg, it ends the converation.
Hi, where should I insert this?
I am also observing this running autogen + local LMStudio server (model does not matter).
autogen: 0.2.35 LLStudio: 0.2.31
raise self._make_status_error_from_response(err.response) from None
openai.BadRequestError: Error code: 400 - {'error': "'messages' array must only contain objects with a 'content' field that is not empty."}
None of the listed workarounds work for me.
I just tested this for both Autogen Studio and Autogen (code) for version 0.2.20, and the response given by @victordibia is the correct response and the solution. There's really no change that's needed to the conversable_agent.py (this is optional). The reason is that you have to understand why the agent is sending the empty content. Using the "default_auto_reply" with a message like "am I still needed?" solves the issues and keeps the conversation flowing as expected. If you add "TERMINATE" in the auto reply it causes the agent to terminate the group chat and this could be done prematurely before the context of the PROBLEM is resolved or acknowledge by the roles. I hope this helps. There needs to be better clarity on the usage of the parameters. I would recommend closing it as both this and @victordibia response below as the answer.
That does not solve the issue at all.
Hi Folks, AutoGen Studio has seen some really significant updates - please try your code again with the latest release supporting AutoGen 0.4.5 or greater.