# Debugging ZORGAX: We Captured the Tool-Calling Loop Between Open WebUI and Ollama

●2 ●56 ●155
calendar_today • schedule7 min read

Debugging ZORGAX: We Captured the Tool-Calling Loop Between Open WebUI and Ollama

From 28 repeated function calls to a successful end-to-end test — and a new hypothesis about context-window limits.

Introduction

In my previous article, Building ZORGAX: Turning a Local LLM into a DevOps AI Agent, I described our effort to transform a local language model into a controlled infrastructure assistant for the MyZubster ecosystem.

ZORGAX runs on Ollama, uses a custom model based on Qwen 2.5 3B, and connects to Open WebUI inside a Docker-based environment.

Our objective is not to give AI unrestricted control over a server. We want an assistant capable of observing infrastructure, explaining problems, and eventually performing carefully authorized operations.

But we encountered a problem that made one thing clear:

An AI agent that knows how to call a tool must also know when to stop.

When ZORGAX called list_automations, the tool correctly returned an empty list. Yet the agent repeatedly called the same function instead of giving a final answer.

In earlier tests, we observed 28 repeated calls, followed by another run with 16 calls.

This article documents how we investigated that behavior, what we verified, and why the root cause is still an open research question.

1. The original problem

We asked ZORGAX to check active automations.

The tool returned:

{
  "automations": [],
  "total": 0
}

The expected answer was straightforward:

There are currently no active automations.

Instead, ZORGAX kept invoking list_automations.

For a read-only function, unnecessary repetition wastes time and computing resources.

For a future DevOps agent with permission to restart services, deploy software, or modify infrastructure, uncontrolled repetition could be much more serious.

We therefore decided to investigate the entire tool-calling workflow before enabling additional operational capabilities.

2. Testing ZORGAX directly through Ollama

Our first experiment bypassed Open WebUI.

We constructed a synthetic tool-calling conversation using Ollama's /api/chat endpoint.

The sequence contained a user request, an assistant function call, and a matching tool response containing the empty automation list.

ZORGAX completed the interaction successfully.

It generated a final answer and did not request another tool call.

This showed that the model could handle an empty tool response correctly.

However, the direct experiment used a simplified context. It was not identical to the original Open WebUI interaction, so it could not establish which component was responsible for the loop.

3. A suggestion from the developer community

After publishing the first article on Coder Legion, a commenter, lisarconnect, suggested capturing the actual request sent to Ollama immediately after the first tool response.

The key question was:

Does the next request preserve the assistant's tool call and the corresponding tool result?

This gave us a concrete investigation strategy.

Instead of guessing whether the problem came from Qwen, Ollama, or Open WebUI, we could inspect the integration boundary directly.

We also wanted to distinguish a successful empty result from a tool execution error.

Those two situations should not trigger the same behavior.

4. Inspecting Open WebUI's tool-call handling

We examined the installed Open WebUI source and identified the code responsible for continuing conversations after tool execution.

We then tested its actual convert_output_to_messages() function using a synthetic fixture.

The conversion preserved the expected structure:

[
  {
    "role": "assistant",
    "content": "",
    "tool_calls": [
      {
        "id": "zorgax-test-001",
        "type": "function",
        "function": {
          "name": "list_automations",
          "arguments": "{}"
        }
      }
    ]
  },
  {
    "role": "tool",
    "tool_call_id": "zorgax-test-001",
    "content": "{\"automations\":[],\"total\":0}"
  }
]

The assistant tool-call identifier matched the tool-result identifier.

The empty result was preserved.

This was an important finding, but it covered only the isolated message-conversion function.

We still needed evidence from the actual HTTP requests reaching Ollama.

5. Building a separate diagnostic environment

To avoid affecting the main MyZubster installation, we deployed a separate Open WebUI instance.

We also configured:

CHAT_RESPONSE_MAX_TOOL_CALL_ITERATIONS: "3"

In the Open WebUI build we inspected, the default tool-call iteration limit was 256.

Reducing that limit helped prevent another long-running diagnostic loop.

It was a safety measure, not a fix for the underlying behavior.

We kept operational tools disabled and used a harmless simulated automation function.

class Tools:
    def list_automations(self) -> dict:
        """Return a synthetic empty automation list."""
        return {
            "automations": [],
            "total": 0
        }

This function performs no infrastructure operation. It always returns the same predictable result.

6. Capturing the real Open WebUI → Ollama requests

We created a temporary HTTP proxy between the diagnostic Open WebUI instance and Ollama.

The proxy forwarded requests while recording structural information such as:

  • Model name
  • Available tool names
  • Message roles
  • Tool-call identifiers
  • Presence of the simulated empty result

We intentionally avoided logging complete private prompts and credentials.

One earlier captured request advertised approximately 35 built-in tools.

That was very different from our successful direct Ollama test, which exposed only list_automations.

We also reproduced the repeated-call behavior in the isolated Open WebUI environment, where it stopped after reaching the configured three-iteration limit.

At this stage, the number of tools became an interesting variable to investigate.

But correlation is not causation.

We had not yet demonstrated that having many available tools caused the repeated calls.

7. The successful end-to-end experiment

We created a diagnostic model configuration called ZORGAX Diagnostic and enabled only one harmless tool.

Then we asked:

Controlla quali automazioni sono attive usando list_automations. Se non ce ne sono, dimmelo.

This time, ZORGAX called the tool once and responded correctly:

Non ci sono automazioni attive.

The proxy captured the complete follow-up structure.

