#131278·hermes-agent

[Bug]: clarify tool schema `maxLength: 8000` breaks every request on llama.cpp servers ("Failed to initialize samplers: failed to parse grammar")

Author: yasu224Created Oct 2, 2026Updated Oct 2, 2026
Labelstype/bugcomp/agentcomp/toolsP2bugarea/local-models

Bug Description

Summary

Since commit a4c31d592b9 ("fix(tools): reject all-blank and over-limit clarify choices…"), the clarify tool schema includes "maxLength": 8000 on choices.items. llama.cpp's JSON-schema-to-grammar converter rejects any repetition count ≥ 2000, so every chat completion request to a llama.cpp server fails with HTTP 400 — even a plain "hello", because the tool list is always sent.

Error

HTTP 400: Failed to initialize samplers: failed to parse grammar
layer: provider, code: format_error, retryable: false

Environment

  • Hermes: v0.21.5+5673.g00373b5 (main @ 00373b53761), Windows 11, desktop app
  • Provider: custom OpenAI-compatible endpoint → llama.cpp server (owned_by: llamacpp), GGUF model
  • Last working build: 5f75ec197b16 (worked), 2fa2f42d412 and later fail

Reproduction

  1. Point Hermes at a llama.cpp server (custom provider, api_mode: chat_completions).
  2. Send any message → 400 above.

Isolated by sending each of the 24 tools individually from the request dump (HERMES_DUMP_REQUESTS=1) to the server:

clarify → choices.items.maxLength Result
8000 (current) ❌ failed to parse grammar
2000 ❌ failed to parse grammar
1999 ✅ OK
removed ✅ OK

All other tools pass individually; the full 24-tool request succeeds once maxLength is removed from clarify.

Cause

tools/clarify_tool.py:

python
"items": {"type": "string", "maxLength": MAX_CHOICE_CHARS},  # MAX_CHOICE_CHARS = 8000

llama.cpp expands maxLength into a bounded repetition and caps it at < 2000.

Suggested fix

Drop maxLength from the schema. The limit is already enforced at runtime in clarify_tool.py (the len(choice.strip()) > MAX_CHOICE_CHARS check), so behavior is unchanged:

diff
-                            "items": {"type": "string", "maxLength": MAX_CHOICE_CHARS},
+                            "items": {"type": "string"},

I've applied this locally, and requests to llama.cpp work again.

More generally, it may be worth stripping or clamping maxLength/maxItems ≥ 2000 from tool schemas for llama.cpp/local providers (similar to agent/gemini_schema.py), so a future schema change can't take down all local-model users.

Steps to Reproduce

Steps to Reproduce

A. Through Hermes

  1. Start a llama.cpp server (llama-server with --jinja, any GGUF model).
  2. Add it to config.yaml as a custom provider:
    yaml
    model:
      default: <model-name>
      provider: my-llamacpp
      base_url: http://<host>:<port>/v1
      api_mode: chat_completions
    providers:
      my-llamacpp:
        base_url: http://<host>:<port>/v1
        model: <model-name>
  3. Send any message, for example:
    bash
    hermes -z "hello"
  4. Expected: the model replies. Actual: the request fails at once with:
    HTTP 400: Failed to initialize samplers: failed to parse grammar
    This happens on every turn, including the first message of a new session, because the clarify tool is always in the tool list.

B. Minimal reproduction without Hermes (curl only)

This sends one tool whose schema copies the choices part of clarify:

bash
curl -s http://<host>:<port>/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "<model-name>",
    "max_tokens": 1,
    "messages": [{"role": "user", "content": "hello"}],
    "tools": [{"type": "function", "function": {
      "name": "clarify",
      "parameters": {"type": "object", "properties": {
        "choices": {"type": "array", "items": {"type": "string", "maxLength": 8000}}
      }}
    }}]
  }'

Result:

json
{"error":{"code":400,"message":"Failed to initialize samplers: failed to parse grammar","type":"invalid_request_error"}}

With "maxLength": 1999, or with maxLength removed, the same request succeeds. Any value ≥ 2000 fails.

Expected Behavior

Expected Behavior

  • Hermes should keep working with llama.cpp servers (and other OpenAI-compatible local servers that turn tool schemas into grammars) as it did before a4c31d592b9. A normal message like "hello" should get a normal reply.
  • Built-in tool schemas should not use JSON Schema constraints that common local inference backends reject. Here, maxLength on clarify → choices.items should be removed, or kept below 2000. The 8000-character limit on choices can still be enforced at runtime, as clarify_tool.py already does.
  • If a tool schema does cause a provider-side grammar error, the error should point to the cause, for example by naming the tool or schema, instead of only suggesting "pick another model". A malformed tool definition should not leave the user with no working model.

Actual Behavior

Actual Behavior

Every request to the llama.cpp server is rejected before any text is generated:

