Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Document Cloudflare Workers AI on the decision model page

Ousmane Touré821b02f7339b
diff --git a/README.md b/README.md
index 1c6526756d..78762a3d38 100644
--- a/README.md
+++ b/README.md
@@ -183,7 +183,7 @@ channel and its bots under a named context, then rename it or change its members
### ⚡ Fast decisions with Jev
-Add a TypeSafe Jev key, or an OpenRouter key and model, in **Settings → Decision model** and rooms set to **Auto** pick the bot
+Add a Cloudflare Workers AI token, a TypeSafe Jev key, or an OpenRouter key and model, in **Settings → Decision and extraction** and rooms set to **Auto** pick the bot
that fits each un-mentioned message in a few hundred milliseconds, falling back to the room's lead whenever the decision model is off or unsure.
See [docs/decision-model.md](docs/decision-model.md).
diff --git a/docs/cloud-pro.md b/docs/cloud-pro.md
index 39e9e722d0..0c74b7613f 100644
--- a/docs/cloud-pro.md
+++ b/docs/cloud-pro.md
@@ -1420,11 +1420,11 @@ computers belong to this machine on every request.
decision-model failure. Any other decision job, now or added later, uses
only the person's own Jev key until the relay accepts it too. The relay
speaks Jev's API only: included decisions are Jev's, and with OpenRouter
- selected in **Settings → Decision model** nothing is included (it needs an
+ selected in **Settings → Decision and extraction** nothing is included (it needs an
OpenRouter key: one saved there, or the one under **Settings → API keys**).
- **Included decisions are on until switched off.** While the decision model
runs on the included token, its master switch counts as on unless the person
- switched it off in **Settings → Decision model**; an explicit off always
+ switched it off in **Settings → Decision and extraction**; an explicit off always
wins, and switching it back on needs no key. The per-job switches keep their
defaults, so rooms set to Auto ask who answers, and new rooms start on Auto,
as with a saved key. An own Jev key is on once saved, as anywhere else, and
diff --git a/docs/decision-model.md b/docs/decision-model.md
index 47c7808b2e..c560c3435f 100644
--- a/docs/decision-model.md
+++ b/docs/decision-model.md
@@ -2,16 +2,47 @@
OpenMausBot can use a fast decision model to pick things for your bots. It
answers in a few hundred milliseconds for a fraction of a cent. It never does
-the work: the chosen bot still runs its own turn on its own engine. Two
-providers are supported: TypeSafe's [Jev](https://typesafe.ai) (the default)
-and a model of your choice on [OpenRouter](https://openrouter.ai).
-
-Everything is in **Settings → Decision model**: the provider, for OpenRouter
-the model, one master switch, that provider's key with **Save** and **Test**,
-and one switch per job it can do. Each provider keeps its own key, so you can
-switch between them without pasting a key again. OpenRouter needs no key here
-when you already saved one under **Settings → API keys**: the decision model
-uses that one.
+the work: the chosen bot still runs its own turn on its own engine. Three
+providers are supported: Cloudflare's Clef on
+[Workers AI](https://developers.cloudflare.com/workers-ai/) (free tier),
+TypeSafe's [Jev](https://typesafe.ai) (the default) and a model of your choice
+on [OpenRouter](https://openrouter.ai).
+
+Everything is in **Settings → Decision and extraction** (Advanced mode): the
+Cloudflare Workers AI card, the Jev/OpenRouter picker under **Another key**,
+for OpenRouter the model, one master switch, each key with **Save** and
+**Test**, and one switch per job it can do. Each provider keeps its own key, so
+you can switch between them without pasting a key again. OpenRouter needs no
+key here when you already saved one under **Settings → API keys**: the decision
+model uses that one.
+
+With several keys saved, one fixed order picks whose key decides: your own Jev
+key, then your own Workers AI key, then Cloud's included decisions, then
+OpenRouter.
+
+## Cloudflare Workers AI (free tier)
+
+A Cloudflare token decides with Clef (Clef-flash by default, Clef for a hard
+case such as a bot's own `decide` call) and also reads with Clairic, the
+extraction model the inbox uses (see
+[proactive-routines.md](proactive-routines.md)). It needs two values:
+
+1. **Account ID.** In the Cloudflare dashboard, open **Workers AI** and choose
+ **Use REST API**, and copy the Account ID (32 letters and digits).
+2. **API token.** On the same page, choose **Create a Workers AI API Token**,
+ then **Create API Token**, and copy it. A custom token needs both
+ **Workers AI - Read** and **Workers AI - Edit**.
+
+Paste both into the **Cloudflare Workers AI (free tier)** card and choose
+**Save**. The token alone is refused: it must come with its account ID.
+Saving checks the token and switches the decision model on. **Test** answers
+*Cloudflare answered in … ms. Extraction works too.*
+
+Cloudflare's free allocation is 10,000 Neurons a day, on the Workers Free and
+Paid plans. Past it, requests fail until the daily reset (00:00 UTC) on Free,
+and are billed on Paid
+([pricing](https://developers.cloudflare.com/workers-ai/platform/pricing/)).
+A failed decision falls back as described in "It fails open".
## Choosing a provider
@@ -107,15 +138,19 @@ The log stays on this machine: workspace backups leave it out.
- **Desktop app:** in the operating system's encrypted store
(`credentials.bin`), like the other workspace keys. The server receives the
- Jev key as `OMB_JEV_API_KEY` and the OpenRouter key as
- `OMB_OPENROUTER_DECIDER_KEY` at start-up; `config.json` keeps only an
- empty placeholder.
+ Jev key as `OMB_JEV_API_KEY`, the OpenRouter key as
+ `OMB_OPENROUTER_DECIDER_KEY` and the Workers AI token as
+ `OMB_WORKERS_AI_TOKEN` at start-up; `config.json` keeps only an empty
+ placeholder.
- **Server or browser use:** in the server's own `config.json` (mode 0600),
- under `decider.key` (Jev) or `decider.openrouterKey` (OpenRouter).
- `OMB_JEV_API_KEY` and `OMB_OPENROUTER_DECIDER_KEY` override them.
+ under `decider.key` (Jev), `decider.openrouterKey` (OpenRouter) or
+ `decider.workersAiToken` (Workers AI). `OMB_JEV_API_KEY`,
+ `OMB_OPENROUTER_DECIDER_KEY` and `OMB_WORKERS_AI_TOKEN` override them.
+- **The Cloudflare account ID is not a secret.** It is kept in `config.json`
+ as `decider.workersAiAccountId` and shown back in Settings.
- **The OpenRouter key is shared with your OpenRouter models.** The decision
model uses the first of these it finds:
- 1. a key saved here, in **Settings → Decision model** (`decider.openrouterKey`
+ 1. a key saved here, in **Settings → Decision and extraction** (`decider.openrouterKey`
or `OMB_OPENROUTER_DECIDER_KEY`): the optional "use a different key"
override, which wins so a key saved before sharing keeps working;
2. the OpenRouter key under **Settings → API keys** (`openrouter.key` or
@@ -156,8 +191,9 @@ usually a similar fraction of a cent.
Each decision sends the state described above (the room's name, its people,
recent room lines and the new message) and the bots' descriptions to the
-selected provider. With OpenRouter that is OpenRouter and the host it routes
-the model to, under OpenRouter's privacy settings and your account's data
+selected provider. With Workers AI that is Cloudflare, which also receives the
+emails Clairic reads for the inbox. With OpenRouter that is OpenRouter and the
+host it routes the model to, under OpenRouter's privacy settings and your account's data
policy; OpenMausBot does not set a data-collection preference. Use Jev, or
leave the job off, for rooms that must not leave the machine.
@@ -183,6 +219,9 @@ responds** or **Only when mentioned**.
"openrouterModel": "typesafe/jev-1.13",
"openrouterApi": "decisions",
"openrouterBaseUrl": "https://openrouter.ai/api/v1",
+ "workersAiToken": "",
+ "workersAiAccountId": "",
+ "workersAiBaseUrl": "https://api.cloudflare.com/client/v4",
"jobs": { "roomRouting": true }
}
```
@@ -210,6 +249,12 @@ decisions model's go to `/alpha/decisions` beside it (for the default base,
API is alpha at OpenRouter and may change. The model list comes from
`GET /api/decider/models`, which needs no key and spends nothing.
+`workersAiAccountId` is 32 hexadecimal characters. `workersAiBaseUrl` has no
+Settings UI, follows the same https-or-loopback rule, and must include
+`/client/v4`. Requests go to
+`{workersAiBaseUrl}/accounts/{workersAiAccountId}/ai/run/@cf/cloudflare/clef-flash`
+(or `clef`, or `clairic` for extraction).
+
## Measuring it
`server/decider/room-routing.eval.test.ts` replays 53 labelled room messages