Skip to content

_spawn_background_review doesn't pass base_url / api_key — context length detection fails for custom/fallback endpoints #15882

@ersinrulez

Description

@ersinrulez

Summary

_spawn_background_review in run_agent.py creates the review AIAgent with only model and provider, omitting base_url and api_key. This means the review agent cannot look up per-model context overrides from custom_providers (which requires base_url to match) and cannot query custom endpoint /models APIs for context length detection.

Affected code

run_agent.py_spawn_background_review_run_review():

review_agent = AIAgent(
    model=self.model,
    max_iterations=8,
    quiet_mode=True,
    platform=self.platform,
    provider=self.provider,
    parent_session_id=self.session_id,
    # ← base_url and api_key missing
)

Impact

When the main agent is on a fallback provider (e.g. openrouter, cerebras, siliconflow), the background review agent:

  1. Cannot resolve custom_providers[].models.<model>.context_length (step 0 in get_model_context_length) because get_custom_provider_context_length returns None when base_url is empty
  2. Falls through to live API detection, which may return the real model context window — triggering the MINIMUM_CONTEXT_LENGTH (64K) guard and raising ValueError, killing the review thread silently

Observed symptom

⚠ Auxiliary background review failed: Model minimax/minimax-m2.5:free has a context window of 32,768 tokens, which is below the minimum 64,000 required by Hermes Agent.

The main agent was using minimax/minimax-m2.5:free as a fallback. The review agent correctly detected 32K from OpenRouter's live API — but the configured context_length override was never consulted because base_url was absent.

Proposed fix

review_agent = AIAgent(
    model=self.model,
    max_iterations=8,
    quiet_mode=True,
    platform=self.platform,
    provider=self.provider,
    base_url=getattr(self, "base_url", ""),
    api_key=getattr(self, "api_key", ""),
    parent_session_id=self.session_id,
)

Environment

  • hermes-agent (main branch, 2026-04-26)
  • Triggered when primary model rate-limits and fallback provider is activated before a background review fires

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existscomp/agentCore agent loop, run_agent.py, prompt builderprovider/openrouterOpenRouter aggregatortype/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions