hermes - 💡(How to fix) Fix Auto-negotiate tool count when model rejects with 'tools array too long'

Official PRs (…)
ON THIS PAGE

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…

Error Message

ERROR root: Non-retryable client error: Error code: 400 - {'error': {'message': "Invalid 'tools': array too long. Expected an array with maximum length 128, but got an array with length 131 instead.", 'code': 'invalid_request_body'}}

ERROR root: Non-retryable client error: Error code: 400 - {'error': {'message': "Invalid schema for function 'mcp_arr_stack_sonarr_update_custom_format': In context=('properties', 'specifications'), array schema missing items.", 'code': 'invalid_request_body'}}

Root Cause

Hermes loads 131-134 tools (builtin ~60 + MCP arr_stack ~72) which exceeds some models' 128-tool limit. Claude models accept unlimited tools, but OpenAI-family models on Copilot enforce 128.

Code Example

Invalid 'tools': array too long. Expected an array with maximum length 128,
but got an array with length 131 instead.

---

⚠️  Model gpt-5-mini supports max 128 tools, but 131 are loaded.
     Choose toolsets to disable for this session:
     
     [1] MCP: arr_stack (72 tools)
     [2] Browser (11 tools)  
     [3] Home Assistant (4 tools)
     [4] Smart home (4 tools)

---

ERROR root: Non-retryable client error: Error code: 400 - {'error': 
  {'message': "Invalid 'tools': array too long. Expected an array with 
  maximum length 128, but got an array with length 131 instead.", 
  'code': 'invalid_request_body'}}

ERROR root: Non-retryable client error: Error code: 400 - {'error': 
  {'message': "Invalid schema for function 'mcp_arr_stack_sonarr_update_custom_format': 
  In context=('properties', 'specifications'), array schema missing items.", 
  'code': 'invalid_request_body'}}
RAW_BUFFERClick to expand / collapse

Bug / Feature Request

Problem

When switching to models that enforce a maximum tool count (e.g., GPT-5-mini on GitHub Copilot caps at 128 tools), the API returns a 400 error:

Invalid 'tools': array too long. Expected an array with maximum length 128,
but got an array with length 131 instead.

This is a hard failure — the error is classified as a non-retryable client error and the request aborts. The user has no way to recover without manually editing config.yaml to disable MCP servers or toolsets.

A secondary issue: some MCP tool schemas (e.g., sonarr_update_custom_format) have arrays without items definitions, which stricter models also reject with 400.

Root Cause

Hermes loads 131-134 tools (builtin ~60 + MCP arr_stack ~72) which exceeds some models' 128-tool limit. Claude models accept unlimited tools, but OpenAI-family models on Copilot enforce 128.

Proposed Solution

Interactive tool negotiation on overflow:

  1. Add a tools_overflow reason to FailoverReason in agent/error_classifier.py

  2. Detect "array too long" in the error message and extract the max limit (128)

  3. In the recovery path in run_agent.py, when tools_overflow is detected:

    • Group tools by source (builtin toolsets vs each MCP server)
    • Present the user with an interactive prompt showing tool groups and counts:
      ⚠️  Model gpt-5-mini supports max 128 tools, but 131 are loaded.
      Choose toolsets to disable for this session:
      
      [1] MCP: arr_stack (72 tools)
      [2] Browser (11 tools)  
      [3] Home Assistant (4 tools)
      [4] Smart home (4 tools)
    • Remove selected tool groups from self.tools and self.valid_tool_names
    • Retry the API call
  4. Schema sanitization: Before sending tools to the API, validate that array-type properties have items defined, and add "items": {} as a fallback if missing.

Environment

  • Hermes Agent on WSL
  • Provider: GitHub Copilot (api.githubcopilot.com)
  • Models affected: gpt-5-mini, gpt-5.4-mini (any non-Claude model with tool limits)
  • MCP server: arr_stack (~72 tools from Sonarr/Radarr/Lidarr)

Error Logs

ERROR root: Non-retryable client error: Error code: 400 - {'error': 
  {'message': "Invalid 'tools': array too long. Expected an array with 
  maximum length 128, but got an array with length 131 instead.", 
  'code': 'invalid_request_body'}}

ERROR root: Non-retryable client error: Error code: 400 - {'error': 
  {'message': "Invalid schema for function 'mcp_arr_stack_sonarr_update_custom_format': 
  In context=('properties', 'specifications'), array schema missing items.", 
  'code': 'invalid_request_body'}}

Relevant Code Locations

  • agent/error_classifier.pyFailoverReason enum, classify_api_error()
  • run_agent.py line ~10640-11165 — error handling / recovery loop
  • run_agent.py line ~1350 — self.tools = get_tool_definitions(...)
  • model_tools.py line ~196 — get_tool_definitions() with toolset filtering
  • toolsets.py — toolset definitions and _HERMES_CORE_TOOLS

extent analysis

TL;DR

Implement interactive tool negotiation to handle tool count overflows and sanitize tool schemas to ensure array-type properties have items defined.

Guidance

  • Identify the maximum tool limit for the model being used (e.g., 128 for gpt-5-mini) and detect when the loaded tools exceed this limit.
  • Implement a recovery path that presents the user with an interactive prompt to select tool groups to disable when a tool count overflow is detected.
  • Validate tool schemas before sending them to the API to ensure array-type properties have items defined, adding a fallback if missing.
  • Consider modifying the FailoverReason enum in agent/error_classifier.py to include a tools_overflow reason.

Example

# Example of sanitizing a tool schema
tool_schema = {
    'type': 'array',
    # Add 'items' definition if missing
    'items': {} if 'items' not in tool_schema else tool_schema['items']
}

Notes

This solution assumes that the agent/error_classifier.py and run_agent.py files can be modified to implement the interactive tool negotiation and schema sanitization. Additionally, the model_tools.py and toolsets.py files may need to be updated to support the new tool filtering and schema validation logic.

Recommendation

Apply the proposed solution to implement interactive tool negotiation and schema sanitization, as it addresses the root cause of the issue and provides a user-friendly recovery path.

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

hermes - 💡(How to fix) Fix Auto-negotiate tool count when model rejects with 'tools array too long'