Skip to content

feat(run): optional per-phase advisor model — measure first, then a retry rung between effort and model escalation #1138

Closed

Description

@admarble

Blocked by #1227 (Phase 0 arms need a correct resolved model; see the 2026-09-30 comment)

Context

Claude Code's advisor tool (experimental, docs: https://code.claude.com/docs/en/advisor) gives the main model a parameterless advisor() server tool backed by a second model. Each call forwards the full conversation (every tool call and result) to the advisor, which returns guidance. The harness prompt tells the model to call it before substantive work, before declaring done, when stuck, and when changing approach; timing is model-driven and there is no cap/force setting — frequency is steered by prompt text only.

Facts verified 2026-09-24 against the docs, the CLI binary, and the installed SDK:

  • Pairing: the advisor must be at least as capable as the main model. Sonnet 5 → Fable / Opus ≥ 4.7 / Sonnet 5; Opus 5.5 → Fable / Opus ≥ 5; Haiku can call but not advise. A refused pairing silently drops the advisor for the rest of the conversation.
  • Enablement: advisorModel settings key, --advisor <model> (absent from --help), /advisor (headless text form needs CLI ≥ 2.1.260). Kill switch CLAUDE_CODE_DISABLE_ADVISOR_TOOL=1.
  • Reaches Sequant today with zero code: src/lib/workflow/drivers/claude-code.ts passes settingSources: ["project"], so a project .claude/settings.json advisorModel applies to every phase. The SDK bundles CLI 2.1.263 and sdk.d.ts exposes Settings.advisorModel, settable per call via query({ settings }) — the SDK reference docs do not list it yet, the typings do.
  • Subagents inherit it and re-check pairing against their own model. Caveat: upstream #76381 (v2.1.206, closed stale 2026-09-15) reported background subagents do not inherit it; exec/SKILL.md §Parallel Groups spawns implementers in the background.
  • Cost: advisor tokens bill at the advisor's rates and the advisor's read is never cached — every call re-reads the whole transcript. Toggling it does not bust the main model's cache.
  • Requirements: Anthropic API only (no Bedrock / Vertex / Foundry); needs feature-flag fetching (any DISABLE_TELEMETRY-style var keeps it off; Sequant sets none).

Relation to existing levers. Sequant's two escalation mechanisms — --escalate-effort (#915) and --model-ladder (#971/#995) — are retry-based and off by default; .sequant/metrics.json has recorded 0 escalations to date. The advisor is a different lever: in-turn and proactive. It is not a replacement for either.

Two design facts that shape this issue:

  1. The advisor cannot be fed context directly. It sees exactly what the main model sees, so "give the advisor the session log" means "put the log in the phase prompt", which the main model then carries all phase and the advisor re-reads uncached on every call. The right inputs are the small structured artifacts Sequant already produces: the previous iteration's structured QA gap findings (feat(qa/loop/ready): structured gap findings — finite taxonomy with required evidence, replacing the lossy prose-scrape gap channel #937), the ladder evidence bundle (SHAs tried, verdicts per iteration), and the spec comment. Not the log.
  2. It must be an optional dependency. Same pattern as feat(run): per-phase model and effort configuration for the claude-code driver #914 model/effort: absent by default, omitted from query() options entirely when unset, honored only by the claude-code driver, ignored by Codex/opencode, never mentioned in any skill (keeps the three mirrors clean and Bedrock/Vertex users unaffected).

Fix shape

Phase 0 — measure before building (the whole issue is gated on this). Add "advisorModel": "opus" to the dogfood project's .claude/settings.json (no code change) and replay 3–4 already-solved issues through exec at the current sonnet/medium pin, at least one with a ## Parallel Groups section. Compare against the same issues' recorded baseline on the #916 discriminators — verdict mix, loop iterations, wall time, tokensUsed (correct since #986/#1010) — and confirm from the transcripts (a) how many advisor calls fired per phase and where, (b) whether background parallel-group implementers ever called it. Write the null result first per the measurement discipline: if advisor-on and advisor-off show the same verdict mix and loop count, the report says so and the build ACs are closed as not needed.

Build (only on a GO from Phase 0):

Acceptance criteria

  • AC-1: docs/investigations/advisor-tool-phase0-2026-09.md exists, reports advisor-on vs advisor-off for ≥ 3 replayed issues on verdict mix, loop iterations, wall time, and tokensUsed, quotes the per-phase advisor call count from the transcripts, states whether background parallel-group implementers called it, and opens with the null-result criterion that would make the measurement meaningless.
  • AC-2: The report ends with an explicit GO or NO-GO for the build track with the numbers that decide it; on NO-GO, AC-3…AC-7 are closed in the PR body as not needed and the issue closes with the report alone.
  • AC-3: run.phases.<phase>.advisor, run.advisor, and --advisor are parsed with CLI > settings > absent precedence through the shared resolvePhasePolicies resolver, and an unset value leaves the query() options object with no settings.advisorModel key — Verify: key-presence unit test mirroring the feat(run): per-phase model and effort configuration for the claude-code driver #914 AC-3 test.
  • AC-4: Only the claude-code driver forwards the advisor; the Codex, opencode, and aider drivers ignore it — Verify: driver-options unit tests per driver.
  • AC-5: sequant doctor warns when an advisor is configured for a non-claude-code backend or when the phase model / advisor pairing is one the docs table rejects, and stays silent when unset — Verify: doctor unit test.
  • AC-6: phaseUsage rows carry advisorModel and advisorCalls for phases that ran with an advisor and omit both keys otherwise — Verify: metrics unit test.
  • AC-7: docs/reference/run-command.md and docs/reference/model-ladder.md document the setting, the pairing rule, the uncached full-transcript cost, the Anthropic-API-only limit, and that no skill references the advisor — Verify: grep -ril advisor .claude/skills templates/skills templates/codex templates/opencode returns nothing.
  • AC-8: On GO, a follow-up issue for the retry rung (effort → advisor → model, with structured gap findings injected on loop re-entry) is filed and linked from the PR body.
  • AC-9: npm run lint:skill-sync 0 diverged; npm run build && npm test green.

