Technical

AI Agents for Sales Follow-Up: Stalled Deals, Approvals, Limits

How to set up an AI agent that finds stalled CRM deals and quotes, drafts follow-ups for a person to approve, logs every action, and stays inside budgets, sending rules and opt-outs.

Kalvyai Engineering · · 7 min read

AI Agents for Sales Follow-Up: Stalled Deals, Approvals, Limits (cover)
On this page

Most CRMs have deals that stopped moving: an opportunity that has sat in one stage for weeks, or a quote sent and never answered. Usually nobody decided to drop them. They just got buried.

An AI agent can help here, but only if the job is narrow and the controls are clear. This post covers a setup that works in practice. Rules find stalled records. The agent drafts a follow-up. A person approves it. Every step is logged. Hard limits apply to spend, sending and opt-outs.

The examples use Odoo and ERPNext. The same pattern applies to any CRM with an API.

What the agent should and should not do

Keep the scope small. A follow-up agent should:

  • Find deals and quotes that match a "stalled" definition you control.
  • Read the record's context: stage, amount, last messages, open activities, quote lines.
  • Draft a short follow-up message and a suggested next step.
  • Put the draft in a queue for the deal owner to approve, edit or reject.
  • Log what it read, what it produced, what it cost and who approved it.

It should not:

  • Send anything without approval, at least at first.
  • Offer new prices, discounts, delivery dates or terms.
  • Change deal stages, amounts or owners.
  • Contact anyone who has opted out.

Write these rules in code, not only in the prompt. A prompt is a request. A check in code is enforced.

Step 1: Define "stalled" with rules, not AI

Do not ask a model to decide which deals are stalled. Use plain filters that sales managers can read and change. A typical definition:

  • The opportunity is open (not won, not lost).
  • The stage has not changed for N days.
  • There is no planned activity (call, meeting, task).
  • There has been no inbound or outbound message for N days.

For quotes:

  • The quote was sent but not confirmed.
  • It is still within its validity date, or expired recently.
  • There has been no reply since it was sent.

The N values depend on your sales cycle. Pick a starting number with your sales team and adjust after a few weeks.

Odoo example

This runs inside an Odoo module, for example from a scheduled action. Check field names against your Odoo version.

Python
from datetime import timedelta
from odoo import fields

def find_stalled_opportunities(env, days=14):
    cutoff = fields.Datetime.now() - timedelta(days=days)
    return env["crm.lead"].search([
        ("type", "=", "opportunity"),
        ("active", "=", True),
        ("stage_id.is_won", "=", False),
        ("date_last_stage_update", "<", cutoff),
        ("activity_ids", "=", False),
    ])

def find_stalled_quotes(env, days=7):
    cutoff = fields.Datetime.now() - timedelta(days=days)
    return env["sale.order"].search([
        ("state", "=", "sent"),
        ("validity_date", ">=", fields.Date.today()),
        ("write_date", "<", cutoff),
    ])

write_date changes on any edit, so it is only a rough signal. Before drafting, check the chatter (mail.message on the record) for recent customer replies. If the customer replied, the deal is not stalled. It is waiting on you, and it needs a different message.

ERPNext example

Python
import frappe
from frappe.utils import add_days, today

def find_stalled_quotations(days=7):
    return frappe.get_all(
        "Quotation",
        filters={
            "docstatus": 1,
            "status": "Open",
            "modified": ["<", add_days(today(), -days)],
        },
        fields=["name", "party_name", "grand_total", "valid_till", "owner"],
    )

The same logic applies to the Opportunity doctype. Filter on its status and last modified date, then check linked Communications for recent emails.

Step 2: Collect context the model is allowed to see

Build a small, explicit context object for each record. Do not hand the model the whole database. Include only what a good salesperson would look at:

  • Customer name and contact name.
  • Deal or quote name, amount, currency, validity date.
  • Product lines (names and quantities, no internal costs or margins).
  • The last 3 to 5 messages, trimmed.
  • The deal owner's name and signature.
  • Any notes marked as safe to reference.

Leave out internal notes, cost prices, other customers' data and anything you would not want quoted back to the customer. Whatever is in the context can end up in the draft.

Step 3: Draft with structured output

Ask the model for structured output, not free text. That way your code can validate it before anyone sees it.

