hermes - 💡(How to fix) Fix Bug: Ollama cloud model glm-5.1 produces malformed JSON tool calls in long contexts

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

When using the glm-5.1:cloud model (via Ollama cloud routing) as the primary reasoning agent, tool calls with complex or lengthy argument values produce malformed JSON. This causes tool call parsing failures and can crash the agent loop.

Root Cause

This appears to be a model-level issue with GLM-5.1's structured output generation degrading in long contexts, not a Hermes parsing bug. The same model works fine for short-context tool calls.

Fix Action

Workaround

  1. Use shorter sessions / clear context more frequently
  2. For complex tasks, use delegate_task with a model that handles long contexts better (e.g., Claude Code ACP)
  3. Break large tool call arguments into smaller chunks
RAW_BUFFERClick to expand / collapse

Description

When using the glm-5.1:cloud model (via Ollama cloud routing) as the primary reasoning agent, tool calls with complex or lengthy argument values produce malformed JSON. This causes tool call parsing failures and can crash the agent loop.

Steps to Reproduce

  1. Configure Hermes with glm-5.1:cloud as the reasoning model (via Ollama ACP)
  2. Engage in a long conversation session (many turns, context approaching limits)
  3. Ask the agent to perform a complex task that requires a tool call with a large JSON argument (e.g., put_page with long markdown content)
  4. Observe malformed JSON in the tool call arguments — often truncation, missing closing braces, or escaped quotes breaking the structure

Expected Behavior

Tool call arguments should always be valid JSON, regardless of context length or argument size.

Actual Behavior

The model's tool call JSON output becomes malformed when:

  • The context window fills up (many turns of conversation)
  • The tool call arguments are large (e.g., long strings, multi-line content)
  • The JSON values contain special characters that the model fails to escape properly

Common malformations observed:

  • Truncated JSON (missing closing })
  • Double-escaped quotes (\\" instead of ")
  • Raw newlines inside JSON string values (should be \\n)
  • Missing commas between JSON object properties

Impact

This makes the agent unreliable in long sessions when using glm-5.1:cloud. The agent may:

  • Fail silently (tool call dropped)
  • Retry the same malformed call repeatedly
  • Eventually hit max retries and give up

Root Cause

This appears to be a model-level issue with GLM-5.1's structured output generation degrading in long contexts, not a Hermes parsing bug. The same model works fine for short-context tool calls.

Suggested Mitigations in Hermes

  1. JSON repair on tool call parse failure: Attempt to fix common JSON malformations (truncation, missing braces) before failing
  2. Model-specific context length limits: Enforce a lower effective context limit for models known to degrade, auto-compacting earlier
  3. Fallback routing: When a tool call parse fails N times, retry with a different model or with a simplified prompt
  4. Validation layer: Validate tool call JSON against the expected schema before dispatching

Workaround

  1. Use shorter sessions / clear context more frequently
  2. For complex tasks, use delegate_task with a model that handles long contexts better (e.g., Claude Code ACP)
  3. Break large tool call arguments into smaller chunks

Environment

  • Hermes Agent v0.10.0
  • Model: glm-5.1:cloud (via Ollama cloud)
  • Transport: Ollama ACP
  • OS: macOS

extent analysis

TL;DR

Implement JSON repair mechanisms and enforce context length limits to mitigate malformed JSON issues with the glm-5.1:cloud model in Hermes.

Guidance

  • Validate and repair JSON: Implement a validation layer to check tool call JSON against the expected schema and attempt to fix common malformations (truncation, missing braces, double-escaped quotes) before failing.
  • Enforce context length limits: Set a lower effective context limit for the glm-5.1:cloud model to prevent degradation in long contexts.
  • Use fallback routing: Retry failed tool calls with a different model or a simplified prompt after a certain number of failures.
  • Break large arguments into chunks: Divide large tool call arguments into smaller, more manageable pieces to reduce the likelihood of malformed JSON.

Example

No code snippet is provided as the issue does not require a specific code example to understand the guidance.

Notes

The provided guidance is based on the suggested mitigations in the issue and may not be exhaustive. The effectiveness of these measures may vary depending on the specific use case and environment.

Recommendation

Apply the suggested workaround of using shorter sessions, clearing context more frequently, and breaking large tool call arguments into smaller chunks, as this approach is likely to mitigate the issue without requiring significant changes to the underlying system.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING