llm-broker
AGENTS.md2 starsChanged 2 days agoMITView on GitHub
This file is for LLM agents working in this repo. The project is not a bag of Codex/Codex special cases. It is a small LLM account orchestration kernel. The design center is: The core execution law is: The state law is: Read this literally: This is a synchronous state-machine core with an event side channel. It is not an event-driven core. 1. Provider details must terminate at driver.Driver. pool, relay, server, and store should not learn provider-specific headers, body shapes,…
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 35,337 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository6 other files it gives its agents.
- .claude/CLAUDE.mdCLAUDE.md
- cellsSkill
- deploySkill
- model-alignSkill
- cellsSkill
- deploySkill
The file
We split this AGENTS.md into the rules it gives an agent
10 rules. About 0 are common, 5 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 65
Do not store duplicate state.
- Very specific: line 66
If status, cooldown_until, and driver.CanServe(...) determine availability, do not add shadow booleans like the old schedulable.
- Distinctive: line 69
Do not grow public schema columns for provider-specific utilization windows or reset fields.
- Very specific: line 72
Keep identity_json and provider_state_json conceptually separate: identity_json answers "who is this account?" provider_state_json answers …
- Distinctive: line 101
If a provider change requires touching many core packages, the boundary is regressing.
- Very specific: line 171
If you find yourself editing pool because a provider has a different header name, stop.
- Distinctive: line 179
add fallback layers that duplicate current truth
- Distinctive: line 182
add UI knobs for redundant state that should not exist
- Very specific: line 203
If provider-specific, can it live entirely in driver?
- Distinctive: line 208
If the answer to 2 is "no" or to 3-5 is "yes", rethink the change.
≈ “Common” is an estimate: at least 1 in 5 of the 45,344 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
broker
This file is for LLM agents working in this repo.
Essence
The project is not a bag of Codex/Codex special cases. It is a small LLM account orchestration kernel.
The design center is:
provider is the change axis
core is the stable axisThe core execution law is:
Relay(req, drv) =
retry(N) {
a <- pool.Pick(drv, exclude, model, boundSession)
t <- tokens.Ensure(a)
u <- drv.BuildRequest(req, a, t)
r <- upstream(u)
e <- drv.Interpret(r)
pool.Observe(a, e)
surface.Write(drv, r)
}The state law is:
identity(account) = (provider, subject)
available(account, model, now) =
status == active
AND cooldown_until <= now
AND drv.CanServe(provider_state_json, model, now)
next_state = Observe(current_state, effect)Read this literally:
driverowns provider protocol.poolowns generic account state transitions.relayowns the execution pipeline.tokensowns token freshness.eventsare observability only, not source of truth.
This is a synchronous state-machine core with an event side channel. It is not an event-driven core.
Non-Negotiable Invariants
- Provider details must terminate at
driver.Driver.pool,relay,server, andstoreshould not learn provider-specific headers, body shapes, ban strings, or rate-limit parsing rules. pool.Observe()is the single semantic write entrance for provider outcomes. Effects enter there; state transitions happen there.- Real account identity is
UNIQUE(provider, subject).emailis display data only. Never deduplicate or bind by email. - Do not store duplicate state.
If
status,cooldown_until, anddriver.CanServe(...)determine availability, do not add shadow booleans like the oldschedulable. - Provider-owned state stays in
provider_state_json. Do not grow public schema columns for provider-specific utilization windows or reset fields. - Durable provider identity metadata stays in
identity_json. Keepidentity_jsonandprovider_state_jsonconceptually separate:identity_jsonanswers "who is this account?"provider_state_jsonanswers "what is this account's current provider-specific runtime state?" - Database migration is explicit.
Startup should not silently rewrite schema. Use
llm-broker migrate.
Architectural Boundary
What belongs in a driver:
- OAuth generation and code exchange
- token refresh request semantics
- upstream request construction
- response interpretation into
driver.Effect - streaming and non-stream response handling
- probe semantics
- model catalog
- provider-specific utilization math
- provider-specific account presentation fields
What does not belong in core:
if provider == ...branches for protocol behavior- provider-specific rate-limit headers in
pool - provider-specific JSON parsing in
server - provider-specific model catalogs hardcoded in
server - provider-specific schema columns in
domain.Account
If a provider change requires touching many core packages, the boundary is regressing.
The Correct Mental Model
Think in compiler terms:
provider protocol -> driver.Interpret -> Effect -> pool.Observe -> account statedriver.Effect is the IR between unstable upstream behavior and stable core semantics.
The core should only care about things like:
- success
- cooldown
- overload
- block
- auth failure
- updated provider state
The core should not care how any provider expressed those facts.
Schema Aesthetic
The schema should encode the fewest truths necessary.
Good:
idprovidersubjectemailstatusprioritypriority_modecooldown_until- encrypted tokens
- timestamps
identity_jsonprovider_state_json
Bad:
- provider-specific columns for rate limits
- duplicate booleans derivable from existing state
- compatibility debris kept after migration is over
The project prefers fewer states over more defensive code.
Route Truths
These are intentional and should not drift casually:
- UI lives at
/and/dashboard - onboarding lives at
/add-account/{provider} /add-accountwithout a provider should 404/ui/*should 404GET /v1/modelsis authenticated- relay paths are registered from driver metadata, not hardcoded server constants
Extension Rule
Adding a provider should look roughly like:
- implement
driver.Driver - register it in
cmd/relay/main.go - expose provider metadata through
Driver.Info()andDriver.Models() - reuse existing
pool,relay,server,tokens, andstore
If you find yourself editing pool because a provider has a different header name, stop. The driver abstraction is being violated.
Review Heuristics
Reject or challenge changes that:
- reintroduce provider conditionals into core packages
- deduplicate accounts by email or mutable metadata
- add fallback layers that duplicate current truth
- rebuild provider state from old legacy fields after migration is complete
- make events/logs authoritative for runtime state
- add UI knobs for redundant state that should not exist
Prefer changes that:
- delete invalid states
- tighten the provider boundary
- make
drivermore complete and core more ignorant - reduce cross-package knowledge
- improve rollback safety without preserving dead runtime compatibility
Operational Truths
- The project relies on VPS snapshots and
restore.shfor rollback safety. - A failed deploy should be recoverable with
bash .Codex/skills/deploy/scripts/restore.sh latest. - That safety net exists so the code can stay clean; it is not permission to leave permanent compatibility clutter in the runtime path.
Short Checklist Before You Edit
Ask:
- Is this change about stable orchestration semantics or provider-specific protocol?
- If provider-specific, can it live entirely in
driver? - Am I introducing duplicate state?
- Am I violating
identity(account) = (provider, subject)? - Am I making core understand something it should merely consume as
Effect?
If the answer to 2 is "no" or to 3-5 is "yes", rethink the change.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

