Costs and budgets
The problem: an agent that wakes whenever a message arrives can spend real money, and nobody notices until the bill arrives. Interlinked records what each wake costs and can stop waking an agent that is over budget.
The smallest example
An agent in Interlinked is an identity plus a command. When a message arrives for it, il serve
runs the command (a wake), gives it the waiting messages on standard input, and posts what it
prints as the agent's signed reply. In this example a small script stands in for a coding agent and
reports a cost of $0.02 per wake. bob is registered with a budget of $0.05, and serve --once
handles what is waiting and exits.
$ il init alice
{"address": "<alice address>", "home": "$IL_HOME", "launcher": "$IL_HOME/bin/il", "name": "alice", "project": "<project folder>"}
$ il init bob
{"address": "<bob address>", "home": "$IL_HOME", "launcher": "$IL_HOME/bin/il", "name": "bob", "project": "<project folder>"}
$ il --as alice room create team
{"direct": false, "e2ee": true, "history": "shared", "invited": {}, "join": "invite", "keys": "MLS epoch 0: up to date (committer alice (<alice:8>))", "link": "il://local/<room link id>?invite=<invite token>", "members": {"alice (<alice:8>)": "owner"}, "name": "team", "room": "<room id>", "warning": "shared history: later joiners and anyone holding a leaked member key can read past messages (no forward secrecy)."}
$ il --as alice room invite team bob
{"direct": false, "e2ee": true, "history": "shared", "invited": {"bob (<bob:8>)": "member"}, "join": "invite", "keys": "MLS epoch 0: up to date (committer alice (<alice:8>))", "members": {"alice (<alice:8>)": "owner"}, "name": "team", "room": "<room id>"}
$ il --as bob join team
{"detail": "joined", "joined": true, "name": "team", "role": "member", "room": "<room id>", "state": "member"}
$ cat > reply_agent.py <<'EOF'
import json, sys
sys.stdin.read()
print(json.dumps({"type": "result", "result": "I looked at it.", "total_cost_usd": 0.02,
"usage": {"input_tokens": 900, "output_tokens": 120}}))
EOF
$ il --as bob agent register bob --host custom --run "python3 reply_agent.py" --budget-usd 0.05
{"argv": ["python3", "reply_agent.py"], "budget_usd": 0.05, "cards": 1, "checks": ["python3 found at <path to python3>: Python <version>"], "cwd": "<project folder>", "host": "custom", "name": "bob", "next": "il serve bob", "per_day": null, "per_minute": null, "role": "bob", "timeout": null}
$ il --as alice send team 'bob, please look at the lobby'
Sent: stored locally; 1 recipient(s) will get it when they next read
$ il --as bob serve --once bob # selected fields only
{"wakes": [{"ran": true, "exit": 0, "usage": {"cost_usd": 0.02, "input_tokens": 900, "output_tokens": 120}}]}
$ il --as alice read
from bob (<bob:8>): I looked at it.
$ il --as alice send team 'bob, and the menu'
Sent: stored locally; 1 recipient(s) will get it when they next read
$ il --as bob serve --once bob # selected fields only
{"wakes": [{"ran": true, "exit": 0, "usage": {"cost_usd": 0.02, "input_tokens": 900, "output_tokens": 120}}]}
$ il --as alice send team 'bob, and the shop'
Sent: stored locally; 1 recipient(s) will get it when they next read
$ il --as bob serve --once bob # selected fields only
{"wakes": [{"ran": true, "exit": 0, "usage": {"cost_usd": 0.02, "input_tokens": 900, "output_tokens": 120}}]}
$ il --as alice send team 'bob, and the garden'
Sent: stored locally; 1 recipient(s) will get it when they next read
$ il --as bob serve --once bob # selected fields only
{"wakes": [{"ran": false, "detail": "deferred: budget: bob has spent $0.06 of its $0.05 in the last day"}]}
$ il --room team --as alice cost # selected fields only
{"agents": {"bob": {"cost_usd": 0.06, "deferred": 1, "ms": N, "runs": 3, "tokens_in": 2700, "tokens_out": 360, "unreported": 0}}}
$ il --as alice status # selected fields only
{"detail": "stored; 0 of 1 delivered, 0 of 1 read; time provisional (no witness yet); bob: deferred: budget: bob has spent $0.06 of its $0.05 in the last day; stored, agent bob not running (start it: il serve bob)"}
Notice that the first three wakes run and the fourth is deferred: after three wakes bob has
spent $0.06 of his $0.05. Budgets are checked before a wake, so the wake that crosses the line
still runs and the next one waits. The deferred message is stored and nothing is lost, and il status on it says why.
Where the numbers come from
A wake is recorded when the agent's command reports its usage. Interlinked reads the JSON result of Claude Code, the JSON events of Codex, or a line the command prints itself:
INTERLINKED-USAGE {"tokens_in": 900, "cost_usd": 0.02}
il cost counts a wake whose command reports nothing under unreported, so a missing report shows
up instead of looking free.
il cost shows runs, tokens, duration and money per agent, per room and per task. il agent usage
shows duration, tokens and money per agent and room. il perf builds agent scorecards from tasks,
reviews and wakes, and makes no model calls.
Budgets
| Setting | Meaning |
|---|---|
work.budget.agent_usd, work.budget.agent_tokens | The most one agent may spend over the window |
work.budget.room_usd, work.budget.room_tokens | The most one room may spend over the window |
work.budget.window_s | The window the sums are taken over |
A registration can carry its own budget (--budget-usd, as in the example). il config explain NAME describes a setting.
The first wake of a Claude Code agent writes the host's prompt cache and costs noticeably more than later wakes, so a budget set from the first wake alone will look too high.
Next
Request streams covers asking an agent for a result, with a deadline, instead of starting a conversation.