Repository navigation
Description
Summary
In agent/agent_init.py, tool schemas returned by a context engine's get_tool_schemas() are wrapped as {"type": "function", "function": _schema} and appended to agent.tools without validating that _schema has a top-level name. If a provider returns an entry that is already in OpenAI tool form (i.e. {"type":"function","function":{...}}) — or any dict lacking a top-level name — the result is a malformed tool whose function has no name. Strict upstream providers (e.g. DeepSeek) reject the entire request with HTTP 400, so a single bad tool silently disables the whole toolset and breaks every turn.
The code
# agent/agent_init.py (context-engine tool registration)
for _schema in agent.context_compressor.get_tool_schemas():
_tname = _schema.get("name", "")
if _tname and _tname in _existing_tool_names:
continue
_wrapped = {"type": "function", "function": _schema} # <-- no validation of _schema
agent.tools.append(_wrapped)
if _tname:
agent.valid_tool_names.add(_tname)
...If _schema is already wrapped, _wrapped becomes:
{"type":"function","function":{"type":"function","function":{"name":"...", ...}}}_schema.get("name") is then "", so the tool is also never added to valid_tool_names — meaning even non‑strict providers can't actually call it. The same unguarded pattern exists for memory providers in agent/memory_manager.py.
Reproduction
A context engine whose get_tool_schemas() returns a fully-wrapped entry:
def get_tool_schemas(self):
return [{"type": "function", "function": {"name": "x_grep",
"description": "...", "parameters": {"type": "object", "properties": {}}}}]Run any turn against DeepSeek. Result (observed on hermes-agent 0.16.0):
HTTP 400: Failed to deserialize the JSON body into the target type:
tools[N].function: missing field `name`
The whole request aborts (non-retryable), then fails over — so it looks like a routing/provider problem when it's actually one malformed tool.
Impact
- A single plugin returning a slightly-wrong schema takes down all model calls, not just its own tool.
- The failure surfaces far from the cause (a provider 400 deep in the toolset payload), making it very hard to diagnose.
Suggested fix
Before wrapping, validate/normalize:
- If
_schemaalready looks wrapped (_schema.get("type") == "function"and"function" in _schema), unwrap it (or use as-is) instead of double-wrapping. - Require a resolvable name; skip with a warning rather than appending a nameless tool.
- Apply the same guard to memory-provider schemas in
memory_manager.py.
This keeps one bad plugin from poisoning the entire request and gives a clear log line pointing at the offending provider.
Found while debugging a downstream DeepSeek tools[N].function: missing field name 400 on hermes-agent 0.16.0. Filed via Claude Code.
Activity
Merge pull request #52140 from NousResearch/salvage/47707-tool-schema…
fix(agent): validate context/memory tool schemas before wrapping
fix(agent): validate context/memory tool schemas before wrapping
6 remaining items
fix(agent): validate context/memory tool schemas before wrapping
Merge pull request NousResearch#52140 from NousResearch/salvage/47707…
fix(agent): validate context/memory tool schemas before wrapping
Merge pull request NousResearch#52140 from NousResearch/salvage/47707…
fix(mcp): normalize wrapped schemas in refresh re-injection so lcm_* …
fix(agent): validate context/memory tool schemas before wrapping
Merge pull request NousResearch#52140 from NousResearch/salvage/47707…
fix(agent): validate context/memory tool schemas before wrapping
Merge pull request NousResearch#52140 from NousResearch/salvage/47707…
fix(agent): validate context/memory tool schemas before wrapping
Merge pull request NousResearch#52140 from NousResearch/salvage/47707…
fix(parity 2026-10-01 ci): M4-tools — misc tools cluster: facade re-e…
fix(agent): validate context/memory tool schemas before wrapping
Merge pull request NousResearch#52140 from NousResearch/salvage/47707…