Skip to content

In-product agent

Every namespace ships with an AI assistant baked into the console. Open it from the sidebar Ask AI button or press ⌘K (Ctrl+K on Windows/Linux). It runs on Cloudflare Workers AI with the @cf/moonshotai/kimi-k2.5 model and inherits your namespace role on every action.

The agent has tools at two levels.

ToolEffect
list_databasesEnumerate every database in the namespace
propose_create_databaseStage a new database (always asks before creating)
list_membersMembers and their roles
propose_invite_memberStage an invitation by email + role
list_tokensList API tokens (without secrets)
propose_create_tokenStage a new API token
get_usage_summaryLast-N-day request / row counts

Database-scoped (every tool takes a database slug)

Section titled “Database-scoped (every tool takes a database slug)”
ToolEffect
list_tablesSchema dump for a database
describe_tableColumns, types, constraints
run_selectExecute a single read-only SELECT (capped at 200 rows)
askNL → SQL → answer for the database’s data
read_docsStored table/column descriptions
list_endpointsPublished endpoints for the database
recent_endpoint_logsLast invocations from analytics
propose_create_tableStage a CREATE TABLE
propose_create_endpointStage an endpoint spec
propose_scaffold_crudStage list / get / create / update / delete endpoints for a table
propose_generate_docsStage auto-docs for selected tables

Anything starting with propose_ is a two-step flow — the first call returns the plan, you see it in the chat, and only after you say something like “yes, do it” does the agent re-call with confirmed: true to actually apply.

There is no per-tier message cap and no per-token throughput cap. Agent usage drains the same prepaid balance as everything else; when the balance runs out you’ll get a 402 with a top-up hint.

Each turn is bounded to 5 recursive tool calls so the agent can’t loop forever.

  1. The console POSTs to /api/namespaces/:slug/agent/chat with your message.
  2. The API worker assembles your last 50 turns of history, the system prompt (which embeds your namespace slug + role), and the tool definitions.
  3. runWithTools from @cloudflare/ai-utils drives the model loop on Workers AI. Tool invocations execute as you, with your namespace role.
  4. The response streams back as SSE: a leading event: trace frame listing every tool call, then the model’s tokens, then [DONE].
  5. The assistant turn is persisted to D1 so reconnecting clients see the same conversation.

History is per (user × namespace). Clear it from the chat panel — that hits DELETE /api/namespaces/:slug/agent/history.

  • Be concrete. “Show me last week’s signups” beats “tell me about my data”.
  • Reference databases by slug. With one database the agent picks it automatically; with several, name it.
  • Approve propose_* actions explicitly. “Yes, create it” or “go ahead” works. The agent won’t mutate without that.
  • Greetings get conversational replies. Saying “hi” won’t trigger any tools.