Skip to content

feat(cli): consult_advisor in missions, delegated children and cron runs (#587 part 2b) - #655

Merged
ajianaz merged 3 commits into
developfrom
feat/advisor-wiring
Nov 13, 2026
Merged

ajianaz merged 3 commits into
developfrom
feat/advisor-wiring

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What

Part 2b of #587: consult_advisor registered in the runs that have a token budget it can share. Closes #587.

Depends on:

This branch has the latest develop merged in (a merge commit) and now targets develop.

Why

Your constraint: the advisor's tokens must come out of the run's own budget, and a face whose meter cannot share it gets no tool, never an uncounted advisor. tole mission (and so a delegated child) and cron agent runs have a token budget. run, chat, the TUI, serve and ACP have none, so the tool is not registered there, and the docs say so.

Changes

  • mission.rs: when the profile declares models.advisor, MissionConfig::advisor registers consult_advisor, with the contract Profile: <name> plus the mission goal.
    • The Budget starts at what the session already spent, so a resume counts earlier advisor usage.
    • The run's provider is wrapped in the Tap (charge = true).
    • After each turn, record_usage writes the advisor's usage to the session, so the next budget check includes it.
  • main.rs: a mission gets the advisor from its own profile. A delegated child is a tole mission --profile <p>, so it gets one only when its profile declares it.
  • cron/agent.rs:
    • TokenMeter now charges a shared Budget (the same limit as before, the same trip).
    • With an advisor, the job's run registers the tool, with the contract Profile: <name> plus the job's own prompt (never the webhook context). It wraps the provider in the Tap (charge = false, since the meter charges).
    • After the turn it records the advisor's usage, so the run's tokens and the daily cap include it.
    • Plan-mode (webhook ReadOnly) runs keep the tool: it is ReadOnly, under the same cap.
    • If recording the usage fails, the run ends with an error rather than leaving the usage uncounted.
  • profile.rs: the doctor line now says where the tool is available.
  • Docs: the CHANGELOG, design A10 "as implemented, part 2", the threat-model row, the README status line and profile example, and docs/epics.md (AGENTS.md §7).

Testing

  • cargo fmt --all

  • cargo clippy --workspace --all-targets --all-features -- -D warnings

  • cargo test --workspace

  • cargo test -p tole-core --no-default-features

  • No-mcp CI commands:

    • cargo check -p tole-cli --no-default-features
    • cargo clippy -p tole-cli --no-default-features --features shell-tools -- -D warnings
    • cargo test -p tole-cli --no-default-features
  • The commands above ran on the combined tree before feat(cli): consult_advisor host tool, tap and usage records (#587 part 2a) #654 merged.

  • After the merge of develop (only the CHANGELOG conflicted), I re-ran fmt, the advisor_host unit tests and advisor_e2e on this head.

  • cora review --no-llm --staged: no issues.

  • tests/advisor_e2e.rs (new): 6 tests on the real binary. One mock provider plays the executor and the advisor (wise-model). They check:

    • the advisor request: it carries no tools, does not stream, and is a system message plus one user message. It is redacted (a process secret in the question and the transcript never appears) and capped. Its window holds the run's own transcript (MISSION GOAL), and the executor gets the fenced verdict back;
    • counting: a usage record tagged "role": "advisor" is written to the session;
    • the use cap: the second ask makes no call and gets the advisor_max_uses refusal. A plain --profile coder run is not offered the tool;
    • a nearly spent budget: one executor step spends 4,800 of 5,000 tokens, and the consultation is refused with no advisor call. This works only because the run's spending reaches the shared budget;
    • failures: an HTTP 500 and an empty reply are reported by the tool, the mission still completes, and the tokens spent are recorded;
    • hostile replies: an advisor answering with its own write_file tool call runs nothing (no file appears), and a hostile text reply cannot close its fence;
    • cron: a profiled job consults and records the usage, and a job whose own step nearly spends its budget gets no advisor call.
  • Mutation breaks, each restored afterwards; the tests caught all 6 for the wiring:

    • the tool is Write;
    • a mission without the tap;
    • a mission's usage is not recorded;
    • a mission gets no advisor;
    • the cron meter keeps its own budget;
    • cron usage is not recorded.

    Together with feat(cli): consult_advisor host tool, tap and usage records (#587 part 2a) #654's 11, all 17 were caught.

…t 2a)

tole_cli::advisor_host: ConsultAdvisor (ReadOnly) makes one advisor call
with no tools, no streaming and no fallback chain, built from the task
contract, the question and an in-memory window of the run's transcript
kept by Tap, and returns only the fenced verdict. A consultation the
run's shared Budget cannot fit, or past advisor_max_uses, is refused
before any call; what a call spent is charged and queued even when it
fails, and record_usage writes it to the session tagged role advisor.
No run registers the tool yet.
…uns (#587 part 2b)

A mission (and so a delegated child, by its own profile) and a cron
agent run register consult_advisor when the profile declares
models.advisor; run, chat, the TUI, serve and ACP have no token budget
for it and do not. The mission's provider is wrapped in the Tap with a
budget seeded from what the session already spent; the cron TokenMeter
charges the same Budget. After each turn the advisor's usage is written
to the session tagged role advisor, so budget checks, resumes, reported
tokens and the daily cap include it.
@ajianaz
ajianaz changed the base branch from feat/advisor-tool to develop November 13, 2026 01:34
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit 04e2004 into develop Nov 13, 2026
15 checks passed
@ajianaz
ajianaz deleted the feat/advisor-wiring branch November 20, 2026 08:35
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.

feat: advisor tier — host-side consult_advisor for any provider

2 participants