Skip to content

Context-engine/memory-provider tool schemas are wrapped without validating a top-level name — one malformed schema 400s the entire request #47707

Closed

Description

@tcconnally

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 _schema already 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

  1. added
    type/bugSomething isn't working
    comp/agentCore agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint
    tool/memoryMemory tool and memory providers
    P1High — major feature broken, no workaround
    on Jun 17, 2026
  2. added a commit that references this issue on Jun 24, 2026
  3. added a commit that references this issue on Jun 24, 2026
    710cd48
  4. added a commit that references this issue on Jun 28, 2026
    11ae1f6
  5. 6 remaining items

  6. added 2 commits that reference this issue on Jul 8, 2026
    8d75f79
    db33540
  7. added 2 commits that reference this issue on Jul 13, 2026
    a58166d
    e5e389f
  8. added 2 commits that reference this issue on Jul 21, 2026
    20e9665
    cf67dbd
  9. added 2 commits that reference this issue on Aug 7, 2026
    8ad65e6
    09bf4dd
  10. added 2 commits that reference this issue on Sep 3, 2026
    da7c5ae
    e65d5d2
  11. added 2 commits that reference this issue on Oct 6, 2026
    9c517c0
    2f62558
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High — major feature broken, no workaroundcomp/agentCore agent runtime: loop, agent_init, prompt builder, context-compression, responses endpointtool/memoryMemory tool and memory providerstype/bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions