Agents
Runs, merge policies as code, approvals, webhooks and events, and undo of any merge.
/agents/v1 lets AI agents change real data safely. Read Concepts first for runs, worlds and
policies.
Agents need the Chronos engine. In postgres mode without it, Forkbase starts with agents off (the log says agents are off), /agents/v1 is not served, and the rest works.
Who may call what
| Caller | Header | Can |
|---|---|---|
| service key | Authorization: Bearer <service_role> | everything: make agents, see every run, approve, reject, undo, webhooks |
agent token fba_ | Authorization: Bearer fba_... | start runs as that agent, list and read its own runs |
run token fbr_ | Authorization: Bearer fbr_... | sql, changes, propose, discard on that one run |
| approval link | the signed link in a Slack message or email | approve or reject that one held run |
Only the service key and approval links approve, reject and undo. An agent can never approve its own work.
Agents
# make one; the token is shown once
curl -X POST $URL/agents/v1/agents -H "authorization: Bearer $SERVICE" -H "content-type: application/json" \
-d '{"name": "support_bot", "policy": "careful"}'
# 201 {"id": "...", "name": "support_bot", "policy": "careful", "token": "fba_..."}
curl $URL/agents/v1/agents -H "authorization: Bearer $SERVICE" # {"agents": [...]}
curl -X DELETE $URL/agents/v1/agents/support_bot -H "authorization: Bearer $SERVICE" # disables itname: letters, digits and _, up to 63. policy: a policy's name; none means agents.default_policy. A disabled
agent's token stops working.
Runs
Start: POST /runs
| Field | |
|---|---|
intent | what the run will do, in a sentence. Reviewers read it. |
ttl_seconds | how long the world lives (at most agents.run_ttl_s) |
meta | any JSON you want kept with the run |
agent | with the service key: whose run it is |
policy | with the service key: a policy for this run instead of the agent's |
act_as | {"user_token": "<a signed-in person's access token>"}: row-level security judges the run's reads and writes as that person's |
Answers 201 with the run: id, status, agent, intent, world, token (fbr_, shown once) and
database_url.
database_url is a plain Postgres URL to the run's world. Anything that speaks Postgres works there:
psql "$DATABASE_URL" -c "update tickets set status = 'closed' where updated_at < now() - interval '90 days'"Work: POST /runs/{id}/sql
{"sql": "update carts set closed = true where id = $1", "params": [42]}One statement per call, $1-style parameters. Answers {"columns": [...], "rows": [[...]], ...}. Reads see the
data as of the fork plus the run's own writes.
Check: GET /runs/{id}/changes
view | Answer |
|---|---|
rows (default) | changes: the inserted, updated and deleted rows, per table (limit rows per table, default 200, at most 1000) |
summary | total, tables, summary: counts only |
sql | sql: the statements that would replay the change |
Always read the changes before proposing: it's what a person will review.
Propose: POST /runs/{id}/propose
| HTTP | Body | Meaning |
|---|---|---|
| 200 | {"status": "merged", ...} | in the data now |
| 202 | {"status": "held", "reasons": [...]} | a person decides; nothing changed yet |
| 409 | {"code": "conflict", "message": ..., "conflicts": [...]} | rows changed under the run; start a new run. code is stale_reads when the policy has check_reads and rows the run read changed |
The rest
| Route | Who | |
|---|---|---|
GET /runs?status=&limit= | service, agent | runs, newest first; an agent sees its own |
GET /runs/{id} | service, agent, run | one run, with its outcome |
POST /runs/{id}/discard | service, agent, run | throw the world away |
POST /runs/{id}/approve | service | merge a held run, exactly what was held |
POST /runs/{id}/reject | service | {"reason": "..."}; nothing merges |
POST /runs/{id}/undo | service | put back what a merged run changed; {"skip_changed": true} leaves rows changed since |
Undo refuses (409) a run that isn't merged, and in postgres mode a run that merged before the engine was attached
again (reattached).
Policies as code
Write one file per policy in agents.policies (default policies/ beside forkbase.toml). The file name is the
policy name. Forkbase applies every file when it starts: new files make policies, changed files change them, and a
rule removed from a file is removed from the policy. Policies the engine has that no file names are left alone.
The dashboard's Agents, Policies page edits the same files: saving writes <name>.toml and applies it at once (a
file the engine refuses is put back as it was), and Try checks an open or held run's world against the text in
the editor without merging anything. From a server: PUT /agents/v1/policies/<name> {"toml": "..."},
POST /agents/v1/policies/check {"run": "<id>", "toml": "..."} (or "name" for a policy as it is), and
DELETE /agents/v1/policies/<name> (not the default policy, nor one an agent keeps to).
# policies/support.toml: a support bot fixing tickets
tables = ["tickets", "ticket_notes"] # it may change nothing else
max_rows = 20
max_deletes = 0
review_columns = ["tickets.assignee"]# policies/money.toml: an agent near payments
max_deletes = 0
review_tables = ["payments", "refunds", "payouts"]
check_reads = true
max_age = "30m"Policy rules
A merge that breaks any rule is held for a person. A rule left out doesn't limit.
| Rule | Value | Holds a merge when |
|---|---|---|
max_rows | number | it changes more rows than this |
max_deletes | number | it deletes more rows than this |
rows_per_hour | number | the agent's merges changed more rows than this in the last hour, this one included |
deletes_per_hour | number | the same, for deletes |
confirm_deletes_over | number | it deletes more than this; the approver must confirm the count |
max_age | "1h", "30 minutes" | the run was forked longer ago than this |
tables | list of tables | it changes a table not in the list |
review_tables | list of tables | it changes any table in the list |
review_columns | list of table.column | it changes any of these columns, even in one row |
schema | true/false (default false) | false and it changes a table's shape, a view, function, sequence, schema or type |
overwrite | true/false (default false) | false and it overwrites rows changed in the data since the fork |
critical | true/false (default false) | false and it changes a column marked critical in the engine |
check_reads | true/false (default false) | true and rows it read changed since the fork (it decided on state that's gone) |
max_effects | number | it queues more side effects than this |
effects_per_hour | number | the agent's merges queued more effects than this in the last hour |
review_channels | list of channels | it queues an effect on one of these channels |
The default policy, agents.default_policy (forkbase_default), is made with max_deletes = 0 unless a file of that
name says otherwise. GET /agents/v1/policies (service key) lists every policy with its rules.
In chronos mode every policy also lists Forkbase's own tables in review_tables, and Forkbase never approves those
holds: agents cannot change sign-ins, files or other agents behind your back.
Approvals
A held run reaches people three ways:
- The dashboard: Agents, Approvals. Each held run with its intent, reasons, rows, SQL and counts.
- Slack: set
agents.slack_webhook_url(orFORKBASE_SLACK_WEBHOOK_URL) to an incoming-webhook URL. - Email: list addresses in
agents.approver_emails. Uses the auth email settings.
Slack messages and emails carry a signed link to a page (/agents/v1/approvals/{token}) that shows the rows and
has Approve and Reject buttons. A link works only for its run, only while the run is held.
A held run that nobody decides within agents.hold_ttl_s (seven days) is discarded.
Webhooks and events
Everything that happens to a run is an event. GET /agents/v1/events (service key) lists them.
| Event | When |
|---|---|
run.created | a run started |
run.merged | a run's changes reached the data |
run.held | a policy held a run |
run.conflict | a proposal hit a conflict |
run.rejected | a person rejected a held run |
run.discarded, run.expired | a world was thrown away |
run.undone | a merged run was undone |
effect.<channel> | a side effect a merge queued, delivered after the merge landed |
job.succeeded, job.failed | a job ended (see Jobs) |
Subscribe a URL:
curl -X POST $URL/agents/v1/webhooks -H "authorization: Bearer $SERVICE" -H "content-type: application/json" \
-d '{"url": "https://example.com/hooks/forkbase", "events": ["run.held", "run.merged"]}'
# 201 {"id": "...", "url": "...", "events": [...], "secret": "whsec_..."}events takes names, run.*, effect.* or *. GET /webhooks lists, DELETE /webhooks/{id} removes.
Every delivery is a JSON POST signed in a forkbase-signature header:
forkbase-signature: t=1733140000,v1=<hex HMAC-SHA256 of "<t>.<raw body>" with the whsec_ secret>Check it before trusting a delivery:
import { createHmac, timingSafeEqual } from "node:crypto";
function verify(body: string, header: string, secret: string) {
const { t, v1 } = Object.fromEntries(header.split(",").map((p) => p.split("=")));
if (Math.abs(Date.now() / 1000 - Number(t)) > 300) return false; // older than 5 minutes
const want = createHmac("sha256", secret).update(`${t}.${body}`).digest("hex");
return timingSafeEqual(Buffer.from(want), Buffer.from(v1));
}A failed delivery (not 2xx) is retried with backoff.
Side effects that wait for the merge
An agent's world can queue a side effect (an email, a payment call) with the engine's NOTIFY ON MERGE. It is sent
as an effect.<channel> event only once the merge lands, never for a run that was held and rejected or discarded.
max_effects, effects_per_hour and review_channels put effects under policy too.
Postgres mode details
- The engine attaches to your
publictables that have a primary key, at the first run. - It refreshes its copy from Postgres every
agents.refresh_every_s(60 s). - A merge is written back to Postgres in one transaction, checked against the rows as they are now.
- A table made later is picked up by attaching again, once no run is open. Runs merged before a re-attach can't be undone.
- Tables without a primary key are invisible to agents.
Chronos mode details
- Agents read Forkbase's own tables (
auth,storage,agents,jobs,mcp) masked, and every change to them is held for a person, who Forkbase never stands in for. - Merges can be undone for
agents.undo_window("7 days"). - Table triggers and realtime don't see merged rows: react to
run.mergedevents instead.
Something wrong or missing? Edit this page on GitHub or open an issue.