agent-zero icon indicating copy to clipboard operation
agent-zero copied to clipboard

litellm.exceptions.APIConnectionError: litellm.APIConnect...

Open asb-42 opened this issue 5 months ago • 4 comments

After installing A0 2.0 with the one liner (curl -fsSL https://bash.agent-zero.ai | bash):

litellm.exceptions.APIConnectionError: litellm.APIConnectionError: APIConnectionError: DeepseekException - Missing dependency No module named 'fastapi'. Run `pip install 'litellm[proxy]'`

Traceback (most recent call last):
Traceback (most recent call last):
  File "/opt/venv-a0/lib/python3.12/site-packages/litellm/proxy/proxy_server.py", line 158, in <module>
    import fastapi
ModuleNotFoundError: No module named 'fastapi'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/venv-a0/lib/python3.12/site-packages/litellm/responses/main.py", line 559, in aresponses
    response = await init_response
               ^^^^^^^^^^^^^^^^^^^
  File "/opt/venv-a0/lib/python3.12/site-packages/litellm/responses/litellm_completion_transformation/handler.py", line 106, in async_response_api_handler
    litellm_completion_request = await LiteLLMCompletionResponsesConfig.async_responses_api_session_handler(
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv-a0/lib/python3.12/site-packages/litellm/responses/litellm_completion_transformation/transformation.py", line 299, in async_responses_api_session_handler
    chat_completion_session = await ResponsesSessionHandler.get_chat_completion_message_history_for_previous_response_id(
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv-a0/lib/python3.12/site-packages/litellm/responses/litellm_completion_transformation/session_handler.py", line 47, in get_chat_completion_message_history_for_previous_response_id
    await ResponsesSessionHandler.get_all_spend_logs_for_previous_response_id(
  File "/opt/venv-a0/lib/python3.12/site-packages/litellm/responses/litellm_completion_transformation/session_handler.py", line 280, in get_all_spend_logs_for_previous_response_id
    from litellm.proxy.proxy_server import prisma_client
  File "/opt/venv-a0/lib/python3.12/site-packages/litellm/proxy/proxy_server.py", line 163, in <module>
    raise ImportError(f"Missing dependency {e}. Run `pip install 'litellm[proxy]'`")
ImportError: Missing dependency No module named 'fastapi'. Run `pip install 'litellm[proxy]'`

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/a0/helpers/extension.py", line 176, in _run_async
    data["result"] = await data["result"]
                     ^^^^^^^^^^^^^^^^^^^^
  File "/a0/agent.py", line 645, in handle_exception
    raise exception # exception handling is done by extensions
    ^^^^^^^^^^^^^^^
  File "/a0/agent.py", line 485, in monologue
    llm_result = await self.call_chat_model_turn(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/a0/helpers/extension.py", line 183, in _run_async
    result = _process_result(data)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/a0/helpers/extension.py", line 143, in _process_result
    raise exc
  File "/a0/helpers/extension.py", line 176, in _run_async
    data["result"] = await data["result"]
                     ^^^^^^^^^^^^^^^^^^^^
  File "/a0/agent.py", line 973, in call_chat_model_turn
    llm_result = await call_data["model"].unified_turn(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/a0/models.py", line 702, in unified_turn
    async for parsed in transport.astream():
  File "/a0/helpers/litellm_transport.py", line 305, in astream
    iterator = await aresponses(**request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv-a0/lib/python3.12/site-packages/litellm/utils.py", line 2100, in wrapper_async
    raise e
  File "/opt/venv-a0/lib/python3.12/site-packages/litellm/utils.py", line 1899, in wrapper_async
    result = await original_function(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv-a0/lib/python3.12/site-packages/litellm/responses/main.py", line 581, in aresponses
    raise litellm.exception_type(
          ^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv-a0/lib/python3.12/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 2471, in exception_type
    raise e  # it's already mapped
    ^^^^^^^
  File "/opt/venv-a0/lib/python3.12/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 644, in exception_type
    raise APIConnectionError(

This error persists upgrading from 2.0 to 2.1.

Workaround candidates:

pip install 'litellm[proxy]'

and/or

docker exec -it agent-zero pip install 'litellm[proxy]'

and/or

litellm[proxy] (in requirements.txt and/or in docker file).

No idea if that will break even more, haven't tried it yet.

asb-42 avatar Jun 26 '26 18:06 asb-42

Just to add some clarity for anyone running into this: the workaround of installing fastapi or litellm[proxy] only fixes the asynchronous logging crash (Task was destroyed but it is pending).

However, if you are using MiniMax as your LLM provider on AgentZero v2.0+, the agent will still immediately loop and crash with a 400 Bad Request: invalid params, tool result's tool id(...) not found (2013), code: invalid_prompt

This happens because AgentZero v2.0+ switched to native OpenAI-style Function Calling. When LiteLLM maps the tool messages back to the MiniMax API, the strict message history sequence required by MiniMax gets broken, leading to the 2013 error code.

Conclusion: Upgrading litellm to the latest version (1.89.4) inside the container does not fix this yet. The underlying issue is a structural incompatibility in how LiteLLM formats tool calls for MiniMax.

If you need to use AgentZero v2.1 right now with tools/knowledge files, the only real solution is to switch the backend model to a fully compliant provider (like native OpenAI).

gianvitoferrara avatar Jun 27 '26 01:06 gianvitoferrara

Nope, not Minimax but Deepseek.

After enforcing litellm with docker exec -it agent-zero /opt/venv-a0/bin/pip install 'litellm[proxy]':

litellm.exceptions.BadRequestError: litellm.BadRequestErr...
litellm.exceptions.BadRequestError: litellm.BadRequestError: DeepseekException - {"error":{"message":"Messages with role 'tool' must be a response to a preceding message with 'tool_calls'","type":"invalid_request_error","param":null,"code":"invalid_request_error"}}

Traceback (most recent call last):
Traceback (most recent call last):
  File "/[opt](http://localhost:5080/#)/[venv-a0](http://localhost:5080/#)/[lib](http://localhost:5080/#)/[python3.12](http://localhost:5080/#)/[site-packages](http://localhost:5080/#)/[litellm](http://localhost:5080/#)/[llms](http://localhost:5080/#)/[custom_httpx](http://localhost:5080/#)/[llm_http_handler.py](http://localhost:5080/#)", line 205, in _make_common_async_call
    response = await async_httpx_client.post(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/[opt](http://localhost:5080/#)/[venv-a0](http://localhost:5080/#)/[lib](http://localhost:5080/#)/[python3.12](http://localhost:5080/#)/[site-packages](http://localhost:5080/#)/[litellm](http://localhost:5080/#)/[litellm_core_utils](http://localhost:5080/#)/[logging_utils.py](http://localhost:5080/#)", line 297, in async_wrapper
    result = await func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/[opt](http://localhost:5080/#)/[venv-a0](http://localhost:5080/#)/[lib](http://localhost:5080/#)/[python3.12](http://localhost:5080/#)/[site-packages](http://localhost:5080/#)/[litellm](http://localhost:5080/#)/[llms](http://localhost:5080/#)/[custom_httpx](http://localhost:5080/#)/[http_handler.py](http://localhost:5080/#)", line 677, in post
    await _raise_masked_async_error(e, stream)
  File "/[opt](http://localhost:5080/#)/[venv-a0](http://localhost:5080/#)/[lib](http://localhost:5080/#)/[python3.12](http://localhost:5080/#)/[site-packages](http://localhost:5080/#)/[litellm](http://localhost:5080/#)/[llms](http://localhost:5080/#)/[custom_httpx](http://localhost:5080/#)/[http_handler.py](http://localhost:5080/#)", line 454, in _raise_masked_async_error
    raise MaskedHTTPStatusError(e, message=_body, text=_body) from None
litellm.llms.custom_httpx.http_handler.MaskedHTTPStatusError: Client error '400 Bad Request' for url 'https://api.deepseek.com/chat/completions'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/[opt](http://localhost:5080/#)/[venv-a0](http://localhost:5080/#)/[lib](http://localhost:5080/#)/[python3.12](http://localhost:5080/#)/[site-packages](http://localhost:5080/#)/[litellm](http://localhost:5080/#)/[main.py](http://localhost:5080/#)", line 637, in acompletion
    response = await init_response
               ^^^^^^^^^^^^^^^^^^^
  File "/[opt](http://localhost:5080/#)/[venv-a0](http://localhost:5080/#)/[lib](http://localhost:5080/#)/[python3.12](http://localhost:5080/#)/[site-packages](http://localhost:5080/#)/[litellm](http://localhost:5080/#)/[llms](http://localhost:5080/#)/[custom_httpx](http://localhost:5080/#)/[llm_http_handler.py](http://localhost:5080/#)", line 723, in acompletion_stream_function
    completion_stream, _response_headers = await self.make_async_call_stream_helper(
                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/[opt](http://localhost:5080/#)/[venv-a0](http://localhost:5080/#)/[lib](http://localhost:5080/#)/[python3.12](http://localhost:5080/#)/[site-packages](http://localhost:5080/#)/[litellm](http://localhost:5080/#)/[llms](http://localhost:5080/#)/[custom_httpx](http://localhost:5080/#)/[llm_http_handler.py](http://localhost:5080/#)", line 782, in make_async_call_stream_helper
    response = await self._make_common_async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/[opt](http://localhost:5080/#)/[venv-a0](http://localhost:5080/#)/[lib](http://localhost:5080/#)/[python3.12](http://localhost:5080/#)/[site-packages](http://localhost:5080/#)/[litellm](http://localhost:5080/#)/[llms](http://localhost:5080/#)/[custom_httpx](http://localhost:5080/#)/[llm_http_handler.py](http://localhost:5080/#)", line 230, in _make_common_async_call
    raise self._handle_error(e=e, provider_config=provider_config)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/[opt](http://localhost:5080/#)/[venv-a0](http://localhost:5080/#)/[lib](http://localhost:5080/#)/[python3.12](http://localhost:5080/#)/[site-packages](http://localhost:5080/#)/[litellm](http://localhost:5080/#)/[llms](http://localhost:5080/#)/[custom_httpx](http://localhost:5080/#)/[llm_http_handler.py](http://localhost:5080/#)", line 5252, in _handle_error
    raise provider_config.get_error_class(
litellm.llms.openai.common_utils.OpenAIError: {"error":{"message":"Messages with role 'tool' must be a response to a preceding message with 'tool_calls'","type":"invalid_request_error","param":null,"code":"invalid_request_error"}}

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/[a0](http://localhost:5080/#)/[helpers](http://localhost:5080/#)/[extension.py](http://localhost:5080/#)", line 176, in _run_async
    data["result"] = await data["result"]
                     ^^^^^^^^^^^^^^^^^^^^
  File "/[a0](http://localhost:5080/#)/[agent.py](http://localhost:5080/#)", line 645, in handle_exception
    raise exception # exception handling is done by extensions
    ^^^^^^^^^^^^^^^
  File "/[a0](http://localhost:5080/#)/[agent.py](http://localhost:5080/#)", line 485, in monologue
    llm_result = await self.call_chat_model_turn(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/[a0](http://localhost:5080/#)/[helpers](http://localhost:5080/#)/[extension.py](http://localhost:5080/#)", line 183, in _run_async
    result = _process_result(data)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/[a0](http://localhost:5080/#)/[helpers](http://localhost:5080/#)/[extension.py](http://localhost:5080/#)", line 143, in _process_result
    raise exc
  File "/[a0](http://localhost:5080/#)/[helpers](http://localhost:5080/#)/[extension.py](http://localhost:5080/#)", line 176, in _run_async
    data["result"] = await data["result"]
                     ^^^^^^^^^^^^^^^^^^^^
  File "/[a0](http://localhost:5080/#)/[agent.py](http://localhost:5080/#)", line 973, in call_chat_model_turn
    llm_result = await call_data["model"].unified_turn(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/[a0](http://localhost:5080/#)/[models.py](http://localhost:5080/#)", line 702, in unified_turn
    async for parsed in transport.astream():
  File "/[a0](http://localhost:5080/#)/[helpers](http://localhost:5080/#)/[litellm_transport.py](http://localhost:5080/#)", line 305, in astream
    iterator = await aresponses(**request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/[opt](http://localhost:5080/#)/[venv-a0](http://localhost:5080/#)/[lib](http://localhost:5080/#)/[python3.12](http://localhost:5080/#)/[site-packages](http://localhost:5080/#)/[litellm](http://localhost:5080/#)/[utils.py](http://localhost:5080/#)", line 2100, in wrapper_async
    raise e
  File "/[opt](http://localhost:5080/#)/[venv-a0](http://localhost:5080/#)/[lib](http://localhost:5080/#)/[python3.12](http://localhost:5080/#)/[site-packages](http://localhost:5080/#)/[litellm](http://localhost:5080/#)/[utils.py](http://localhost:5080/#)", line 1899, in wrapper_async
    result = await original_function(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/[opt](http://localhost:5080/#)/[venv-a0](http://localhost:5080/#)/[lib](http://localhost:5080/#)/[python3.12](http://localhost:5080/#)/[site-packages](http://localhost:5080/#)/[litellm](http://localhost:5080/#)/[responses](http://localhost:5080/#)/[main.py](http://localhost:5080/#)", line 581, in aresponses
    raise litellm.exception_type(
  File "/[opt](http://localhost:5080/#)/[venv-a0](http://localhost:5080/#)/[lib](http://localhost:5080/#)/[python3.12](http://localhost:5080/#)/[site-packages](http://localhost:5080/#)/[litellm](http://localhost:5080/#)/[responses](http://localhost:5080/#)/[main.py](http://localhost:5080/#)", line 559, in aresponses
    response = await init_response
               ^^^^^^^^^^^^^^^^^^^
  File "/[opt](http://localhost:5080/#)/[venv-a0](http://localhost:5080/#)/[lib](http://localhost:5080/#)/[python3.12](http://localhost:5080/#)/[site-packages](http://localhost:5080/#)/[litellm](http://localhost:5080/#)/[responses](http://localhost:5080/#)/[litellm_completion_transformation](http://localhost:5080/#)/[handler.py](http://localhost:5080/#)", line 117, in async_response_api_handler
    ] = await litellm.acompletion(
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/[opt](http://localhost:5080/#)/[venv-a0](http://localhost:5080/#)/[lib](http://localhost:5080/#)/[python3.12](http://localhost:5080/#)/[site-packages](http://localhost:5080/#)/[litellm](http://localhost:5080/#)/[utils.py](http://localhost:5080/#)", line 2100, in wrapper_async
    raise e
  File "/[opt](http://localhost:5080/#)/[venv-a0](http://localhost:5080/#)/[lib](http://localhost:5080/#)/[python3.12](http://localhost:5080/#)/[site-packages](http://localhost:5080/#)/[litellm](http://localhost:5080/#)/[utils.py](http://localhost:5080/#)", line 1899, in wrapper_async
    result = await original_function(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/[opt](http://localhost:5080/#)/[venv-a0](http://localhost:5080/#)/[lib](http://localhost:5080/#)/[python3.12](http://localhost:5080/#)/[site-packages](http://localhost:5080/#)/[litellm](http://localhost:5080/#)/[main.py](http://localhost:5080/#)", line 656, in acompletion
    raise exception_type(
          ^^^^^^^^^^^^^^^
  File "/[opt](http://localhost:5080/#)/[venv-a0](http://localhost:5080/#)/[lib](http://localhost:5080/#)/[python3.12](http://localhost:5080/#)/[site-packages](http://localhost:5080/#)/[litellm](http://localhost:5080/#)/[litellm_core_utils](http://localhost:5080/#)/[exception_mapping_utils.py](http://localhost:5080/#)", line 2466, in exception_type
    raise e
  File "/[opt](http://localhost:5080/#)/[venv-a0](http://localhost:5080/#)/[lib](http://localhost:5080/#)/[python3.12](http://localhost:5080/#)/[site-packages](http://localhost:5080/#)/[litellm](http://localhost:5080/#)/[litellm_core_utils](http://localhost:5080/#)/[exception_mapping_utils.py](http://localhost:5080/#)", line 487, in exception_type
    raise BadRequestError(

asb-42 avatar Jun 27 '26 03:06 asb-42

Issue was gone two days ago, now it is back since yesterday (Deepseek v4 Pro, via Deepseek API).

asb-42 avatar Jul 02 '26 04:07 asb-42

Fixed in 2.3, closing.

asb-42 avatar Jul 10 '26 19:07 asb-42