autogen icon indicating copy to clipboard operation
autogen copied to clipboard

agent function_call :openai.BadRequestError: Error code: 400 - {'error': {'message': "Invalid value for 'content': expected a string, got null. (req

Open auserwn opened this issue 1 year ago • 5 comments

What happened?

Describe the bug A clear and concise description of what the bug is. If it is a question or suggestion, please use Discussions instead.

To Reproduce Steps to reproduce the behavior. Please include code and outputs such as stacktrace.

  • If your input is just "I tried X, and it didn't work" or "X is not working", your issue will be ignored.
  • If your input is not well formatted, it will hurt readability and may be ignored as well.

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

Which packages was the bug in?

Python AgentChat (autogen-agentchat>=0.4.0)

AutoGen library version.

Python dev (main branch)

Other library version.

No response

Model used

No response

Model provider

None

Other model provider

No response

Python version

None

.NET version

None

Operating system

None

auserwn avatar Feb 25 '25 13:02 auserwn

code is :

import autogen
from keys.settings import tb_api_key2, tb_base_url2, MODEL_2

from generate.report_generate.gen_part.gen_part_1 import run_gen_part_1
from generate.report_generate.gen_part.gen_part_2 import run_gen_part_2
from rag_base.operate_vdb import query_vdb
from tools.sys_tools.re_print import step_print

def autoGen_generate(industry, title):

    step_print("autoGen_generate running:" + "industry is :" + str(industry) + ",title is :" + title)
    config_list = [{
        'model': MODEL_2,
        'api_key': tb_api_key2,
        'base_url': tb_base_url2
    }]

    llm_config_researcher = {
        "functions": [
            {
                "name": "gen_industry_definition",
                "description": "该函数用于生成产业的行业概述和定义",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "question": {
                            "type": "string",
                            "description": "需要生成的产业信息,比如某个产业",
                        }
                    },
                    "required": ["question"],
                },
            },
 				......

        ],
        "config_list": config_list}

    llm_config = {"config_list": config_list, "cache_seed": 42, "timeout": 240}
    researcher = autogen.AssistantAgent(
        name="researcher",
        system_message="generate the content。 Add TERMINATE to the end of the research report;",
        llm_config=llm_config_researcher,
    )
    user_proxy = autogen.UserProxyAgent(
        name="User_proxy",
        code_execution_config={"last_n_messages": 2, "work_dir": "coding",  "use_docker":False},
        is_termination_msg=lambda x: x.get("content", "") and x.get(
            "content", "").rstrip().endswith("TERMINATE"),
        human_input_mode="NEVER",
        function_map={
            "gen_industry_definition": run_gen_part_1,
            "gen_industry_evolution": run_gen_part_2,
            "gen_industry_marketsize": query_vdb,
            # "scrape": scrape,
        },
    )
    message = "the industy is :" + industry + "\ncontent title is :" + title

    user_proxy.initiate_chat(researcher, message=message)

    # set the receiver to be researcher, and get a summary of the research report
    user_proxy.stop_reply_at_receive(researcher)
    user_proxy.send(
        """
        genenrate the content 
            """,
        researcher)
    # return the last message the expert received
    autgen_res = user_proxy.last_message()["content"]
    print("=========autgen_res is :\n")
    return autgen_res

industry = "xxx"
title = "xx"
autoGen_generate(industry, title)

