Skip to content

feat(2048): Hermes brain for live solo loop — B-direct adapter + AGENT_BRAIN selector#183

Open
youngstar-eth wants to merge 1 commit into
mainfrom
feat/hermes-brain-2048-loop
Open

feat(2048): Hermes brain for live solo loop — B-direct adapter + AGENT_BRAIN selector#183
youngstar-eth wants to merge 1 commit into
mainfrom
feat/hermes-brain-2048-loop

Conversation

@youngstar-eth

Copy link
Copy Markdown
Owner

Summary

Adds an OpenRouter Hermes 3 (Nous Research) brain to the live 2048 solo loop as a drop-in alternative to the Claude brain, selectable per-deploy via the AGENT_BRAIN env. Move-generation only — the duel_moves insert, reasoning capture, on-chain submitSoloScore path, and DB schema are untouched and brain-agnostic.

Do NOT merge / deploy yet. This stage is build + local dry-run only. No live on-chain run, no deploy, no Vercel env writes.

Why B-direct (not @skillos/hermes-mcp-wrapper.run())

The wrapper's run()/MCP surface owns game state in an MCP session_store and loops multiple turns internally — the wrong shape for the runner's one-call-one-move contract. Instead we use the openai SDK pointed at OpenRouter's base URL: a single chat.completions.create per move with a forced make_move function tool, preserving the structured-output guarantee (no free-text parsing).

Change-set

