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

CallerHeaderCan
service keyAuthorization: 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 linkthe signed link in a Slack message or emailapprove 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

shell
# 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 it

name: 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
intentwhat the run will do, in a sentence. Reviewers read it.
ttl_secondshow long the world lives (at most agents.run_ttl_s)
metaany JSON you want kept with the run
agentwith the service key: whose run it is
policywith 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:

shell
psql "$DATABASE_URL" -c "update tickets set status = 'closed' where updated_at < now() - interval '90 days'"

Work: POST /runs/{id}/sql

JSON
{"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

viewAnswer
rows (default)changes: the inserted, updated and deleted rows, per table (limit rows per table, default 200, at most 1000)
summarytotal, tables, summary: counts only
sqlsql: 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

HTTPBodyMeaning
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

RouteWho
GET /runs?status=&limit=service, agentruns, newest first; an agent sees its own
GET /runs/{id}service, agent, runone run, with its outcome
POST /runs/{id}/discardservice, agent, runthrow the world away
POST /runs/{id}/approveservicemerge a held run, exactly what was held
POST /runs/{id}/rejectservice{"reason": "..."}; nothing merges
POST /runs/{id}/undoserviceput 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).

TOML
# 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"]
TOML
# 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.

RuleValueHolds a merge when
max_rowsnumberit changes more rows than this
max_deletesnumberit deletes more rows than this
rows_per_hournumberthe agent's merges changed more rows than this in the last hour, this one included
deletes_per_hournumberthe same, for deletes
confirm_deletes_overnumberit deletes more than this; the approver must confirm the count
max_age"1h", "30 minutes"the run was forked longer ago than this
tableslist of tablesit changes a table not in the list
review_tableslist of tablesit changes any table in the list
review_columnslist of table.columnit changes any of these columns, even in one row
schematrue/false (default false)false and it changes a table's shape, a view, function, sequence, schema or type
overwritetrue/false (default false)false and it overwrites rows changed in the data since the fork
criticaltrue/false (default false)false and it changes a column marked critical in the engine
check_readstrue/false (default false)true and rows it read changed since the fork (it decided on state that's gone)
max_effectsnumberit queues more side effects than this
effects_per_hournumberthe agent's merges queued more effects than this in the last hour
review_channelslist of channelsit 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:

  1. The dashboard: Agents, Approvals. Each held run with its intent, reasons, rows, SQL and counts.
  2. Slack: set agents.slack_webhook_url (or FORKBASE_SLACK_WEBHOOK_URL) to an incoming-webhook URL.
  3. 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.

EventWhen
run.createda run started
run.mergeda run's changes reached the data
run.helda policy held a run
run.conflicta proposal hit a conflict
run.rejecteda person rejected a held run
run.discarded, run.expireda world was thrown away
run.undonea merged run was undone
effect.<channel>a side effect a merge queued, delivered after the merge landed
job.succeeded, job.faileda job ended (see Jobs)

Subscribe a URL:

shell
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:

text
forkbase-signature: t=1733140000,v1=<hex HMAC-SHA256 of "<t>.<raw body>" with the whsec_ secret>

Check it before trusting a delivery:

TypeScript
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 public tables 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.merged events instead.

Something wrong or missing? Edit this page on GitHub or open an issue.

Agents · Forkbase