JSON
{
  "record_model": "sale.order",
  "record_id": 4821,
  "channel": "email",
  "subject": "Following up on quote S04821",
  "body": "Hi Priya, I wanted to check whether the quote we sent on the 3rd covers what you need...",
  "suggested_next_step": "Offer a 15-minute call to go through the line items",
  "reason_stalled": "Quote sent 9 days ago, no reply, valid for 12 more days",
  "mentions_price_or_terms": false
}

Then validate in code:

  1. Reject the draft if it contains a currency amount, percentage or date that is not in the source record.
  2. Reject it if mentions_price_or_terms is true, or if a simple keyword check finds words like "discount" or "free shipping".
  3. Reject it if the body is longer than your limit.
  4. Reject it if the recipient address does not match a contact on the record.

Rejected drafts are logged with the reason. They never reach the approval queue.

Keep the prompt plain. State the goal, the tone, the facts and the rules: "Write a short, polite follow-up. Use only the facts provided. Do not offer discounts, new prices or dates. If the last message was from the customer, answer it instead of following up."

Step 4: Route every draft to a person

The approval step is where the value is protected. Give each draft a simple state machine:

Plain text
drafted -> pending_approval -> approved -> sent
                            -> edited -> approved -> sent
                            -> rejected (with reason)
                            -> expired (not reviewed in time)

Practical details that matter:

  • Route to the deal owner. They know the customer. Send to a manager only if the owner is away.
  • Show the reason. Display reason_stalled and the source record next to the draft, so the reviewer can judge it quickly.
  • Allow edits. Store both the original draft and the edited version. The difference shows you where the prompt needs work.
  • Ask for a reason on rejection. A short dropdown works: "customer already contacted by phone", "deal is dead", "wrong tone", "wrong facts".
  • Expire old drafts. A draft that sat unreviewed for a week is probably out of date. Expire it and let the next run decide again.

In Odoo, the queue can be a custom model with a list view and approve/reject buttons, or a scheduled activity on the record. In ERPNext, a custom doctype with a workflow does the same job.

Step 5: Log every action

If someone asks "why did we send this to that customer?", you should be able to answer from the log alone. Log at least:

SQL
CREATE TABLE agent_followup_log (
    id              BIGSERIAL PRIMARY KEY,
    created_at      TIMESTAMPTZ NOT NULL DEFAULT now(),
    run_id          UUID NOT NULL,
    record_model    TEXT NOT NULL,
    record_id       BIGINT NOT NULL,
    action          TEXT NOT NULL,   -- selected, skipped, drafted, rejected_by_rule,
                                     -- approved, edited, rejected_by_user, sent, expired
    reason          TEXT,
    model_name      TEXT,
    input_tokens    INTEGER,
    output_tokens   INTEGER,
    cost            NUMERIC(12,6),
    actor           TEXT NOT NULL,   -- 'agent' or a user login
    payload         JSONB            -- draft, edits, context hash
);

A few habits make the log useful:

  • Log skips, not only actions. "Skipped: contact opted out" is as important as "sent".
  • Store a hash of the context, or the context itself if your data policy allows it. You can then reproduce why a draft said what it said.
  • Post a note on the CRM record when a message is sent, so the sales team sees it in the normal timeline.
  • Make the log append-only. Agents and normal users should not be able to edit or delete entries.

The limits to set

Budgets

Model calls cost money. A loop bug can burn through a month's budget overnight. Set limits at several levels:

  • Per run: the maximum number of records processed and the maximum spend. Stop the run when either is reached.
  • Per month: a hard cap. When it is reached, the agent stops drafting and alerts an admin. It does not quietly switch to a cheaper path.
  • Per record: one draft per record per cycle. No retries in a loop.

Enforce the cap before each call, not after. If you are on Odoo, AI Base lets you plug any AI model into Odoo with a hard monthly cap. AI Base for ERPNext does the same for ERPNext.

Sending rules

These rules apply at send time, even after approval:

  • Approval required. No approved state, no send. Check this in the send function itself.
  • Frequency cap. No more than one agent follow-up per contact within a set window, and a maximum number of follow-ups per deal. After that, the record goes to the owner as a task instead.
  • Sending hours. Only send during the recipient's business hours, if you know their time zone.
  • Rate limit. Spread sends out so your mail server and domain reputation are not hit by a burst.
  • Send from the owner's address, or a monitored shared address, so replies reach a person.
  • Re-check state. If the deal was won, lost or updated since the draft was made, cancel the send.

