AI assistant inside a CRM: how we built Trinity and why its writes need a yes

Tanvir Akhter Shakib8 min read

The short answer

An AI assistant inside a CRM is a language model with a registry of tools, and the safety lives in those tools, not in the prompt. Trinity, the assistant in Propily, takes its agency and user from the signed-in session, reads freely, and holds the actions that reach a customer or change a live listing until the user answers yes to a question the code builds from the records.

What an AI assistant inside a CRM actually is

Strip away the interface and an assistant inside a CRM is a loop. The user's message goes to a language model together with a list of tool definitions. The model either answers or asks for a tool. We run the tool, hand the result back and repeat until it answers. The answer streams to the browser and every message is saved, so a conversation survives a reload. A lighter model takes short lookups and a heavier one takes long or reasoning-style questions.

The model proposes and our code decides. That split drives every choice below. Trinity can look things up across the CRM and take actions such as booking a viewing or sending an email, but the model never gets to say which agency it acts for, which user it is, or whether a risky action has been approved.

How the tool registry works for AI agent tool calling in a CRM

Tools live in one registry: a dictionary from tool name to a JSON schema, which the model sees as a function definition, and an async handler. A handler receives a context object holding the database session, the agency and the signed-in staff member, plus the arguments the model chose. The agency and the user come from the authenticated session, never from the arguments.

One registry serves three callers: the chat, background tasks that Trinity runs on its own, and the MCP server that exposes the same tools to outside AI clients. A single definition of what a tool is, and whether it writes, keeps the three from drifting apart. Each handler returns records with a relative link so the assistant can send the user to the page. A tool call has a fifteen second timeout, and a failure rolls the database session back and hands the model an error to explain.

TOOLS["search_leads"] = {
    "spec": {"name": "search_leads", "parameters": {...}},  # schema the model sees
    "handler": search_leads,
}

async def search_leads(ctx: ToolContext, **args) -> dict:
    # ctx.agency_id and ctx.agency_user come from the session, never from args
    ...

Which tools read and which tools write

We keep an explicit set of write tools: anything that creates or changes a record, sends a message or saves something to memory. Everything outside that set is a read. The set is the single source of truth for chat and background tasks alike, so a read-only mode can remove the writes from the tool list before the model sees it. Every successful write is also recorded in the activity log with the user, the tool and its arguments, committed at once so the record does not depend on the rest of the turn surviving.

Creating, updating, booking, cancelling, emailing, notifying a colleague, moving a deal and saving a note are writes. Searching, listing, reading a record, running a report and recalling memory are reads. Some tools are checked again where an HTTP route would normally do it. A tool that changes viewings or deals is refused when the agency has switched that workspace off, and a tool that reads finance is refused when the agency's plan does not include it.

How writes need a confirmation step

A request like 'cancel the 9am today' can resolve to the wrong viewing, and a cancellation is hard to undo quietly. So the actions that reach a customer or another person's diary are held. They are booking, cancelling, moving or assigning a viewing, sending an email, sending property matches and updating a repair. Editing a property is held for every field, because each one re-publishes a live listing. Editing a contact is held when it changes an email address or phone number, because those are how the agency reaches the person.

The first call to a held tool does not run. It returns a question built in code from the stored records, never worded by the model, and the model is told to ask exactly that and stop. The action runs only when the next user message is a clear yes and the model calls the same action again with the arguments the user was shown.

We decide what counts as the same action by a key: the ids and the time for a viewing, the recipient and subject for an email. Rewording the body does not ask again, and the body the user approved is the one sent.

Reading the reply is deliberately conservative. A plain yes acts and a no declines. A hesitation, a question back, a different time or an email address in the reply counts as unclear and the question is asked again, because 'yes, but on Friday' is a change, not an approval. A negated yes is a no, and 'cancel it' counts as a yes only for a cancellation. The cost is that some genuine approvals are asked twice.

async def confirm_gate(name, args, history, user_message):
    key = action_key(name, args)                 # ids and time, not wording
    pending = find_pending(history, name, key)
    if pending:
        verdict = yes_no(user_message, {name})   # yes, no or unclear
        if verdict == "yes":
            return await run_tool(name, pending.args)  # the args the user saw
        if verdict == "no":
            return {"declined": True}
    question = describe_action(name, args)       # built from records, not the model
    return {"needs_confirmation": True, "question": question,
            "note": "Nothing has been done yet. Ask exactly this and stop."}

How the assistant respects the signed-in user's permissions and agency

Trinity acts as the person using it, with that person's reach. Branch rules apply: an admin sees every branch, a manager sees their own branch plus leads not yet routed, anyone else sees their own branch plus leads assigned to them, and a person with no branch sees only their own. Tools that an HTTP route would normally protect check the same permission themselves. Seeing repairs, tenancies or keys needs the seat's own view permission, so a user who cannot open those pages cannot read them through the assistant either.

Three more gates sit around the loop. Trinity is a package feature, so the whole assistant is refused for an agency whose plan excludes it. Before any tool runs, the service checks it was among the tools offered to the model on that call, so a model that names a tool it was not given gets a refusal instead of a run. And finance has a hard boundary enforced on the server, not in a prompt: anything running as an AI is refused when it tries to approve money, change a payee or claim a payment succeeded, whatever permissions the user holds.

What outside clients get, and what we have not shipped

The same registry is exposed over MCP to outside AI clients, with the agency taken from the client's token. There the caller is not a member of staff in the loop, so the server adds guards: a write scope for anything that changes state, a recipient check on email so it can only go to someone the agency already knows or an allowlisted domain, a second explicit call carrying a token bound to the exact message, and rate limits.

Some guards exist in the code but are off by default, so we leave them out of what we claim: holding changes made after the assistant has read text written by someone outside the conversation, asking before a background task acts, and a fallback model if the main provider fails. Text written by a tenant or typed into a web form is data, not an instruction, and that is the problem the first of those guards exists for.

What does run today is cleaning inside the tool: text typed by a stranger, such as a web form answer, has hidden direction-control characters dropped, line breaks collapsed, links replaced and its length capped before the model sees it.

Where to go next

The AI for estate agents page shows what Trinity does day to day, and the real estate CRM page shows the records it works on. If you are comparing assistants, ask which actions need a yes and who writes the question.

Questions people ask

What is an AI assistant inside a CRM?

It is a language model connected to the CRM's own functions, so it can look up records and take actions in plain English. What separates a safe one from a risky one is how those functions are scoped, confirmed and logged.

How does an AI agent call tools in a CRM?

The model is given a schema for each tool and replies with the tool it wants and its arguments. Our code runs the matching handler with the agency and user taken from the session, then returns the result so the model can answer.

How do you stop an AI assistant taking the wrong action in a CRM?

Hold the risky actions until the user says yes to a question the code builds from the records, and run the action only with the arguments the user saw. Also check permissions inside each tool and log every successful write.

Can an AI assistant see data a user is not allowed to see?

It should not. Ours takes the agency and the user from the signed-in session and applies the same branch and permission checks as the pages, so it cannot read what that person could not open.

Who answers your phones tonight?Book a demo
AI assistant inside a CRM: how we built Trinity | Propily