The first request exposed:

Tools: ['list_automations']
Messages: ['user']

The next request contained:

Tools: ['list_automations']
Messages: ['user', 'assistant', 'tool']
Empty automation result: True

This was the evidence we had been looking for.

Open WebUI successfully transmitted the assistant tool call and the empty tool result to Ollama, and ZORGAX produced a final answer.

We later repeated the successful single-tool experiment.

The proxy again confirmed that the tool result reached Ollama and that ZORGAX completed the task.

This does not solve the original loop, but it substantially narrows our investigation.

8. A second hypothesis: context-window truncation

Another Coder Legion commenter, Mike Dabydeen, suggested examining the model's available context window.

His hypothesis was that a conversation containing a system prompt, extensive tool definitions, and chat history might exceed the available context.

If older messages are truncated, the model might receive the latest tool result without sufficient context to understand the original request.

That could potentially explain repeated tool calls.

We investigated the Ollama configuration.

Our environment uses:

Ollama version: 0.32.14
Model: zorgax:latest

The ZORGAX Modelfile does not explicitly specify num_ctx.

The Ollama service also does not explicitly configure OLLAMA_CONTEXT_LENGTH.

After running a diagnostic inference, we queried the loaded model:

NAME             PROCESSOR    CONTEXT
zorgax:latest    100% CPU     4096

We confirmed that the successful single-tool test operated with a 4096-token context window.

We also updated our diagnostic proxy to record explicitly supplied values of num_ctx and num_predict.

The logging worked correctly.

For real requests generated by our diagnostic Open WebUI configuration, num_ctx was not explicitly present in the captured request options.

That is different from saying the model had no context limit. Ollama still allocated a context window, as confirmed by ollama ps.

What remains unverified

We have not yet captured evidence that Ollama actually truncated messages during the problematic 35-tool interaction.

We have also not completed a controlled comparison of the same tool workload at 4096 versus 8192 tokens.

Context truncation is therefore a plausible hypothesis, not our final diagnosis.

The next experiment must keep the model, system instructions, tool schemas, and user request as consistent as possible while changing one variable at a time.

9. What these experiments taught us

The investigation revealed three separate questions that matter for reliable AI agents.

First: Did the tool execute correctly?

An empty list can be a successful result. It must not automatically be treated as an error.

Second: Did the result reach the language model?

The conversation should preserve the relationship between the assistant's tool call and the tool's response.

Third: Did the model use the result correctly?

Even a correctly transmitted response does not guarantee that a model will stop calling tools.

All three stages need independent testing.

For infrastructure agents, safeguards must also exist outside the model:

  • Restricted tool permissions
  • Bounded execution and retries
  • Duplicate-call detection
  • Idempotent operations where applicable
  • Human authorization for consequential actions
  • Auditable execution results

A prompt instruction saying “do not repeat the tool call” is not a substitute for these controls.

10. Opening the investigation to contributors

We have published our diagnostic findings in the public MyZubster repository.

GitHub investigation issue:

https://github.com/MyZubster-Ecosystem/myzubster/issues/1577

Technical reproduction guide:

https://github.com/MyZubster-Ecosystem/myzubster/blob/main/docs/zorgax/TOOL-CALLING-INVESTIGATION-2026-10-09.md

Developers working with Ollama, Open WebUI, Qwen, Python, or local AI agents are invited to reproduce the experiments.

Useful contributions include controlled context-window comparisons, tool-schema experiments, sanitized HTTP request analysis, and regression tests for empty results and repeated calls.

Contributors can use their own systems. No access to the MyZubster production VPS or private infrastructure is required.

Conclusion

We started with an AI agent repeatedly invoking a function that had already returned a valid result.

We now have a working diagnostic environment, a trace of the actual tool-result continuation, and two successful end-to-end single-tool experiments.

We have also confirmed a 4096-token context allocation and identified a new hypothesis worth testing.

The root cause of the original loop remains open.

That is an important distinction.

We are not claiming that we have fixed a bug simply because one controlled configuration works.

We are building an evidence-based process to understand why the integration behaves differently under different conditions.

For ZORGAX, the objective remains unchanged: create a useful local DevOps assistant that operates within clear security boundaries and earns trust through reproducible tests.

The next milestone is a controlled 4096-versus-8192 context experiment with safe tool fixtures.

Thanks to lisarconnect and Mike Dabydeen for their technical suggestions and to everyone following the MyZubster development process.

The investigation continues in public.


Project: MyZubster Ecosystem
Agent: ZORGAX
Stack: Ollama, Qwen 2.5 3B, Open WebUI, Docker, Python, Ubuntu
Status: Experimental; root cause under investigation

Build in public. Test with evidence. Keep humans in control.

Want more #debugging & #myzubster deep dives?

Join 6,175+ developers sharing real benchmarks, code breakdowns, and projects. Free forever.

More Posts

When One Python Process Fails, You Need to See All of Them

Tom Smithverified - Nov 23

AAIF Hits 10 Projects. Its CTO on What to Adopt Now and the Security Gaps Left Open

Tom Smithverified - Oct 23

3.5 best practices on how to prevent debugging

Codeac.io - Dec 18, 2025

How to save time while debugging

Codeac.io - Dec 11, 2025

We’re Taking Zorgax From GitHub Into the Real World — And N4K48 Is One of the First Experiments

Myzubster - Sep 1
chevron_left
4.4k Points • 213 Badges
Rimini
112Posts
17Comments
33Connections

Commenters (This Week)

17 comments
13 comments
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!