Token economics: see, bound, and prove what a run costs its own context window - #111
Merged
Merged
Conversation
…own context window and act on it. Adds a pre-act sub-agent dispatch gate over declared backend pools, efficiency actuators independent of window room, split SessionStart writers with per-session mail delivered-state and identity parity gates, generation telemetry with band and compare verbs, grader visibility of harness interventions, a watchdog latch and alarm terminus, dispatcher crons, mergepatrol merge authority, and formula, skill, doc, and test hardening. Closes #110.
|
agentfactory seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
This was referenced Sep 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This change gives the factory an accounting of what each run costs its own context window, and a policy surface that acts on it. Constrained local backends stop wedging under parallel sub-agents, session start stops silently dropping mail and memory, the grader and watchdog stop punishing agents for doing what the harness told them, and there is one verb that can say whether a change actually helped.
Closes #110
What you get
Sub-agents can no longer starve their orchestrator on a shared backend. Declare the backend's shared pool size on a model profile, and a sub-agent launch that would oversubscribe it is refused before it starts, with the arithmetic shown to the agent. Cloud profiles are untouched: with no pool declared, refusal is impossible by construction. A strict one-at-a-time mode holds the slot for the child's whole lifetime, survives crashes and teardowns, and admits exactly one contender when the slot frees.
Efficiency works on every profile, not just cramped ones. A step that historically generates more than it needs gets a reduced effort level on its next session, chosen from history rather than from remaining room, never above what the profile declared, and bounded so a run cannot spend itself relaunching. Self-edits from the improvement loop are checked so a formula cannot buy tokens by deleting a gate.
Session start delivers everything, every time. Formula context, mail, and memory each get their own budget, so a large step body can no longer evict your mail. Identity comes from the agent's own
CLAUDE.md, re-rendered at every provisioning site and held byte-equal to its template by a test. Each message reaches a session once; later prompts stop re-injecting the whole mailbox.You can tell whether a run was normal, and whether a change helped. Every closed step records what it generated (output, thinking, peak, sub-agent spend) beside its timing, with unmeasured figures as null rather than zero.
af telemetry bandjudges each step against learned medians and prints the band it used.af telemetry compareis the one verb allowed to claim an improvement, over two arms of five runs, and voids rather than fails when the arms were not held constant.af telemetry rebuildkeeps learned data alive across record rotation.af tokenomics statusnames every reason the surface is inert. Off is the default; turning it off is operator-only.The harness stops fighting itself. The fidelity grader is shown every intervention taken during a turn and grades compliance as compliant. Grader sub-processes no longer fire the agent's hooks or take its session id. The watchdog does not recycle an agent that was told to wait. Halted breakers, dark channels, and a dead watchdog show on the pane, in
af statusline status, and ataf up, whether or not the escalation mail ever arrived.Recurring work without a triggering issue.
dispatch.jsonaccepts acronslist of name, agent, cadence, and vars. Schedules survive restarts, back off with a bound, are validated against the target formula at write time, fire without GitHub access, and appear inaf dispatch status.mergepatrol trusts GitHub, not local git. A PR counts as merged only when GitHub says so. The formula never closes a PR itself or pushes a local landing, and a test fails if those semantics are edited away.
Formulas and skills learned from measured runs. design-plan-impl must justify every phase beyond what the design narrates. design-v7 builds its snapshot by redirection, cites true source lines, and never stashes or checks out in a shared worktree. fable-increment and fable-review cope with shared stash stacks and harnesses that lack
run_in_background. improve-agent gains an efficiency review. Two new skills: improve-solution propagates design decisions into derived docs, and perfeval-agent finds an agent's single highest-impact cost from telemetry.Also in this change
USING_TOKENOMICS.md; updates toUSING_AGENTFACTORY.md,USING_TELEMETRY.md,USING_MODELS.md, andUSING_MEMORY.md; a new ADR on the session-start context surface and an amendment to the hooks-never-block ADR enumerating the one gate that may refuse.Notes for review
.agentfactory/agents/were not regenerated in this commit, soTestDeployedAgentIdentityMatchesEmbeddedTemplateandTestDeployedAgentSettingsMatchEmbeddedTemplatefail for all 26 agents untilaf install --initis run and the result committed. Every other root and web test passes.USING_TELEMETRY.mdand two code comments still say nothing reads the learned digest.af telemetry bandand the admission predicate do read it.af uporaf install --initso the split SessionStart entries are in place; a stale single-entrysettings.jsonputs three concatenated JSON objects on one stdout.🤖 Generated with Claude Code