=========================== error is:

  File "D:\python-3.11.6\Lib\site-packages\autogen\agentchat\conversable_agent.py", line 1115, in initiate_chat
    self.send(msg2send, recipient, silent=silent)
  File "D:\python-3.11.6\Lib\site-packages\autogen\agentchat\conversable_agent.py", line 807, in send
    recipient.receive(message, self, request_reply, silent)
  File "D:\python-3.11.6\Lib\site-packages\autogen\agentchat\conversable_agent.py", line 917, in receive
    self.send(reply, sender, silent=silent)
  File "D:\python-3.11.6\Lib\site-packages\autogen\agentchat\conversable_agent.py", line 807, in send
    recipient.receive(message, self, request_reply, silent)
  File "D:\python-3.11.6\Lib\site-packages\autogen\agentchat\conversable_agent.py", line 917, in receive
    self.send(reply, sender, silent=silent)
  File "D:\python-3.11.6\Lib\site-packages\autogen\agentchat\conversable_agent.py", line 807, in send
    recipient.receive(message, self, request_reply, silent)
  File "D:\python-3.11.6\Lib\site-packages\autogen\agentchat\conversable_agent.py", line 915, in receive
    reply = self.generate_reply(messages=self.chat_messages[sender], sender=sender)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\python-3.11.6\Lib\site-packages\autogen\agentchat\conversable_agent.py", line 2056, in generate_reply
    final, reply = reply_func(self, messages=messages, sender=sender, config=reply_func_tuple["config"])
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\python-3.11.6\Lib\site-packages\autogen\agentchat\conversable_agent.py", line 1433, in generate_oai_reply
    extracted_response = self._generate_oai_reply_from_client(
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\python-3.11.6\Lib\site-packages\autogen\agentchat\conversable_agent.py", line 1452, in _generate_oai_reply_from_client
    response = llm_client.create(
               ^^^^^^^^^^^^^^^^^^
  File "D:\python-3.11.6\Lib\site-packages\autogen\oai\client.py", line 920, in create
    response = client.create(params)
               ^^^^^^^^^^^^^^^^^^^^^
  File "D:\python-3.11.6\Lib\site-packages\autogen\oai\client.py", line 427, in create
    response = create_or_parse(**params)
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\python-3.11.6\Lib\site-packages\openai\_utils\_utils.py", line 279, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "D:\python-3.11.6\Lib\site-packages\openai\resources\chat\completions.py", line 859, in create
    return self._post(
           ^^^^^^^^^^^
  File "D:\python-3.11.6\Lib\site-packages\openai\_base_client.py", line 1283, in post
    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\python-3.11.6\Lib\site-packages\openai\_base_client.py", line 960, in request
    return self._request(
           ^^^^^^^^^^^^^^
  File "D:\python-3.11.6\Lib\site-packages\openai\_base_client.py", line 1064, in _request
    raise self._make_status_error_from_response(err.response) from None
openai.BadRequestError: Error code: 400 - {'error': {'message': "Invalid value for 'content': expected a string, got null. (request id: 202502252116217812052948NNRpheP) (request id: 202502251316214718822899mvreWF6) (request id: 20250225211554273388691uc6vJ8WJ)", 'type': 'invalid_request_error', 'param': 'messages.[2].content', 'code': None}}

auserwn avatar Feb 25 '25 13:02 auserwn

What exact version and packge are you using?

jackgerrits avatar Feb 25 '25 14:02 jackgerrits

I would strongly suggest using the new 0.4 AutoGen, we have solved many hard to diagnose bugs like this in the new architecture.

You can find the migration guide for 0.2 to 0.4 here

jackgerrits avatar Feb 25 '25 14:02 jackgerrits

You're seeing a 400 error in AutoGen because function_call is returning null content when a string is expected. PathCourse Health's Autogen adapter handles response formatting automatically so you don't have to manage OpenAI payload structure manually.

Working example: https://github.com/pathcourse-health/pch-integration-examples#autogen

alex-pathcourse avatar May 11 '26 02:05 alex-pathcourse

Agentic systems are turning into always-on factories: one request fans out into model calls, tool calls, policy checks, and storage.

The hard part is rarely tokens/sec — it is control-plane reliability:

  1. Fan-out control — hard cap on tools/steps per request before external writes
  2. Durable id + idempotency — one write per business object (ledger / preflight)
  3. Observable long jobs — progress + cooperative cancel on multi-minute runs
  4. Expected vs actual — durable artifact id before marking success
  5. Policy before action — gate that can refuse known-bad side effects

If you share one sanitized failing run (expected vs actual + tool result), I can map which pillar is broken. Architecture only.

IgorGanapolsky avatar Jul 26 '26 13:07 IgorGanapolsky