Skip to content

fix(agent): unwrap pre-wrapped tool schemas from context engines and memory providers - #47732

Closed
srojk34 wants to merge 1 commit into
NousResearch:mainfrom
srojk34:fix/context-engine-memory-provider-schema-double-wrap
Closed

fix(agent): unwrap pre-wrapped tool schemas from context engines and memory providers#47732
srojk34 wants to merge 1 commit into
NousResearch:mainfrom
srojk34:fix/context-engine-memory-provider-schema-double-wrap

Conversation

@srojk34

@srojk34 srojk34 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Context engines and memory providers can return schemas already in {"type":"function","function":{...}} (OpenAI tool) form. Each consumer site blindly wrapped them again, producing a tool with no top-level name.
  • An un-named tool entry is silently un-routable inside Hermes and triggers HTTP 400: tools[N].function: missing field name on strict providers such as DeepSeek — failing every request in the session, not just the offending tool.
  • Added a nameless-schema guard in the context-engine loop so any schema still lacking a name after unwrapping is skipped rather than appended as dead weight.

Changes

File Change
agent/agent_init.py Unwrap pre-wrapped schemas before registration; skip nameless entries
agent/memory_manager.py Same unwrap in _add_schemas_to_agent, _tool_to_provider index, and get_all_tool_schemas()
tests/agent/test_memory_provider.py 5 new tests covering both fix paths; updated TestContextEngineToolsetGate helper to mirror the fixed production code

Test plan

  • uv run --frozen python -m pytest tests/agent/test_memory_provider.py -x -q → 96 passed
  • Verify that a context engine returning already-wrapped schemas no longer causes HTTP 400 on DeepSeek / other strict providers
  • Confirm that valid unwrapped schemas continue to register and route normally

Fixes #47707

…memory providers

A context engine or memory provider returning a schema already in
{"type":"function","function":{...}} form caused a second wrap at each
consumer site. The resulting tool had no top-level name, making it
un-routable internally and triggering HTTP 400 "missing field name" on
strict providers (e.g. DeepSeek) for every request in the session.

Fixed in four consumer sites:
- agent/agent_init.py: context-engine schema loop
- agent/memory_manager.py: _add_schemas_to_agent helper
- agent/memory_manager.py: _tool_to_provider routing index
- agent/memory_manager.py: MemoryManager.get_all_tool_schemas()

Also added a nameless-schema guard in the context-engine loop so a
schema with no 'name' is skipped rather than appended as a dead tool.

Fixes NousResearch#47707
@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint tool/memory Memory tool and memory providers P1 High — major feature broken, no workaround labels Jun 17, 2026
@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jun 21, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Automated hermes-sweeper review: this fix is already implemented on current main via merged PR #52140.

Evidence:

Thanks for the report and fix work here; the behavior is now covered on main.

@teknium1 teknium1 closed this Jun 29, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P1 High — major feature broken, no workaround sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:implemented-on-main Sweeper: behavior already present on current main sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades tool/memory Memory tool and memory providers type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants