Developer walkthrough · CRM
Build an AI-Powered CRM
Follow Roman as he builds a CRM whose AI assistant can look up contacts, draft follow-ups and send email, safely, using the official OpenVerb CRM template, runtime and policies.
Last reviewed
An idea for a CRM
It's Saturday morning, and Roman is building a CRM for small businesses. The basics are clear: contacts, an inbox, email drafts, campaigns. What he wants on top is an assistant his customers can just talk to:
- “Show me every contact tagged lead.”
- “Draft a follow-up to Michael about last week's quote.”
- “Reply to the open thread from Acme.”
- “Make a segment of everyone at a construction company.”
A chatbot can talk about those things. Roman wants one that can do them, without ever emailing a customer or deleting a record nobody asked it to. That's the problem OpenVerb solves: giving an AI a defined set of actions, and rules for using them.
Two agents, two jobs
Roman works with two different AI agents, and keeping them apart is the key idea of this walkthrough.
| Coding agent | Application agent | |
|---|---|---|
| Its job | Builds the CRM | Operates the CRM for its users |
| Who talks to it | Roman | Roman's customers |
| Examples | Claude Code, Codex, Cursor | The CRM's built-in assistant |
| What it touches | Source code, packages, tests | Contacts, drafts, the inbox, via verbs only |
| When it runs | While Roman is developing | Every time a customer asks for something |
The coding agent helps Roman define and wire up the verbs. The application agent is only ever allowed to call them. The verb list is the contract between the two: whatever Roman and his coding agent put in it is exactly what the assistant can do, and nothing more.
Why this distinction matters so much is its own essay: Your coding agent is not your application agent.
Start from the CRM template
Roman's app is Next.js with TypeScript, which is what the official OpenVerb CRM template is built for. It isn't a black-box dependency: like shadcn/ui, the installer copies the components, API routes and verb library straight into his repository, so he owns the code.
npx openverb-crm initThe installer asks where his app, lib and components folders are, then drops the CRM in alongside them. It boots on an in-memory store so he can click around in seconds. For real data he points the store at his database, and picks an email provider:
// lib/crm/store.ts
// The template boots on an in-memory store. Point it at your real database:
export { default as db } from '@/lib/prisma'# .env
CRM_EMAIL_PROVIDER=resend # resend, postmark, sendgrid, mailchimp or ses
RESEND_API_KEY=...Building in Python instead? The template itself is TypeScript, but the verb idea isn't: pip install openverb gives you the same library loader and executor for your own verbs. See Getting started.
Find the verbs
Roman asks one question about his CRM: what should the assistant be able to do? Every answer is a verb. The template already defines them in a library called crm, so most of the work is choosing which ones the assistant gets.
| What the user wants | Verb | Changes data? |
|---|---|---|
| Find or filter contacts | contact.list | No |
| Look up one contact | contact.get | No |
| Add a new contact | contact.create | Yes |
| Tag a contact | contact.add_tags | Yes |
| Group contacts by rules | segment.create | Yes |
| Write an email | draft.create | Yes, a draft only |
| Send an email | draft.send | Yes, reaches a customer |
| Read the inbox | inbox.list_threads | No |
| Answer a customer | inbox.reply | Yes, reaches a customer |
| Schedule a campaign | campaign.schedule | Yes, reaches many customers |
| Remove a contact | contact.delete | Yes, destructive |
The template publishes the whole list at one endpoint, so any agent can discover what it's allowed to call:
GET /api/crm/openverb
{
"verbs": [
{ "name": "contact.list", "description": "List contacts with optional filtering", ... },
{ "name": "draft.create", "description": "Create an email draft", ... },
{ "name": "draft.send", "description": "Send an email draft immediately", ... },
...
],
"description": "OpenVerb CRM API - Deterministic verbs for AI-powered CRM operations"
}Notice what the right-hand column is doing: reading is harmless, drafting is safe, but sending and deleting are not. That column becomes Roman's rules in chapter 6.
Hand it to the coding agent
Roman doesn't wire all of this by hand. He opens his coding agent and gives it a specific brief, naming the real files and the real verbs so it has nothing to guess:
I installed the OpenVerb CRM template with `npx openverb-crm init`.
1. Point lib/crm/store.ts at our Prisma client and map the CRM's contacts,
drafts, inbox and campaigns onto our schema.
2. Configure the email adapter for Resend using CRM_EMAIL_PROVIDER.
3. In lib/crm/openverb-v2.ts, replace the allow-all policy with one that:
- never lets the AI actor run contact.delete
- denies draft.send, inbox.reply and campaign.schedule for the AI actor
unless context.confirmedByUser is true
4. Make the AI assistant's tools in app/api/crm/ai/route.ts execute through
that runtime (actor type "ai"), so the policy applies to every call.
5. Add an assistant tool for draft.send. Set context.confirmedByUser only
when the user has explicitly approved that specific draft in the UI.
6. Log every receipt the runtime returns.
Use only verbs from the template's crm library. Show me the policy before
you wire it in, and add tests for the denied cases.Steps 4 and 5 matter. Out of the box, the template's assistant can draft an email but has no tool to send one, its tools call verbs directly, and its runtime uses an allow-everything policy. Roman wants sending, so he adds the tool, and routes every tool through the runtime so the rules in the next chapter apply to each action the assistant takes.
The coding agent can do the typing; Roman still reviews the policy and the tests before anything ships.
Set the rules
@openverb/runtime checks a policy before every verb runs. The policy sees the verb, who is asking (a person, a service, or the AI), and the request context, and returns allow or deny with a reason. Roman's rules are short:
| Verb | For the assistant |
|---|---|
| contact.list, contact.get, inbox.list_threads | Allowed |
| contact.create, contact.add_tags, draft.create | Allowed |
| draft.send, inbox.reply, campaign.schedule | Only after the user confirms |
| contact.delete | Never |
// lib/crm/openverb-v2.ts
import type { Actor, Context, PolicyDecision, VerbDefinition } from '@openverb/runtime'
// Actions that reach people outside the CRM.
const OUTBOUND = new Set(['draft.send', 'inbox.reply', 'campaign.schedule'])
export async function crmPolicy(
verb: VerbDefinition,
actor: Actor,
context: Context
): Promise<PolicyDecision> {
// The assistant may never delete data.
if (actor.type === 'ai' && verb.id === 'contact.delete') {
return {
decision: 'deny',
reasons: ['ai_cannot_delete'],
code: 'forbidden',
message: 'The assistant cannot delete contacts. Ask a teammate to do it.',
}
}
// Anything that emails a customer needs the user's explicit go-ahead.
if (actor.type === 'ai' && OUTBOUND.has(verb.id) && context.confirmedByUser !== true) {
return {
decision: 'deny',
reasons: ['needs_confirmation'],
code: 'confirmation_required',
message: 'Show the user what will be sent and ask them to confirm.',
}
}
return { decision: 'allow', reasons: ['crm_default'] }
}Then he gives the runtime that policy, and a place to keep every receipt:
const runtime = createRuntime({
verbs,
handlers,
policy: crmPolicy,
onReceipt: async (receipt) => {
// verbId, status ('ok' | 'denied' | 'error'), actorId, durationMs, ...
await saveReceipt(receipt)
},
})
await runtime.execute({
verbId: 'draft.send',
args: { id: 'draft_42' },
actor: { type: 'ai', id: 'crm-assistant' },
context: { tenantId: 'acme', confirmedByUser: true },
})Charging by plan as well? @openverb/policy builds a policy from plan tiers, for example keeping campaign.schedule to paid plans, using allow and deny lists of verbs.
Try it
A customer opens the assistant on Monday morning. Here is what happens underneath each answer:
User
Who's tagged as a lead right now?
Verb call
contact.list { "tags": ["lead"], "status": "active" } → allow
Assistant
Three leads: Michael Grant, Dana Ruiz and Sam Okafor.
User
Draft Michael a friendly follow-up about last week's quote and send it.
Verb call
draft.create { "contact_id": "c_118", "subject": "Following up on your quote", … } → allow
Verb call
draft.send { "id": "draft_42" }
Policy
deny · confirmation_required Show the user what will be sent and ask them to confirm.
Assistant
Here's the draft to Michael. Send it?
User
Yes, send it.
Verb call
draft.send { "id": "draft_42" } context.confirmedByUser = true → allow
Assistant
Sent. I'll let you know if Michael replies.
The assistant tried to send straight away, and the policy stopped it, not a prompt instruction it could ignore. Every one of those calls also left a receipt:
{
"executionId": "…",
"verbId": "draft.send",
"verbVersion": "1.0.0",
"timestamp": "…",
"actorId": "crm-assistant",
"tenantId": "acme",
"status": "ok",
"durationMs": 212
}What Roman built
Step back and the architecture is simple:
- A customer asks the assistant for something in plain language.
- The model picks a verb from the CRM's published list and fills in its arguments.
- The runtime checks the policy: who is asking, which verb, has the user confirmed?
- If allowed, the verb's handler runs against Roman's real database or email provider.
- A receipt records what ran, for whom, and whether it succeeded or was denied.
Roman didn't teach a model how his whole CRM works. He gave it a short list of verbs, rules for the risky ones, and a record of everything it did. Swap the model, add a second app, or let a different agent in, and the verbs and rules stay the same.
Ready to try it on your own app? Install the CRM template, or start smaller with the 5-minute quick start.