Opt-outs

Check opt-outs twice: once before drafting, so you do not spend money on drafts you cannot send, and again right before sending, because people unsubscribe in between.

In Odoo, blacklisted email addresses are stored by the mail blacklist feature. Records that use it expose an is_blacklisted field. In ERPNext, check the contact's unsubscribe status and any Email Unsubscribe entries.

Python
def can_send(draft, contact):
    if draft.state != "approved":
        return False, "not approved"
    if contact.is_blacklisted:
        return False, "contact opted out"
    if followups_in_window(contact) >= MAX_PER_WINDOW:
        return False, "frequency cap"
    if record_changed_since(draft):
        return False, "record changed after drafting"
    return True, "ok"

Every False result is written to the log with its reason.

Also respect the law that applies to you. Consent and unsubscribe rules for sales email differ by country.

A sensible rollout

  1. Shadow mode. Run the selection rules only. Review the list of "stalled" records with the sales team and fix false positives.
  2. Draft only. Generate drafts but do not send them. Owners read them and mark them good or bad.
  3. Approve and send, small group. Turn on sending for one team or one pipeline, with approval required.
  4. Review weekly. Look at rejection reasons, edit rates, replies and cost per sent message. Adjust the rules and the prompt.
  5. Widen carefully. Add pipelines one at a time. Keep approval required unless you have a strong, documented reason to remove it for a narrow case.

What to measure

  • Stalled records found per week, and how many the team agreed were really stalled.
  • Approval rate, edit rate and the top rejection reasons.
  • Reply rate on sent follow-ups compared with your usual manual follow-ups.
  • Deals that moved stage within a set number of days after a follow-up.
  • Spend per run and per sent message.

If the edit rate stays high, the context is usually missing something, or the prompt is asking for too much. Fix that before you add more pipelines.

How Kalvyai can help

We build AI agents that work inside Odoo, ERPNext and Shopify with human approvals, budgets and an audit trail. Sales follow-up is a common place to start. You can read more about this work at kalvyai.com/ai-agents.

For Odoo, our Abandoned Cart Recovery & AI Sales Agent app covers win-back and quotation follow-up. Our other apps are at store.kalvyai.com.

If you want an agent fitted to your pipeline, your approval flow and your opt-out rules, contact us.

Share this article

  • AI agents
  • CRM
  • sales follow-up
  • Odoo
  • ERPNext
  • human approval
  • audit trail

Kalvyai Engineering · Engineering team

The engineers who build, connect and fix business systems at Kalvyai: Odoo, ERPNext, Shopify and AI agents that work inside them with approvals, budgets and an audit trail.

Comments

No comments yet. Questions and corrections are welcome.

Rate this post or leave a comment

Your rating (optional)
Not rated

Comments appear after an editor approves them. See our privacy notice.

Read next

AI Bank Reconciliation: Suggested Matches a Person Confirms (cover)Technical
Kalvyai EngineeringAI agents

AI Bank Reconciliation: Suggested Matches a Person Confirms

How an AI matcher suggests bank reconciliation matches from descriptions and amounts, explains each one, sorts them by confidence, and leaves the final confirmation to a person.

7 min read

Claude Tool Use for ERP Tasks: Safe Read and Write Actions (cover)Technical
Kalvyai EngineeringAI agents

Claude Tool Use for ERP Tasks: Safe Read and Write Actions

How to give Claude function calling access to your ERP without giving it the keys: narrow tools, argument validation in code, approval gates for writes, and a log entry for every call. Includes a Python example against Odoo.

6 min read

AI Agent Audit Trail: What to Log and How Long to Keep It (cover)Technical
Kalvyai EngineeringAI agents

AI Agent Audit Trail: What to Log and How Long to Keep It

A practical design for audit trails of AI agents in ERP and commerce systems: which events to record, how to store them so they can't be quietly changed, how long to keep them, and how to use them to investigate an incident.

8 min read

Newsletter

Get new guides in your inbox.

Practical notes on Odoo, ERPNext, Shopify and AI agents, written by the engineers who build them. No spam, and you can ask to stop at any time.

Prefer a feed? Subscribe by RSS. We use your email only to send new articles. See our privacy policy.