HTTP 400: Failed to initialize samplers: failed to parse grammar
  • It happens on every turn. A brand-new session that only sends "hello" fails the same way, because the clarify tool is always in the tool list. Hermes is unusable with this provider.

  • Hermes does not retry. The error is classified as format_error / retryable: false, and the turn ends after one attempt:

    WARNING agent.conversation_loop: API call failed (attempt 1/3, not retryable) error_type=BadRequestError ... summary=HTTP 400: Failed to initialize samplers: failed to parse grammar
    ERROR   agent.conversation_loop: Non-retryable client error: Error code: 400 - {'error': {'code': 400, 'message': 'Failed to initialize samplers: failed to parse grammar', 'type': 'invalid_request_error'}}
  • The hint points the wrong way. The user is told:

    custom rejected this request as malformed, so the model didn't answer. Start a clean session with /new or switch models with /model; if it keeps happening, run hermes doctor.

    Neither /new nor switching to another model on the same llama.cpp server helps, because the bad schema comes from Hermes and not from the session or the model.

  • The server itself is healthy. The same server answers normally when clarify is left out or its maxLength is below 2000. The regression appeared right after updating from 5f75ec197b16 to 2fa2f42d412, with no change on the server side.

Affected Component

Other

Messaging Platform (if gateway-related)

No response

Debug Report

bash
## Debug Report

<details>
<summary><code>hermes debug share --local</code> (dump section + relevant log excerpt, IP/paths redacted)</summary>


--- hermes dump ---
version:          0.21.5+5673.g00373b5 [00373b53] (2026-10-01)
os:               Windows 11 AMD64
python:           3.14.7
openai_sdk:       2.24.0
profile:          <profile>
model:            <model-name>  (GGUF on llama.cpp server)
provider:         custom (named custom provider, api_mode: chat_completions)
terminal:         local

features:
  toolsets:           hermes-cli
  mcp_servers:        0
  memory_provider:    built-in
  platforms:          none
  skills:             85

config_overrides:
  agent.max_turns: 500
  display.streaming: True
--- end dump ---



--- agent.log (excerpt) ---
INFO  hermes_cli.main: Checkout changed since last launch (git:refs/heads/main:5f75ec197b16 -> git:refs/heads/main:2fa2f42d412a)
INFO  tools.tool_search: tool_search activated (tier 1): 22 core/visible tools kept, 16 deferred (~7463 tokens), listing full (budget ~4000 tokens)
INFO  agent.turn_context: conversation turn: ... model=<model-name> provider=custom platform=desktop history=0 msg='hello'
INFO  run_agent: OpenAI client created (chat_completion_stream_request, shared=False) ... provider=custom base_url=http://<llama-host>:<port>/v1
ERROR agent.chat_completion_helpers: Streaming failed before delivery: Error code: 400 - {'error': {'code': 400, 'message': 'Failed to initialize samplers: failed to parse grammar', 'type': 'invalid_request_error'}}
Traceback (most recent call last):
  File "agent/chat_completion_helpers.py", line 3868, in _call
  File "agent/chat_completion_helpers.py", line 3845, in _call_wire
  File "agent/chat_completion_helpers.py", line 3194, in _call_chat_completions
  File "agent/relay_llm.py", line 329, in _start_unmanaged
  File "agent/chat_completion_helpers.py", line 3085, in _open_chat_stream
    return request_client.chat.completions.create(**stream_kwargs)
  File ".../openai/_base_client.py", line 1070, in request
openai.BadRequestError: Error code: 400 - {'error': {'code': 400, 'message': 'Failed to initialize samplers: failed to parse grammar', 'type': 'invalid_request_error'}}
WARNING agent.conversation_loop: API call failed (attempt 1/3, not retryable) error_type=BadRequestError ... summary=HTTP 400: Failed to initialize samplers: failed to parse grammar
ERROR   agent.conversation_loop: Non-retryable client error: Error code: 400 - {'error': {'code': 400, 'message': 'Failed to initialize samplers: failed to parse grammar', 'type': 'invalid_request_error'}}
INFO    tui_gateway.server: tui turn finished: ... status=error error_retained=True duration=1.0s failure_reason=format_error cause='HTTP 400: Failed to initialize samplers: failed to parse grammar'



--- llama.cpp server (/v1/models) ---
owned_by: llamacpp, format: gguf, n_ctx: 131072, system_fingerprint: b0-unknown


</details>

Full request payload is available via `HERMES_DUMP_REQUESTS=1`; the only tool that fails on its own is `clarify` (see table above).

Operating System

Windows11

Python Version

No response

Hermes Version

No response

Additional Logs / Traceback (optional)

bash

Root Cause Analysis (optional)

No response

Proposed Fix (optional)

No response

Are you willing to submit a PR for this?

  • I'd like to fix this myself and submit a PR

Source: NousResearch/hermes-agent