File Change
apps/api/src/lib/duel/hermes-agent.ts (NEW) Exact mirror of anthropic-agent.ts — same getNextMove(ctx) contract, prompt, board rendering, legal-move validation + illegal-move fallback. Post-response extraction isolated in pure exported parseMoveResponse() (unit-testable without a key). temperature 0.3.
apps/api/src/lib/duel/hermes-client.ts (NEW) Lazy OpenRouter client reading OPENROUTER_API_KEY; AGENT_MATCH_MODEL pinned to hermes-3-llama-3.1-405b; 70B fallback noted for B4; display Hermes 3 405B (Nous).
apps/api/src/lib/duel/runner.ts Import swapped to an AGENT_BRAIN selector (loadBrain, literal import() specifiers, default 'claude'), resolved once per match. B4: match wall-clock budget exposed via MATCH_MAX_DURATION_SECONDS / MATCH_TIMEOUT_MARGIN_SECONDS env with defaults preserving the original Claude-path timing.
apps/api/package.json Add openai ^4.77.0 (resolves 4.104.0).
apps/api/vercel.json Add openai to function includeFiles (companion to the dep; the Claude path's @anthropic-ai is already listed). prepare-bundle.sh's npm ls pass also copies it automatically.
apps/api/.env.example Document AGENT_BRAIN, OPENROUTER_API_KEY, and the B4 knobs.
apps/api/scripts/hermes-dryrun.ts (NEW) Dry-run harness. --mock = offline parseMoveResponse logic check (no key); live mode calls the real brain against 3 sample boards and reports per-move + median latency.

Verification (this stage)

  • tsc --noEmit green; eslint green.
  • ✅ Mock dry-run 8/8: valid passthrough, illegal→fallback, and missing-tool / bad-JSON / invalid-direction all throw; 3 sample boards expose legal moves.
  • ✅ Claude path regression-free: anthropic-agent.ts byte-unchanged; selector defaults to 'claude'; duel_moves + submitSoloScore hunks byte-identical.
npm run -w apps/api hermes:dryrun -- --mock     # offline (no key) — runs in CI-like conditions
OPENROUTER_API_KEY=sk-or-... npm run -w apps/api hermes:dryrun   # LIVE — prints median latency

⚠️ Follow-ups (NOT in this PR)

  • Live median latency (405B) is PENDING a founder-run of the dry-run with a real OPENROUTER_API_KEY (local env only). This number feeds the 405B-vs-70B model decision (B4): if 405B per-move latency blows the wall-clock move budget, flip AGENT_MATCH_MODEL to the 70B fallback noted in hermes-client.ts.
  • OPENROUTER_API_KEY must be provisioned on the Vercel app-api project by the founder before any Hermes-path deploy — not committed here.
  • Apex /watch model-name render lives in the sibling skillbase-apex repo (currently may show "Claude Haiku 4.5") — out of scope here; flag for a separate sister check.

🤖 Generated with Claude Code

…T_BRAIN selector

Adds an OpenRouter Hermes 3 (Nous Research) brain to the live 2048 solo loop
as a drop-in alternative to the Claude brain, selectable per-deploy via the
AGENT_BRAIN env. Move-generation only: the duel_moves insert, reasoning
capture, on-chain submitSoloScore path, and DB schema are untouched and
brain-agnostic.

Why B-direct (not @skillos/hermes-mcp-wrapper.run()): the wrapper's run()/MCP
surface owns game state in an MCP session_store and loops multiple turns
internally — the wrong shape for the runner's one-call-one-move contract.
Instead we use the `openai` SDK pointed at OpenRouter's base URL: a single
chat.completions.create per move with a forced make_move function tool,
preserving the structured-output guarantee (no free-text parsing).

- NEW hermes-agent.ts: exact mirror of anthropic-agent.ts (same getNextMove
  contract, prompt, board rendering, legal-move validation + illegal-move
  fallback). Post-response extraction isolated in pure exported
  parseMoveResponse() so it is unit-testable without an API key. temperature
  0.3 (between Anthropic's 0.4 and the wrapper's deterministic 0).
- NEW hermes-client.ts: lazy OpenRouter client reading OPENROUTER_API_KEY;
  AGENT_MATCH_MODEL pinned to hermes-3-llama-3.1-405b; 70B fallback noted for
  the B4 latency call; display 'Hermes 3 405B (Nous)'.
- runner.ts: import swapped to AGENT_BRAIN selector (loadBrain, literal
  import() specifiers, default 'claude'); resolved once per match. B4: match
  wall-clock budget (MATCH_MAX_DURATION_SECONDS / MATCH_TIMEOUT_MARGIN_SECONDS)
  exposed via env with defaults preserving the original Claude-path timing.
- package.json: add openai ^4.77.0 (resolves 4.104.0).
- vercel.json: add openai to function includeFiles (companion to the dep; the
  Claude path's @Anthropic-AI is already listed). prepare-bundle.sh's npm-ls
  pass also picks it up automatically.
- .env.example: document AGENT_BRAIN, OPENROUTER_API_KEY, and the B4 knobs.
- scripts/hermes-dryrun.ts: dry-run harness. --mock = offline parseMoveResponse
  logic check (no key); live mode calls the real brain against 3 sample boards
  and reports per-move + median latency.

Verification (this stage, no live on-chain / no deploy):
- typecheck (tsc --noEmit) green; lint green.
- mock dry-run 8/8: valid passthrough, illegal→fallback, missing-tool /
  bad-JSON / invalid-direction all throw; 3 sample boards expose legal moves.
- Claude path regression-free: anthropic-agent.ts byte-unchanged; selector
  defaults to 'claude'; duel_moves + submitSoloScore hunks byte-identical.

Live median latency (405B) is PENDING a founder-run of the dry-run with a real
OPENROUTER_API_KEY — feeds the 405B-vs-70B model decision. OPENROUTER_API_KEY
must be provisioned on the Vercel app-api project (NOT in this PR). Apex /watch
model-name render lives in the sibling skillbase-apex repo — out of scope here.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 1, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
mas-2048 Ready Ready Preview, Comment Jun 1, 2026 8:09am
mas-clicker Ready Ready Preview, Comment Jun 1, 2026 8:09am
mas-match3 Ready Ready Preview, Comment Jun 1, 2026 8:09am
mas-minesweeper Ready Ready Preview, Comment Jun 1, 2026 8:09am
mas-sudoku Ready Ready Preview, Comment Jun 1, 2026 8:09am
mas-wordle Ready Ready Preview, Comment Jun 1, 2026 8:09am
skillbase-orchestrator Ready Ready Preview, Comment Jun 1, 2026 8:09am
skillbase-sponsor Ready Ready Preview, Comment Jun 1, 2026 8:09am

Request Review

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.

1 participant