Skip to content

fix: gateway provider resolution and model config parity with CLI#42

Closed
VencentSoliman wants to merge 2 commits into
NousResearch:mainfrom
VencentSoliman:fix/gateway-provider-resolution
Closed

fix: gateway provider resolution and model config parity with CLI#42
VencentSoliman wants to merge 2 commits into
NousResearch:mainfrom
VencentSoliman:fix/gateway-provider-resolution

Conversation

@VencentSoliman

@VencentSoliman VencentSoliman commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

Summary

The gateway was hardcoding OpenRouter as the LLM provider, ignoring the provider setting in config.yaml and Nous OAuth credentials. This brings the gateway in line with how the CLI resolves providers, models, and credentials.

  • Provider resolution: Gateway now calls resolve_provider() from hermes_cli.auth, supporting both Nous OAuth and OpenRouter
  • Nous OAuth support: Added _ensure_runtime_credentials() that refreshes access tokens and mints agent keys before each AIAgent creation
  • Model resolution: Matches CLI priority chain (HERMES_MODEL > LLM_MODEL > config.yaml model.default)
  • Hot-reload feat from @teknium1 preserved: Re-reads .env and config.yaml per message (builds on 55a0178) so credential/config changes are picked up without gateway restart
  • Both AIAgent call sites fixed: Main message handler + memory flush on /reset
  • /model command: Now uses centralized self._model state instead of env var

👇 Thats a table (Summary of changes)

Aspect Before After
Provider OpenRouter (hardcoded) Respects config.yaml provider setting
Nous OAuth Ignored (sad) Full support (token refresh + agent key minting)
Model source Only HERMES_MODEL env var HERMES_MODEL > LLM_MODEL > config.yaml
Memory flush agent No api_key/base_url passed Uses resolved credentials
/model command Set env var only Updates self._model directly

Test plan

  • Set provider: nous in config.yaml, verify gateway uses Nous inference endpoint
  • Set provider: openrouter (or remove provider), verify gateway uses OpenRouter
  • Change LLM_MODEL in .env without restart, verify gateway picks it up on next message
  • Test /model command shows and changes the active model
  • Test /reset command (memory flush agent uses correct provider)

The gateway was hardcoding OpenRouter as the LLM provider, ignoring
the provider setting in config.yaml and Nous OAuth credentials.
This brings the gateway in line with how the CLI resolves providers,
models, and credentials.

Changes:
- Add provider resolution via resolve_provider() from hermes_cli.auth
- Add _ensure_runtime_credentials() that re-reads .env and config.yaml
  per message (preserving hot-reload for long-lived gateway process)
- Support Nous OAuth: refresh access tokens and mint agent keys
- Fix model resolution to match CLI priority chain
  (HERMES_MODEL > LLM_MODEL > config.yaml model.default)
- Pass api_key and base_url to both AIAgent call sites
  (main message handler + memory flush on reset)
- Update /model command to use centralized self._model state
- Updated model configuration to prioritize environment variables and config file settings for better consistency.
- Added functionality to persist model changes to both config.yaml and .env, aligning with CLI behavior.
- Improved error handling during the saving process to ensure robustness.
@teknium1

Copy link
Copy Markdown
Contributor

partially fixed in cbde854

going to close and add the remainder, added you as a coauthor to that commit so you are still a contributor now ^_^

thank you <3

@VencentSoliman

Copy link
Copy Markdown
Contributor Author

This is a blocking comment

😐

sudo-yf pushed a commit to sudo-yf/hermes-agent that referenced this pull request Apr 5, 2026
…arkdown-update

docs: comprehensive markdown update for v0.24

@lex-assistant lex-assistant left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: PR #42

Verdict: Good direction, needs rebase + some polish

What is good

  • Extracting credential/resolution logic into _ensure_runtime_credentials() is the right abstraction.
  • Nous OAuth flow with agent key minting and TTL/timeout via env vars is solid.
  • /model persistence writing to both config.yaml and .env mirrors CLI behavior.
  • Fixing both call sites (_handle_reset_command and run_sync()) is correct.

Blocking issues

  1. Needs rebase: Branch is from Feb 26 with merge conflicts. ~20 commits to gateway/run.py since then. Commit cbde854 already added Nous auth inline in run_sync() — simpler form. Your approach is more comprehensive but needs careful rebase.
  2. Return value unchecked: _ensure_runtime_credentials() return value is ignored in both run_sync() and _handle_reset_command. If credential refresh fails, gateway proceeds with stale creds.
  3. Hardcoded Path.home(): Codebase is migrating to get_hermes_home() from hermes_constants.py. The inline config reads here should use it.

Non-blocking suggestions

  • Move imports to module level if possible (or comment circular import concern).
  • Consider logger.debug instead of logger.info for provider/model on init.
  • Extract a shared helper for config.yaml read + model resolution to avoid duplication between init and _ensure_runtime_credentials.

Summary

This is a meaningful improvement over both the original hardcoded OpenRouter code and the minimal cbde854 partial fix. Needs rebase, return-value checks, and hardcoded path fix. Please rebase onto current main, resolve conflicts, and re-submit.

jarvis-stark-ops pushed a commit to 1Team-Engineering/hermes-agent that referenced this pull request Jun 10, 2026
Adds two new completion gates that fire alongside the Part 1/2 gates.

Closes hermes-jarvis#63 (PR-existence verification)
Closes hermes-jarvis#32 (doc-drift check)
Context: hermes-jarvis#61 (bootstrap-paradox case study)

## NousResearch#63 — verify_pr_urls_exist

When a verdict result or summary contains a GitHub PR URL pattern,
the dispatcher runs `gh pr view <url> --json number` to verify each
URL resolves. Phantom URLs (404 with "Not Found" / "Could not
resolve" / "no pull request" in stderr) reject the completion.

Indeterminate cases (gh missing, network error, unauthenticated) fall
open — workers can still complete in offline / broken-gh envs without
being trapped.

Catches the 2026-06-09 Tchalla case (hermes-jarvis#61): release-gate
reviewer blocked with "cannot run gh pr diff 42" on PR NousResearch#42 that
didn't exist. With this gate, his completion would have surfaced the
phantom URL specifically, prompting him to surface the real cause.

Opt-out: `metadata.x_phantom_pr_ok` with ≥20-char string reason.

## NousResearch#32 — verify_doc_drift

For tasks whose tenant slug encodes a version
(`marvel-swarm-vN-N-test`), the gate scans `README.md` / `README` in
the workspace for older `vX.Y` mentions outside a history-style
heading (`## History`, `## Older versions`, `## Previous versions`,
`## Archive`). Stale mentions reject the completion.

CHANGELOG.md is intentionally skipped — older versions are expected
there by definition.

Catches the 2026-06-09 agent-dashboard PR #1 case (hermes-jarvis#61):
README still said "v6.2 Marvel swarm test target" while the chain
was v6.6. No reviewer flagged it.

Opt-out: `metadata.x_doc_drift_ok` with ≥20-char string reason.

## Tests

19 new tests added to `test_kanban_completion_gates.py`:
- TestPRExistence (8) — no PR URL skipped, real passes, phantom
  rejects, mixed real+phantom flags only phantom, indeterminate falls
  open, summary scanned, dedup, opt-out
- TestDocDrift (10) — non-versioned tenant skips, no README skips,
  stale README rejects, current README passes, History section
  excused, CHANGELOG file excused, higher version not stale, scratch
  skipped, opt-out

83 passed in test_kanban_completion_gates.py (up from 64). Zero
regressions on adjacent paths.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants