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

Chapter 1

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.

Chapter 2

Two agents, two jobs

Roman works with two different AI agents, and keeping them apart is the key idea of this walkthrough.

Coding agentApplication agent
Its jobBuilds the CRMOperates the CRM for its users
Who talks to itRomanRoman's customers
ExamplesClaude Code, Codex, CursorThe CRM's built-in assistant
What it touchesSource code, packages, testsContacts, drafts, the inbox, via verbs only
When it runsWhile Roman is developingEvery 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.

Chapter 3

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.

terminal
npx openverb-crm init

The 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
// 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
# .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.

Chapter 4

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 wantsVerbChanges data?
Find or filter contactscontact.listNo
Look up one contactcontact.getNo
Add a new contactcontact.createYes
Tag a contactcontact.add_tagsYes
Group contacts by rulessegment.createYes
Write an emaildraft.createYes, a draft only
Send an emaildraft.sendYes, reaches a customer
Read the inboxinbox.list_threadsNo
Answer a customerinbox.replyYes, reaches a customer
Schedule a campaigncampaign.scheduleYes, reaches many customers
Remove a contactcontact.deleteYes, destructive

The template publishes the whole list at one endpoint, so any agent can discover what it's allowed to call:

verb discovery
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.

Chapter 5

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:

prompt for your coding agent
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.

Chapter 6

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:

VerbFor the assistant
contact.list, contact.get, inbox.list_threadsAllowed
contact.create, contact.add_tags, draft.createAllowed
draft.send, inbox.reply, campaign.scheduleOnly after the user confirms
contact.deleteNever
lib/crm/openverb-v2.ts
// 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:

lib/crm/openverb-v2.ts (continued)
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.

Chapter 7

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:

receipt
{
  "executionId": "…",
  "verbId": "draft.send",
  "verbVersion": "1.0.0",
  "timestamp": "…",
  "actorId": "crm-assistant",
  "tenantId": "acme",
  "status": "ok",
  "durationMs": 212
}
Chapter 8

What Roman built

Step back and the architecture is simple:

  1. A customer asks the assistant for something in plain language.
  2. The model picks a verb from the CRM's published list and fills in its arguments.
  3. The runtime checks the policy: who is asking, which verb, has the user confirmed?
  4. If allowed, the verb's handler runs against Roman's real database or email provider.
  5. 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.

OpenVerb Sandbox

Paste a Verb Library JSON schema here to define what actions the AI can perform.

Ask the AI to perform a task. It will use the vocabulary defined in your library.

The AI proposes a structured action based on your library vocabulary.

Waiting for prompt...

OpenVerb Core intercepts the AI's action and validates it before execution.

Verb exists in library
Payload matches JSON Schema
Policy requirements passed
Inputs valid and sanitized

The validated action is routed to the application backend for execution.

Waiting...

OpenVerb Core generates an execution receipt for full auditability.

Waiting for execution...