Skip to content

[Bug] TypeError in models.py: "can only concatenate str (not 'NoneType') to str" when using Ollama #970

@librepensador-coder

Description

@librepensador-coder

Description

When using Agent Zero v0.9.7-10 with Ollama models, the memory recall system fails with a TypeError because reasoning_delta can be None.

Error

Traceback (most recent call last):
  File "/a0/python/extensions/message_loop_prompts_after/_50_recall_memories.py", line 146, in search_memories
    filter = await self.agent.call_utility_model(
  File "/a0/agent.py", line 719, in call_utility_model
    response, _reasoning = await call_data["model"].unified_call(
  File "/a0/models.py", line 545, in unified_call
    output = result.add_chunk(parsed)
  File "/a0/models.py", line 118, in add_chunk
    self.reasoning += processed_chunk["reasoning_delta"]
TypeError: can only concatenate str (not "NoneType") to str

Environment

  • Agent Zero version: v0.9.7-10
  • Model provider: Ollama
  • Chat model: qwen2.5:32b
  • Utility model: qwen2.5:7b / qwen2.5:32b
  • OS: Windows 11 (Docker)

Root Cause

In models.py line 118-119, the code assumes processed_chunk["reasoning_delta"] and processed_chunk["response_delta"] are always strings, but Ollama can return None.

Proposed Fix

# Line 118-119 in models.py
self.reasoning += processed_chunk["reasoning_delta"] or ""
self.response += processed_chunk["response_delta"] or ""

Workaround

Manually patch the container:

docker exec agent-zero sh -c "sed -i 's/self.reasoning += processed_chunk\[\"reasoning_delta\"\]$/self.reasoning += processed_chunk[\"reasoning_delta\"] or \"\"/g' /a0/models.py && sed -i 's/self.response += processed_chunk\[\"response_delta\"\]$/self.response += processed_chunk[\"response_delta\"] or \"\"/g' /a0/models.py"
docker restart agent-zero

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions