Tutorial
How to Add an AI Agent to Your App
A step-by-step guide to giving an existing application an in-app AI agent that can take real actions: define its capabilities as verbs, connect a model, add rules for risky actions, and test it the way your users will.
Last reviewed
In short: list what the agent should be able to do, define those actions as verbs, connect them to your existing code, give a model access to them through tool calling, and put rules on anything risky. Then test the feature by asking the agent, the way your users will.
Most apps that “add AI” add a chat box that can only talk. An AI agent inside your app is different: it can actually do things for the user, like finding records, filling in a form, creating a task or sending a message, using the same features your interface already offers.
This guide adds one to an existing app. The example is a simple task manager, but the steps are the same for a CRM, a store, a GIS tool or an internal dashboard.
1. Decide what the agent should be able to do
Start from your users, not from the model. Write down the requests you want the agent to handle, then the action behind each one:
| The user says | The action | Risk |
|---|---|---|
| “What's still open for Dana?” | List tasks by status and assignee | None: read only |
| “Add a task to send the Q3 report” | Create a task | Low |
| “Mark the report task done” | Complete a task | Low |
| “Delete that task” | Delete a task | High: permanent |
Two habits help here. Start small, with read-only actions first, and keep the risk column. It becomes your rules in step 5.
2. Define those actions as verbs
A verb is one action described as data: a name, a description the model will read, typed parameters, and flags for anything destructive. A verb library groups them. Install OpenVerb:
npm install openverb
# or, for Python
pip install openverbThen describe the task manager's actions:
import { loadLibrary, createExecutor } from 'openverb';
const library = loadLibrary({
namespace: 'my.tasks',
version: '1.0.0',
description: 'Actions the in-app assistant may take in the task manager.',
verbs: [
{
name: 'task.list',
category: 'tasks',
description: 'List tasks, optionally filtered by status or assignee.',
params: {
status: { type: 'enum', enum: ['open', 'done'], description: 'Only tasks with this status.', required: false },
assignee: { type: 'string', description: 'Only tasks assigned to this person.', required: false },
},
},
{
name: 'task.create',
category: 'tasks',
description: 'Create a new task.',
params: {
title: { type: 'string', description: 'What needs to be done.', required: true },
assignee: { type: 'string', description: 'Who should do it.', required: false },
due_date: { type: 'string', description: 'Due date, YYYY-MM-DD.', required: false },
},
},
{
name: 'task.complete',
category: 'tasks',
description: 'Mark a task as done.',
params: { id: { type: 'string', description: 'Task ID.', required: true } },
},
{
name: 'task.delete',
category: 'tasks',
description: 'Permanently delete a task.',
params: { id: { type: 'string', description: 'Task ID.', required: true } },
destructive: true,
requires_confirmation: true,
},
],
});Write descriptions for the model, not for yourself: say what the action does and what each parameter means. Notice destructive and requires_confirmation on task.delete; that's the risk column, written into the definition.
For common interface actions such as theme, navigation, search, forms and modals, you don't have to write your own: the Standard Library already defines them.
3. Connect each verb to your existing code
Register a handler for every verb. Handlers call the code your app already uses, such as your data layer and services, so the agent does exactly what the interface does, and nothing it doesn't:
const executor = createExecutor(library);
executor.register('task.list', async ({ status, assignee }) => ({
verb: 'task.list',
status: 'success',
data: await tasks.find({ status, assignee }), // your existing data layer
}));
executor.register('task.create', async ({ title, assignee, due_date }) => ({
verb: 'task.create',
status: 'success',
data: await tasks.create({ title, assignee, due_date }),
}));
executor.register('task.complete', async ({ id }) => ({
verb: 'task.complete',
status: 'success',
data: await tasks.update(id, { status: 'done' }),
}));
executor.register('task.delete', async ({ id }) => {
await tasks.remove(id);
return { verb: 'task.delete', status: 'success', data: { id } };
});4. Route every action through one place
Whatever model you use, every action it requests should pass through a single function. That is where you check confirmations and where you will add logging later:
// Every action the agent asks for goes through this one function.
async function runAction(action, { confirmed = false } = {}) {
const verb = executor.getVerb(action.verb);
if ((verb?.destructive || verb?.requires_confirmation) && !confirmed) {
// Don't run it: hand it back to the UI to ask the user.
return { verb: action.verb, status: 'needs_confirmation', message: `Confirm: ${verb.description}` };
}
return executor.execute(action); // rejects unknown verbs and missing required params
}Here is what it returns for mistakes, a risky request and something that was never allowed:
await runAction({ verb: 'task.create', params: {} });
// { verb: 'task.create', status: 'error', error_message: 'Missing required param: title' }
await runAction({ verb: 'task.delete', params: { id: 't1' } });
// { verb: 'task.delete', status: 'needs_confirmation', message: 'Confirm: Permanently delete a task.' }
await runAction({ verb: 'invoice.pay', params: {} });
// { verb: 'invoice.pay', status: 'error', error_message: 'Unknown verb: invoice.pay' }These are real outputs from the openverb package. The model never touches your database directly: unknown actions and incomplete requests are rejected before your code runs.
5. Put rules on risky actions
Confirmation flags cover the basics. When you need more, such as different permissions for admins and regular users, actions limited to paid plans, or a record of every action for auditing, run verbs through @openverb/runtime. It checks a policy before every action and returns a receipt after it. @openverb/policy adds plan-based rules.
The CRM walkthrough shows a real policy that lets an assistant read and draft freely but never delete, and never email a customer without confirmation. For a bigger example of policy design, see Governed by Design, which models the U.S. Constitution as an OpenVerb policy.
6. Connect a model and give it the verbs as tools
Now give a model access. Convert each verb into the model's tool format, send the conversation, run any tool calls through runAction, and send the results back until the model answers. With Claude:
import Anthropic from '@anthropic-ai/sdk';
const anthropic = new Anthropic();
// verbToJsonSchema converts each verb's params into JSON Schema; see the
// OpenAI and Anthropic guide for the full, tested converter.
const tools = library.verbs.map((verb) => ({
name: verb.name,
description: verb.description,
input_schema: verbToJsonSchema(verb),
}));
export async function askAgent(messages) {
while (true) {
const response = await anthropic.beta.messages.create({
model: 'claude-opus-5-5',
max_tokens: 16000,
system: 'You are the assistant inside a task manager. Use the tools to act for the user.',
tools,
messages,
betas: ['server-side-fallback-2026-07-01'],
fallbacks: 'default',
});
if (response.stop_reason === 'refusal') return { messages, done: true };
messages.push({ role: 'assistant', content: response.content });
if (response.stop_reason !== 'tool_use') return { messages, done: true };
const results = [];
for (const block of response.content) {
if (block.type !== 'tool_use') continue;
const result = await runAction({ verb: block.name, params: block.input });
results.push({ type: 'tool_result', tool_use_id: block.id, content: JSON.stringify(result) });
}
messages.push({ role: 'user', content: results });
}
}Run this on your server, never in the browser, so your API key stays private and every action goes through your backend. The OpenAI and Anthropic guide has the full verb-to-tool converter, the same loop for OpenAI, Python versions, and a production checklist.
7. Give the agent a place in your interface
The agent needs somewhere to live: a chat panel, a sidebar, or a command bar. Keep it simple. Send the user's message to your server, run askAgent, and show the reply. Two details make a big difference:
- Confirmations in the UI. When
runActionreturnsneeds_confirmation, show the user what will happen with a clear Confirm button, then run the action again withconfirmed: true. - Show what was done. After an action, update the screen (the new task appears, the completed one is ticked) so the user can see the agent did what it said.
8. Test it the way your users will
Your coding agent can confirm the code works. Only the in-app agent can confirm the experience works. For each feature, open your app and ask for it in plain language:
- Does the agent pick the right action, with the right parameters?
- Does it notice when information is missing, and ask for it?
- Does it stop and ask before anything destructive?
- Does it explain clearly what happened, including when something fails?
- Does it refuse requests that no verb allows?
Then make it a habit: build a feature, define its verbs, test it through the agent, repeat. The reasoning behind that is in Your coding agent is not your application agent.
Frequently asked questions
Can I add an AI agent to an app I've already built?
Yes. You don't rebuild anything: you describe the actions your app already has as verbs and register handlers that call your existing code. Start with a few read-only actions and add more as you go.
Which AI model do I need?
Any model that supports tool calling (function calling) works, including OpenAI, Anthropic and Gemini models. Because the actions are defined once as verbs, you can switch models without redefining them.
How is an AI agent different from a chatbot?
A chatbot answers in text. An AI agent can also take actions in your app, like creating a task or sending an email, by calling capabilities you have defined and allowed.
How do I stop the agent from doing something dangerous?
Only expose the actions you want it to have, mark destructive ones so they need the user's confirmation, and, when you need roles, plans or an audit trail, run actions through a policy with @openverb/runtime.
Does this work in Python?
Yes. pip install openverb gives you the same library loader and executor: load_library, create_executor, register and execute.