Non-goals

  • Putting session logs or prior-phase transcripts into phase prompts to "give the advisor context" — see design fact 1.
  • Any skill-level mention of the advisor (keeps Codex/opencode mirrors clean).
  • Replacing --escalate-effort or --model-ladder.

Related: #1135 (upstream gap; this is one of its follow-ups), #914, #915, #971, #995, #916, #986.

Activity

  1. added
    enhancement
    planned
    cli
    on Sep 24, 2026
  2. admarble commented on Sep 30, 2026

    @admarble
    ContributorAuthor

    Pre-Phase-0 findings (2026-09-30)

    This issue's Phase 0 is the advisor on/off experiment. Four findings from the code and one probe change what Phase 0 needs.

    1. Advisor tokens reach phaseUsage as their own row (mechanism confirmed). The CLI's cost accumulator walks each response's usage.iterations[] and adds every advisor_message iteration under the advisor's own model ID. So the SDK result's modelUsage carries the advisor as a separate key, and normalizeModelUsage (phase-executor.ts:1858) turns it into a phaseUsage row with its own costUSD. A one-shot claude -p --model opus probe with an advisor configured returned two keys, claude-opus-5-5 and claude-fable-5-1, and the advisor's input was entirely uncached (cacheReadInputTokens: 0). No code change is needed for cost. Two gaps remain, and both are already AC-6:

    • When the advisor is the same model as the phase model (for example Opus advising Opus), the two merge into one key and the advisor cost can't be separated.
    • Nothing counts advisor calls. advisorCalls has to come from the transcript's advisor tool uses.

    2. No sequant phase has run with an advisor yet. The claude-code driver passes settingSources: ["project"], so an advisorModel set in user settings never reaches a phase. No .sequant/metrics.json on the dogfood machine has an advisor-model phaseUsage row. Phase 0 must set the project .claude/settings.json key as written above. Interactive-session observations do not stand in for phase data.

    3. Phase 0 is now blocked by #1227. Since 2026-09-20, resolvedModel records the Haiku helper for every phase: it takes the first modelUsage key, and that key is now Haiku. #1198 carries the bad value into the run log and the top-level metrics model. Arms keyed on that field would repeat #916 phase-0 confound 3. #1227's AC-2 also keeps the fix from selecting the advisor key. Until #1227 lands, key Phase 0 arms on the per-model phaseUsage rows, not on resolvedModel.

    4. Field observations: one Max account, 2026-09, interactive sessions, not sequant phases.

    • Advisor usage sits in message.usage.iterations[] (type: "advisor_message"), not in the top-level usage. Transcript-based counters vary: as of 2026-09-29, ccusage 20.0.26 counts it, while entire 0.11.3 and claude-monitor 4.0.0 do not. Sequant's SDK path is unaffected (finding 1). A future transcript-based fallback must read iterations[].
    • With an Opus 5.5 driver, the advisor added roughly 17–20% on top of the driver's per-turn cost.
    • Pattern: calls made just before handing off a plan or PR most often changed what the main model did next. Calls at the start of a task rarely did. Report-only subagents paid for calls that changed nothing. Background subagents did call it, which is evidence against the upstream #76381 inheritance concern. Phase 0 should still check this for ## Parallel Groups implementers.
    • The advice text comes back encrypted, so its effect can only be read from the main model's next actions. Phase 0's verdict mix and loop count are the right outcome measures, not the advice content.

    Considered, not filed: a general "assign setups to runs, join each run to its outcome (merged / CI / reverted within N days)" experiment framework. There's no consumer today. #916 and this Phase 0 both replay in fixture forks with no PR, so there is nothing to join to. In-vivo dogfood volume, around 10 runs a week per repo, is too small for rare outcomes like reverts or re-opens. If it comes back, it needs a key first: a metrics run id does not match its run log's runId, so a run can't be joined to its PR except by issue number and timestamp.

  3. admarble commented on Sep 30, 2026

    @admarble
    ContributorAuthor

    Phase 0 results (2026-09-30): NO-GO

    Report: docs/investigations/advisor-tool-phase0-2026-09.md, in #1230.

    Per AC-2, #1230 closes AC-3…AC-7 as not needed. The retry-rung idea (advisor only on a loop retry) remains a candidate new issue, not part of this one.

  4. added a commit that references this issue on Sep 30, 2026
  5. admarble commented on Sep 30, 2026

    @admarble
    ContributorAuthor

    Closed by #1230 (squash 2aec2459): Phase 0 NO-GO, build track AC-3…AC-7 not needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    clienhancementplanned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions