autogen icon indicating copy to clipboard operation
autogen copied to clipboard

AttributeError: 'str' object has no attribute 'get' after the task is finished

Open I4mCh40s opened this issue 3 years ago • 44 comments

Hi! First, thank you to all the devs who made autogen, it is so cool!

Unfortunately I have a persistent error (AttributeError: 'str' object has no attribute 'get')

It pops up sometimes before the Assistant is finished (when it writes python code for example), but when the task is primitive ( "come up with 5 possible names for SMMA that helps companies get leads") it manages to get it done and then spits out this error.

`user_proxy (to assistant):

come up with 5 possible names for SMMA that helps companies get leads


assistant (to user_proxy):

  1. Lead Generation Machine
  2. Lead Generator
  3. Sales Leads Machine
  4. Business Leads Generator
  5. Lead Finder

Traceback (most recent call last): File "c:\Users\ihasdslr\Documents\auto_gen\autogen_init.py", line 36, in user_proxy.initiate_chat( File "C:\Users\ihasdslr\anaconda3\envs\auto_gen\Lib\site-packages\autogen\agentchat\conversable_agent.py", line 531, in initiate_chat self.send(self.generate_init_message(**context), recipient, silent=silent) File "C:\Users\ihasdslr\anaconda3\envs\auto_gen\Lib\site-packages\autogen\agentchat\conversable_agent.py", line 334, in send recipient.receive(message, self, request_reply, silent) File "C:\Users\ihasdslr\anaconda3\envs\auto_gen\Lib\site-packages\autogen\agentchat\conversable_agent.py", line 464, in receive
self.send(reply, sender, silent=silent) File "C:\Users\ihasdslr\anaconda3\envs\auto_gen\Lib\site-packages\autogen\agentchat\conversable_agent.py", line 334, in send recipient.receive(message, self, request_reply, silent) File "C:\Users\ihasdslr\anaconda3\envs\auto_gen\Lib\site-packages\autogen\agentchat\conversable_agent.py", line 462, in receive reply = self.generate_reply(messages=self.chat_messages[sender], sender=sender) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ihasdslr\anaconda3\envs\auto_gen\Lib\site-packages\autogen\agentchat\conversable_agent.py", line 781, in generate_reply final, reply = reply_func(self, messages=messages, sender=sender, config=reply_func_tuple["config"]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ihasdslr\anaconda3\envs\auto_gen\Lib\site-packages\autogen\agentchat\conversable_agent.py", line 606, in generate_oai_reply response = oai.ChatCompletion.create( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ihasdslr\anaconda3\envs\auto_gen\Lib\site-packages\autogen\oai\completion.py", line 799, in create response = cls.create( ^^^^^^^^^^^ File "C:\Users\ihasdslr\anaconda3\envs\auto_gen\Lib\site-packages\autogen\oai\completion.py", line 830, in create return cls._get_response(params, raise_on_ratelimit_or_timeout=raise_on_ratelimit_or_timeout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ihasdslr\anaconda3\envs\auto_gen\Lib\site-packages\autogen\oai\completion.py", line 218, in _get_response response = openai_completion.create(**config) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ihasdslr\anaconda3\envs\auto_gen\Lib\site-packages\openai\api_resources\chat_completion.py", line 25, in create return super().create(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ihasdslr\anaconda3\envs\auto_gen\Lib\site-packages\openai\api_resources\abstract\engine_api_resource.py", line 155, in create response, _, api_key = requestor.request( ^^^^^^^^^^^^^^^^^^ File "C:\Users\ihasdslr\anaconda3\envs\auto_gen\Lib\site-packages\openai\api_requestor.py", line 299, in request resp, got_stream = self._interpret_response(result, stream) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ihasdslr\anaconda3\envs\auto_gen\Lib\site-packages\openai\api_requestor.py", line 710, in _interpret_response self._interpret_response_line( File "C:\Users\ihasdslr\anaconda3\envs\auto_gen\Lib\site-packages\openai\api_requestor.py", line 775, in _interpret_response_line raise self.handle_error_response( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ihasdslr\anaconda3\envs\auto_gen\Lib\site-packages\openai\api_requestor.py", line 428, in handle_error_response error_code=error_data.get("code"), ^^^^^^^^^^^^^^ AttributeError: 'str' object has no attribute 'get'`

