$npx -y skills add WenyuChiou/agent-collab-skills --skill agent-context-budgetUse when multi-agent work risks context overflow, memory growth, noisy logs, oversized handoffs, cross-session continuation, or parallel Codex and Gemini execution.
| 1 | # agent-context-budget |
| 2 | |
| 3 | Context governor for multi-agent rounds. The core rule is simple: |
| 4 | keep `.coord/` as the canonical state, pass agents compact packets, |
| 5 | and never paste raw logs or unbounded memory into the main session. |
| 6 | |
| 7 | ## When to Use |
| 8 | |
| 9 | Use this before or during: |
| 10 | |
| 11 | - Large Codex + Gemini + Claude runs. |
| 12 | - Cross-session resumes where the prior conversation is too large. |
| 13 | - Any round with more than two delegate tasks. |
| 14 | - Any workflow where `.coord/memory.yml`, `.ai/*_log_*.txt`, or agent |
| 15 | summaries are starting to dominate the prompt. |
| 16 | |
| 17 | Not for small one-agent edits. Use the direct delegate skill instead. |
| 18 | |
| 19 | ## Default Policy |
| 20 | |
| 21 | If `.coord/plan.yml` lacks `context_policy`, add this block: |
| 22 | |
| 23 | ```yaml |
| 24 | context_policy: |
| 25 | main_session_token_budget: 3000 |
| 26 | task_packet_token_budget: 6000 |
| 27 | result_summary_word_budget: 250 |
| 28 | memory_digest_token_budget: 1200 |
| 29 | log_tail_lines_on_error: 50 |
| 30 | raw_log_policy: path-only |
| 31 | agentmemory: optional |
| 32 | |
| 33 | # W3 — $ cost gate per task (v0.2.2+) |
| 34 | # Optional. If set, agent-acceptance-gate flags any task whose |
| 35 | # codex/gemini delegate exceeded the cap. Estimated from token |
| 36 | # usage × provider price (Anthropic / OpenAI / Google rates). |
| 37 | # Set per-task in plan.yml tasks[].budget.max_cost_usd to override. |
| 38 | default_max_cost_usd: 0.50 # default $ ceiling per task |
| 39 | total_round_max_cost_usd: 5.00 # hard stop for the entire round |
| 40 | ``` |
| 41 | |
| 42 | **Why both `token` and `cost` budgets?** Token gate prevents context |
| 43 | bloat (a session quality concern). Cost gate prevents runaway delegation |
| 44 | spend (a financial concern). They're orthogonal: a 2k-token delegate |
| 45 | call can cost $0.05 (Claude Haiku) or $0.50 (Claude Opus), so token |
| 46 | count alone doesn't bound dollars. |
| 47 | |
| 48 | Per-task override example: |
| 49 | |
| 50 | ```yaml |
| 51 | # in plan.yml |
| 52 | tasks: |
| 53 | - id: T1 |
| 54 | agent: codex |
| 55 | slug: simple-refactor |
| 56 | budget: |
| 57 | max_cost_usd: 0.10 # this task is mechanical, cap low |
| 58 | - id: T2 |
| 59 | agent: codex |
| 60 | slug: complex-rewrite |
| 61 | budget: |
| 62 | max_cost_usd: 2.00 # this task needs frontier model, allow higher |
| 63 | ``` |
| 64 | |
| 65 | ## Workflow |
| 66 | |
| 67 | 1. Read `.coord/plan.yml` and `.coord/memory.yml` if present. |
| 68 | 2. Write `.coord/context_<NNN>.md` with: |
| 69 | - round goal and success criteria |
| 70 | - task graph and write ownership |
| 71 | - per-agent context packets to include |
| 72 | - context intentionally excluded |
| 73 | - optional `agentmemory` recall queries, if available |
| 74 | 3. Write or refresh `.coord/session_primer.md` with: |
| 75 | - current decisions |
| 76 | - open questions |
| 77 | - active round status |
| 78 | - recent artifacts by path |
| 79 | - no raw logs |
| 80 | 4. Enforce result packets: |
| 81 | - delegate summaries are <= 250 words |
| 82 | - changed files are listed by path |
| 83 | - tests are listed by command + result |
| 84 | - risks are explicit and short |
| 85 | 5. If a log is needed, include only the path. Read the last 50 lines |
| 86 | only when the corresponding `result.json` status is `error`. |
| 87 | |
| 88 | ## Optional agentmemory |
| 89 | |
| 90 | `agentmemory` is a recall cache, not the source of truth. |
| 91 | |
| 92 | - Query it only to enrich `.coord/session_primer.md`. |
| 93 | - Store only compact memory candidates: accepted decisions, resolved |
| 94 | open questions, artifact summaries, and final session outcomes. |
| 95 | - If it is unavailable, continue with `.coord/memory.yml` only. |
| 96 | - Never use vector recall as acceptance evidence. The acceptance gate |
| 97 | must read `.coord/plan.yml`, result files, reconciliation, and tests. |
| 98 | |
| 99 | ## Memory Promotion Rules |
| 100 | |
| 101 | Promote only: |
| 102 | |
| 103 | - Decisions with a one-sentence `what` and `why`. |
| 104 | - Open questions with a blocker and suggested next owner. |
| 105 | - Artifact pointers with one-line summaries. |
| 106 | - Agent session outcomes with status and result-summary path. |
| 107 | |
| 108 | Do not promote: |
| 109 | |
| 110 | - Raw logs. |
| 111 | - Full diffs. |
| 112 | - Source code. |
| 113 | - Long analysis. |
| 114 | - Secrets or credentials. |
| 115 | |
| 116 | ## Output |
| 117 | |
| 118 | End with: |
| 119 | |
| 120 | ```text |
| 121 | [agent-context-budget] |
| 122 | Round: <N> |
| 123 | Policy: .coord/plan.yml context_policy |
| 124 | Context plan: .coord/context_<NNN>.md |
| 125 | Session primer: .coord/session_primer.md |
| 126 | Raw logs: path-only; failure tail max 50 lines |
| 127 | agentmemory: optional cache, not required |
| 128 | ``` |
| 129 | |
| 130 | ## Common Mistakes |
| 131 | |
| 132 | - Pasting full logs into chat. Store the path; read bounded tail only |
| 133 | on failure. |
| 134 | - Treating memory as a transcript. Promote decisions, questions, |
| 135 | artifacts, and outcomes only. |
| 136 | - Giving Gemini only `.ai/` paths. Inline critical context because |
| 137 | `.ai/` may be gitignored. |
| 138 | - Using agentmemory as the gate. Gate with tests and `.coord/` |
| 139 | artifacts. |
| 140 | |
| 141 | ## Subagent review (keep main session lean) |
| 142 | |
| 143 | **When**: ≥ 3 task packets exist and you want to verify they stayed |
| 144 | within the declared `task_packet_token_budget` (default 6000 tokens |
| 145 | ≈ 24 KB) without re-reading them all in the main session. |
| 146 | |
| 147 | **Why**: After writing `.coord/context_<NNN>.md` + `session_primer.md`, |
| 148 | the main session has the policy in context but doesn't need to re-read |
| 149 | every packet to verify compliance. A subagent can scan all packets |
| 150 | and return |