Skip to content

feat(agents): Hermes and Codex give each turn's counts by model - #896

Merged
earakely-scale merged 3 commits into
mainfrom
edgararakelyan/fd6744-hermes-codex-models
Nov 23, 2026
Merged

earakely-scale merged 3 commits into
mainfrom
edgararakelyan/fd6744-hermes-codex-models

Conversation

@earakely-scale

@earakely-scale earakely-scale commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

What changes

The last of P16 (FD-6744): Hermes and Codex give each turn's counts by model (Usage.models, #887), so each model a turn used is priced at its own rate. The other agents switch to the protocol helper #893 added.

  • Codex: one row per model a turn's threads ran on. The bridge keeps each thread's share of the turn (CodexResult.threads: the turn's own thread, then each subagent's) with the model its rollout last ran on, read from the rollout's turn_context. One reader, read_rollout, now reads a rollout's running total, its request count and that model in one pass, in place of a function each. spawn_agent can start a subagent on another model, so this matters for Codex. A thread whose rollout names no model counts as the turn's configured model; with none known, the turn gives no rows and is priced at the role's model.
  • Hermes: one row, the turn's model, with the turn's counts. Hermes runs its auxiliary tasks (title, compression) on the main model, and a delegate_task child inherits it, as the profile the bridge writes pins no other. The usage file names the main loop's model; the post_api_request events name each child's (and, for a killed turn, each call's). A turn whose calls named more than one model gives no rows rather than guess how they split.
  • Relay and Gemini: each model's row comes from ModelUsage.of (feat(agents): Claude Code, Gemini, OpenCode, Letta Code and the proxy give each turn's counts by model #893), as the proxy's does.
  • Protocol floors:

Tests

  • tst/unit/agents/codex/test_usage.py: a subagent on another model is that model's row, with the calls each thread made; a thread whose rollout names no model counts as the turn's; none known gives no rows.
  • tst/unit/agents/hermes/test_message_contract.py: a turn's counts, its title call's and a child's included, are its model's one row, with Hermes' cost when it priced every call; calls naming two models give no rows; a killed turn's row is the model its calls named.
  • The relay's, Gemini's and the proxy's existing row tests cover the switch to ModelUsage.of.

E2E against the real proxy

On an admin host, through a logging pass-through in front of the real proxy, each run's solver entry was compared row by row with the proxy's own count for each model its calls named, and each row's cost with the map's price of the proxy's counts.

Run Rows (calls) Counts vs proxy Cost vs map
Codex, gpt-5.6-sol parent, subagent on gpt-6-luna gpt-5.6-sol (3), gpt-6-luna (2) exact equal
Codex, subagent on the parent's model gpt-5.3-codex (4) exact equal
Codex, baseline and chat gpt-4.1-mini (3; 4) exact equal
Hermes, delegate_task child, title call claude-haiku-4-5 (5) exact equal
Hermes, baseline (GPT, Claude), chat one row each exact equal
Hermes, killed turn claude-haiku-4-5 (2), partial exact equal
OpenCode, Letta Code, Gemini web search (relay and Gemini on ModelUsage.of) as before #896 exact equal
  • Codex's subagent on another model is priced at that model's rate: the gpt-6-luna subagent's two calls cost $0.0019 at its own rate, beside the parent's $0.0588.
  • A Codex turn stopped at its tool-call limit misses the request in flight when the bridge stopped the CLI, as since feat(agents): Claude Code and Codex report each turn's token usage, subagents' calls included #850, and is marked partial.
  • Finding: through Scale's proxy, a Codex subagent on a model routed to another provider than its parent's fails. A gpt-5.3-codex parent (OpenAI) with a gpt-5.6-sol or gpt-6-luna subagent (Azure OpenAI): every subagent request ends in response.failed (invalid_encrypted_content, the parent's encrypted reasoning can't be read there), so the subagent used nothing. The two-model run above keeps both on Azure. gpt-5.4-mini isn't one Codex 0.162.1 lets spawn_agent choose.
  • Chaos, 15 minutes on two workers: 32 runs of those scenarios with faults at 0%, 20% or 35% on every call. All completed; 37 of 38 rows were exact against the proxy and equal to the map's price, the other being the stopped Codex turn above, marked partial. Every entry is priced, and no model the proxy saw for the solver went without a row.

Model spend: about $1.25 at list prices.

Docs

For FD-6263 and FD-6442: Hermes and Codex give their counts by model, so every shipped agent that knows its calls' models now does (Claude Code, Gemini, OpenCode, Letta Code, Hermes, Codex, the proxy, sandboxed and in-process). Through Scale's proxy, a Codex subagent on a model the proxy routes to another provider than its parent's fails (invalid_encrypted_content: the parent's encrypted reasoning can't be read there).

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no actionable new issues were found.

Summary

Codex and Hermes now report turn usage by model. Gemini and the shared relay use ModelUsage.of, and agent requirements raise the protocol floors.

  • Codex turns report each thread's counts under the model it ran.
  • Hermes reports one model row when all calls name the same model.
  • The sandboxed proxy can send usage rows for each model it calls.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
    C[Codex thread rollouts] --> T[Turn counts per thread]
    T --> M[Usage.models]
    H[Hermes usage file and child events] --> S{One named model?}
    S -->|Yes| M
    S -->|No| U[Turn totals only]
    M --> P[Price each model separately]
Loading

Reviews (5) · Last reviewed commit: "refactor(agents): Codex reads each rollo..." · Reviewed by Greptile

earakely-scale and others added 2 commits November 23, 2026 12:44
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…delUsage.of, and the sandboxed proxy gives rows

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earakely-scale
earakely-scale marked this pull request as ready for review November 23, 2026 21:15
@earakely-scale
earakely-scale requested a review from a team as a code owner November 23, 2026 21:15
…in one place, and Hermes names its turn's models in a function of its own

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earakely-scale
earakely-scale merged commit e4b20bd into main Nov 23, 2026
35 checks passed
@earakely-scale
earakely-scale deleted the edgararakelyan/fd6744-hermes-codex-models branch November 23, 2026 21:48
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