Reduce AI token usage across planner/implementer/verifier/reviewer runs
Maintainers usually reply within 6 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 15/100
- Issue type
- Refactor
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- javascript
- Domain
- devtools, performance
Research direction
This is an umbrella design issue spanning handoff, memory injection and measurement in bundle/hooks/lib/handoff-enforcer.js, bundle/hooks/lib/token-tracker.js and bundle/hooks/orchestra-subagent-stop.js. Read token-tracker.js first to see how estimateTokens and AGENT_BUDGETS work, then the handoff builder. A newcomer should pick the linked sub-task #41 (per-stage token logging) instead; done for this issue means a recorded baseline, an agreed target, and the listed acceptance criteria met.
Written by the indexing model from the issue text.
Description
Summary
Reduce AI token usage across planner → implementer → verifier → reviewer runs without losing quality. Today the budgets are 10k/30k/15k/8k (≈63k per cycle) but the only measurement is a rough estimate of output size, and there is no caching or summarisation layer for repeated reads.
Where tokens go today (grounded in code at v3.8.0)
- Handoff:
bundle/hooks/lib/handoff-enforcer.js—MAX_HANDOFF_CHARS = 2500,HANDOFF_RULES("pass only goal + plan summary + failures"),buildPhaseHandoffincludes last 3 phase summaries (120 chars each).bundle/hooks/orchestra-subagent-stop.js:~520-548then adds evidence digest, commit-gate block, work-item context and six-file validation to the payload (buildHandoffEnforcement,spawnSubagent). - Memory injection:
bundle/hooks/orchestra-prompt.js:279-280,orchestra-session-start.js:72,orchestra-memory.js:~14-25each inject memory context independently. - Six-file context:
bundle/hooks/lib/context-detector.js(buildContextInjection) tells every agent to read sixcontext/*.mdfiles in order. - Measurement:
bundle/hooks/lib/token-tracker.js—estimateTokens= chars/4 (L70-73) onsummary/result/outputtext only; reported usage (extractReportedUsage, cache-read tokens) used only if the host exposes it; budgetsAGENT_BUDGETS/CYCLE_BUDGET(L14-21).
Proposed work
- Trim handoff context — send only what the next stage needs (e.g. plan bullets + failing check output), de-duplicate against what memory/six-file injection already provided.
- Cache repeated lookups — file reads, searches and memory recall within a run (and across runs when files are unchanged, keyed by path+mtime/hash). Candidate: a small per-run cache in the state dir (
PCORE_STATE_DIR). - Summarise long outputs before handoff — cap evidence/test output (e.g. keep failing assertions + last N lines), store the full log on disk and pass a path.
- Diffs instead of full files — verifier/reviewer receive
git diff <diffBase>(the run already recordsstate.diffBaseinevidence-runner.js) plus file paths, not whole files. - Per-stage measurement — record input and output tokens per stage with a baseline for a fixed set of sample tasks and a target (e.g. −25% total tokens per cycle at equal pass rate).
- Report — extend
printTokenReportto show per-stage input/output, cache-hit rate and savings vs baseline.
Host notes
Hook-driven hosts (Cursor, Qoder, Claude Code) can measure at subagentStop; OpenCode and Codex are conductor-driven so measurement relies on what the host reports (document the fallback to estimates).
Acceptance criteria
- Baseline numbers (tokens per stage and per cycle) for ≥3 sample tasks are recorded in
docs/orcontext/. - A target is agreed and documented; CI or a script reports against it.
- Handoff payload size is measured and reduced;
MAX_HANDOFF_CHARSenforced by a test. - Repeated file reads/searches/memory recall in one run hit a cache (tests for hit/miss/invalidations).
- Long outputs are summarised with full log stored on disk and referenced.
- Verifier/reviewer use diffs against
diffBase. - No regression in the existing suites (
test-adaptive-loop.js, handoff, evidence).
Beginner sub-task
Per-stage token logging is split out as its own good first issue (linked below).
Raised from the v3.8.0 audit (commit 22d2146).
Beginner sub-task: #41 (per-stage token logging).
- Dominant language
- JavaScript
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from P-Core-System/pcore-orchestra
-
documentation good first issue priority: medium
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
P-Core-System/pcore-orchestra#37 ·
Maintainers usually reply within 6 days
-
documentation good first issue priority: low
Difficulty 1/5 1-3 hours Newbie friendliness 72/100
P-Core-System/pcore-orchestra#36 ·
Maintainers usually reply within 6 days
-
documentation good first issue priority: low
Difficulty 1/5 1-3 hours Newbie friendliness 84/100
P-Core-System/pcore-orchestra#35 ·
Maintainers usually reply within 6 days
-
documentation good first issue priority: medium
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
P-Core-System/pcore-orchestra#33 ·
Maintainers usually reply within 6 days
-
enhancement good first issue installer priority: low
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
P-Core-System/pcore-orchestra#20 ·
Maintainers usually reply within 6 days
All issues in P-Core-System/pcore-orchestra
Similar issues
-
Administration: required plugin configuration field stays invalid after restoring its saved valueOpenneeds-triage Platform(Default)
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
nearform/ag-grid-url-sync#314 · 1 reaction ·
Maintainers usually reply within 1 day
-
chore
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
idean3885/claude-ops-agent#910 ·
Maintainers usually reply within 1 day
-
S: triage
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
oskarrough/agent-ide#29 · 1 comment ·
Maintainers usually reply within 1 day