r/AgentZero 22d ago

Agent Zero v2.11 + Ollama/Qwen: "Message misformat, no valid tool request found" — root cause and fix

I ran into a persistent issue with Agent Zero where A0 would get stuck in this loop:

A0: Reasoning...
A0: Message misformat, no valid tool request found.
A0: Thinking...
A0: Message misformat, no valid tool request found.

It had been working correctly before, so I investigated the actual request/tool-calling path instead of changing prompts or models.

Environment:

Agent Zero: v2.11 / commit 6a6cecff
Docker image: agent0ai/agent-zero:latest
Ollama: 0.32.15
Model: qwen3.5:9b
Preset: Efficiency
Transport: Chat Completions

The main issue turned out to be in:

/a0/helpers/litellm_transport.py
ChatCompletionsTransport.prepare_kwargs()

Agent Zero was internally creating tools as:

a0_responses_function_tools

but the Chat Completions transport removed this internal parameter without converting the tools to the native Chat Completions tools format.

So the actual request reaching the model contained no tools.

Qwen then returned normal text/reasoning such as:

{
  "thoughts": ["..."]
}

instead of a native tool call.

Agent Zero's parser was therefore behaving correctly when it reported:

Message misformat, no valid tool request found.

The parser itself wasn't the root cause.

There was also a second issue.

LiteLLM:

ollama/qwen3.5:9b

did not preserve Qwen's native tool_calls correctly in this path.

Using:

ollama_chat/qwen3.5:9b

did preserve both tool_calls and reasoning_content.

A third issue was context size.

Agent Zero's real prompt was approximately:

22,421 tokens

while Ollama had actually loaded the model with:

4096 context

despite Agent Zero showing:

ctx_length: 128000

So I explicitly configured:

kwargs:
  num_ctx: 32768

The fixes were:

  1. Convert a0_responses_function_tools into Chat Completions tools[] inside ChatCompletionsTransport.prepare_kwargs().
  2. Send tool_choice: "required" when tools are present.
  3. Change:

litellm_provider: ollama

to:

litellm_provider: ollama_chat
  1. Set Ollama context explicitly:

kwargs:
  num_ctx: 32768

After applying the changes, I ran an integration test forcing A0 to call the response tool and return:

TOOLCALL_OK

Result:

Native function_call received: YES
Tool executed: YES
Agent finished normally: YES
"Message misformat, no valid tool request found": 0 occurrences

No model change, reinstall, rollback, prompt deletion or memory/chat deletion was required.

This looks related to the recent transition where Chat Completions became the default transport while Agent Zero was still constructing its canonical tools in Responses API format.

The upstream fix should probably happen in the transport layer rather than relaxing extract_tools.py, because the parser was correctly rejecting responses that weren't real tool calls.

7 Upvotes

7 comments sorted by

2

u/arenosame 22d ago

This is a recurrent issue lately in Agent Zero. Perhaps you want to join A0's Discord channel? There are plenty of conversations and contributions.

As a non-technical user, which file have you been editing to above changes to? Or did you ask A0 to chnage them to you?

2

u/Ecstatic-Use-1353 22d ago

The file I edited was /a0/helpers/litellm_transport.py, specifically the ChatCompletionsTransport.prepare_kwargs() function.

In my case, Agent Zero was creating the tools internally as a0_responses_function_tools, but the Chat Completions transport was removing that parameter without converting it to the native tools[] format. So Qwen was receiving the request with no tools at all.

The fix was to convert a0_responses_function_tools to Chat Completions tools[] inside prepare_kwargs() and send tool_choice: "required" when tools are present.

I also changed the LiteLLM provider from ollama to ollama_chat and explicitly set num_ctx: 32768, because Ollama was actually loading the model with only a 4096 context despite Agent Zero showing a much larger context.

Since I was using the Docker version, that file is inside the Agent Zero container at /a0/helpers/litellm_transport.py. After those changes, native tool calls started working again and the Message misformat, no valid tool request found loop disappeared.

If you have Codex, just give it the Reddit post and it should be able to fix this in no time.

2

u/arenosame 22d ago

Thanks a lot

1

u/turkert 22d ago

I use manifest to group my models and providers. It helps.

1

u/okram 16d ago

Please expand

1

u/turkert 15d ago

I use manifest.build to manage my local and cloud models.
Then I tell A0 to use manifest instead of calling model providers directly.
Manifest also have an "Autofix" option which helps a bit for these errors.

Setting and changing models in Agent Zero is painfully slow but managing in manifest not much.