I run the server with local LLMs via the LM studio. During this error my server logs say [ERROR] Error: 'messages' array must only contain objects with a 'content' field that is not empty.

pls help!

I4mCh40s avatar Oct 18 '23 10:10 I4mCh40s

Ihave the similar issue

CCMKCCMK avatar Oct 18 '23 15:10 CCMKCCMK

Try setting default_reply of UserProxyAgent to a non-empty str.

sonichi avatar Oct 18 '23 15:10 sonichi

Try setting default_reply of UserProxyAgent to a non-empty str.

Unfortunately still the same error:

Traceback (most recent call last):
  File "c:\Users\ihasdslr\Documents\auto_gen\autogen_init.py", line 37, in <module>
    user_proxy.initiate_chat(
  File "C:\Users\ihasdslr\anaconda3\envs\auto_gen\Lib\site-packages\autogen\agentchat\conversable_agent.py", line 531, in initiate_chat
    self.send(self.generate_init_message(**context), recipient, silent=silent)
  File "C:\Users\ihasdslr\anaconda3\envs\auto_gen\Lib\site-packages\autogen\agentchat\conversable_agent.py", line 334, in send
    recipient.receive(message, self, request_reply, silent)
  File "C:\Users\ihasdslr\anaconda3\envs\auto_gen\Lib\site-packages\autogen\agentchat\conversable_agent.py", line 464, in receive
    self.send(reply, sender, silent=silent)
  File "C:\Users\ihasdslr\anaconda3\envs\auto_gen\Lib\site-packages\autogen\agentchat\conversable_agent.py", line 334, in send
    recipient.receive(message, self, request_reply, silent)
  File "C:\Users\ihasdslr\anaconda3\envs\auto_gen\Lib\site-packages\autogen\agentchat\conversable_agent.py", line 462, in receive
    reply = self.generate_reply(messages=self.chat_messages[sender], sender=sender)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ihasdslr\anaconda3\envs\auto_gen\Lib\site-packages\autogen\agentchat\conversable_agent.py", line 781, in generate_reply
    final, reply = reply_func(self, messages=messages, sender=sender, config=reply_func_tuple["config"])
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ihasdslr\anaconda3\envs\auto_gen\Lib\site-packages\autogen\agentchat\conversable_agent.py", line 606, in generate_oai_reply
    response = oai.ChatCompletion.create(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ihasdslr\anaconda3\envs\auto_gen\Lib\site-packages\autogen\oai\completion.py", line 799, in create
    response = cls.create(
               ^^^^^^^^^^^
  File "C:\Users\ihasdslr\anaconda3\envs\auto_gen\Lib\site-packages\autogen\oai\completion.py", line 830, in create
    return cls._get_response(params, raise_on_ratelimit_or_timeout=raise_on_ratelimit_or_timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ihasdslr\anaconda3\envs\auto_gen\Lib\site-packages\autogen\oai\completion.py", line 218, in _get_response
    response = openai_completion.create(**config)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ihasdslr\anaconda3\envs\auto_gen\Lib\site-packages\openai\api_resources\chat_completion.py", line 25, in create
    return super().create(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ihasdslr\anaconda3\envs\auto_gen\Lib\site-packages\openai\api_resources\abstract\engine_api_resource.py", line 155, in create
    response, _, api_key = requestor.request(
                           ^^^^^^^^^^^^^^^^^^
  File "C:\Users\ihasdslr\anaconda3\envs\auto_gen\Lib\site-packages\openai\api_requestor.py", line 299, in request
    resp, got_stream = self._interpret_response(result, stream)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ihasdslr\anaconda3\envs\auto_gen\Lib\site-packages\openai\api_requestor.py", line 710, in _interpret_response
    self._interpret_response_line(
  File "C:\Users\ihasdslr\anaconda3\envs\auto_gen\Lib\site-packages\openai\api_requestor.py", line 775, in _interpret_response_line
    raise self.handle_error_response(
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ihasdslr\anaconda3\envs\auto_gen\Lib\site-packages\openai\api_requestor.py", line 428, in handle_error_response
    error_code=error_data.get("code"),
               ^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'get'

My current UserProxy definition now looks like this:

user_proxy = autogen.UserProxyAgent(
    name="user_proxy",
    human_input_mode="NEVER",
    default_auto_reply="default_auto_reply",
    max_consecutive_auto_reply=10,
    code_execution_config={"work_dir": "result"},
    llm_config=llm_config,
)

I4mCh40s avatar Oct 18 '23 15:10 I4mCh40s

Do you intend for the user proxy agent to use llm-based reply? If not, please remove llm_config from its constructor.

sonichi avatar Oct 18 '23 20:10 sonichi

Do you intend for the user proxy agent to use llm-based reply? If not, please remove llm_config from its constructor.

Thanks so much for the help! It worked! Both assistants are now in an infinite loop sending the same code to each other :D But the error is gone. Thank you!

I4mCh40s avatar Oct 18 '23 20:10 I4mCh40s

The user proxy agent is not supposed to send code. It will use default_auto_reply when no code is in the received msg.

sonichi avatar Oct 18 '23 21:10 sonichi

Ihave the similar issue

Same.

From the API I get the error:

[ERROR] Error: 'messages' array must only contain objects with a 'content' field that is not empty.

And I can see that the repsonse contains multiple content fields which are empty:

, { "content": "```", "role": "user", "name": "Planner" }, { "content": "", "role": "user", "name": "Executor" }, { "role": "system", "content": "Read the above conversation. Then select the next role from ['Admin', 'Engineer', 'Planner', 'Executor', 'Critic'] to play. Only return the role." }

stefan-wiesner avatar Oct 19 '23 13:10 stefan-wiesner

I'm getting this error trying to run the official example for visualizations with no substantial code changes. example

The only difference is that I'm using an LLM running on the local network rather than OAI. config_list_gpt4 = [ { "api_type": "open_ai", "api_base": "http://###.###.##.##:1234/v1", "api_key": "NULL" } ]

The LLM is receiving requests and returning results. This error seems to hit after the first cycle through the group.

Terristen avatar Oct 20 '23 21:10 Terristen

Same reason as I said above. The local LLM doesn't allow empty content. The workaround is to set default_auto_reply to a non empty str.

sonichi avatar Oct 20 '23 23:10 sonichi

can you write example? im new at this lol

POWERFULMOVES avatar Oct 21 '23 12:10 POWERFULMOVES

heres what i got rom autogen import AssistantAgent, UserProxyAgent

Load LLM inference endpoints from an env variable or a file

See https://microsoft.github.io/autogen/docs/FAQ#set-your-api-endpoints

and OAI_CONFIG_LIST_sample

config_list = [ { "api_type": "openai", "api_base": "http://localhost:5001/v1", "api_key": "NULL", } ]

llm_config={ "request_timeout": 600, 'seed': 42, "config_list": config_list, "temperature": 0 }

assistant = AssistantAgent( name="assistant", llm_config=llm_config ) user_proxy = UserProxyAgent( name="User_proxy", human_input_mode="TERMINATE", max_consecutive_auto_reply=10, is_termination_msg=lambda x: x.get("content","").rstrip().endswith("TERMINATE"), code_execution_config={"work_dir": "web"}, system_message="""Reply TERMINATE if the task has been solved at full satisfaction. Otherwise, reply CONTINUE, or the reason why the task is not solved yet.""" )

task = """ plot the stock price of apple for the past 5 days using python """

user_proxy.initiate_chat( assistant, message=task )

POWERFULMOVES avatar Oct 21 '23 12:10 POWERFULMOVES

@POWERFULMOVES You can add llm_config=llm_config in the constructor of UserProxyAgent if you intend to use llm-based reply for the UserProxyAgent.

sonichi avatar Oct 21 '23 13:10 sonichi

This is a string error. There's something completely wrong with the line: is_termination_msg=lambda x: x.get("content", "").rstrip().endswith("TERMINATE"),

MikeyBeez avatar Oct 21 '23 17:10 MikeyBeez

import json and do this: # create a UserProxyAgent instance named "user_proxy" user_proxy = autogen.UserProxyAgent( name="user_proxy", human_input_mode="NEVER", max_consecutive_auto_reply=100, default_auto_reply="default_auto_reply",

is_termination_msg = lambda x: (

False if x.get("content") is None else

x.get("content", "").rstrip().endswith("TERMINATE")

if isinstance(x.get("content"), str) else

False

),

is_termination_msg = lambda x: (
False if x.get("content") is None else
x.get("content", "").rstrip().endswith("TERMINATE")
if isinstance(json.loads(x.get("content")), dict) else
False
),

code_execution_config={
    "work_dir": "coding",
    "use_docker": True,  # set to True or image name like "python:3" to use docker
},

)

autogen.ChatCompletion.start_logging()

research_problem_to_solve = { "sender": "user", "content": json.dumps({ "text": "Get YTD returns for the top 5 performing stocks and plot their prices" }) }

MikeyBeez avatar Oct 21 '23 18:10 MikeyBeez

This seems to work, although I'm getting a new error. I'm running LM Studio with a local server: raise error.Timeout("Request timed out: {}".format(e)) from e openai.error.Timeout: Request timed out: HTTPConnectionPool(host='localhost', port=1234): Read timed out. (read timeout=60) In any case, I think I've stopped getting the str error.

MikeyBeez avatar Oct 21 '23 18:10 MikeyBeez

For timeout error, check https://microsoft.github.io/autogen/docs/FAQ#handle-rate-limit-error-and-timeout-error

If anyone is interested in adding the workaround about the str error to the FAQ page, please feel free to make a PR.

sonichi avatar Oct 22 '23 15:10 sonichi

Thanks. I found the trick is to lower the retry_wait_time and raise the others. And the str problem can be fixed by doing a json load of the message. Cheers.

On Oct 22, 2023, at 10:32 AM, Chi Wang @.***> wrote:

For timeout error, check https://microsoft.github.io/autogen/docs/FAQ#handle-rate-limit-error-and-timeout-error

If anyone is interested in adding the workaround about the str error to the FAQ page, please feel free to make a PR.

— Reply to this email directly, view it on GitHub https://github.com/microsoft/autogen/issues/279#issuecomment-1774124649, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADM2NQCPQPNKQUWBSP2KVY3YAU4B3AVCNFSM6AAAAAA6FIRYN6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZUGEZDINRUHE. You are receiving this because you commented.

MikeyBeez avatar Oct 22 '23 16:10 MikeyBeez

Problem is still occurring on my end. @MikeyBeez I tried your suggestion to no avail. I'm hoping some sort of clever prompting could force a response, but I haven't had any success. My script utilizes 10 agents though it seems to be random that an agent simply doesn't give a response.

AutoChedda avatar Oct 23 '23 04:10 AutoChedda

Same here, getting that all the time with local LLMs

latao3450 avatar Oct 23 '23 04:10 latao3450

Did either of you get JSON errors when you switched to JSON? I had to switch back to strings, but then got 'get' errors.

e404nothing avatar Oct 23 '23 13:10 e404nothing