Basic

How auto-reply works

Rule-based auto-reply matches a message to a response. It is fast and predictable, and the smart bit is knowing when to hand off to a person instead.

What you will see

billing-team support general

About 2 min of reading

Quick check

Before this new lesson, one small question about the lesson you just finished. Recall it, do not look it up.

Try It

A rule-based auto-reply matches keywords in a message and replies with a fixed answer. I match three messages, hand off low-confidence ones to a person, and route each question to the specialist team that can fix it.

1

Rule-based auto-reply looks for keywords in the message and chooses one of three replies. I test a cancel request, a shipping question, and a greeting to see how the rules split them.

def reply(message): text = message.lower() if "cancel" in text: return "cancel" elif "shipping" in text: return "tracking" else: return "person" for m in ["Please cancel that", "Where is my order?", "Hi there"]: print(reply(m))

Before you run it, say out loud what it will print. Then open the answer.

What it prints
cancel person person
Keyword matching is exact, so "I'd like to cancel" and "stop please" both mean cancel but only the first has the word "cancel".
2

When the bot is unsure it should hand off to a person. I set a confidence score and print whether the bot replies itself or forwards the message to a human.

def decide(score): if score > 0.8: return "auto reply" else: return "forward to human" for s in [0.95, 0.6, 0.4]: print(decide(s))

Before you run it, say out loud what it will print. Then open the answer.

What it prints
auto reply forward to human forward to human
The 0.8 threshold is the design choice. Setting it too high makes the bot ask a human for everything; too low and it answers when unsure.
3

Routing sends a message to the specialist team best suited to help it. I match three messages and print which team handles each one.

def route(text): if "billing" in text: return "billing-team" elif "technical" in text: return "support" else: return "general" for m in ["My invoice is wrong", "It keeps crashing", "General question"]: print(route(m))

Before you run it, say out loud what it will print. Then open the answer.

What it prints
billing-team support general
Order the rules carefully. A message with both words takes the first match, so put the most specific rule first.

Put it in order

Before you write anything, put these lines back in the right order. Click a line to move it up one step. This support step is easier than writing code from scratch, and it is here to make the last example stick.

Data Flow

A message is checked against rules or a model; a confident match auto-replies, otherwise it hands off.
1 Receive the incoming message
↓
2 Match keywords or score intent
↓
3 If confident -> send auto-reply
↓
4 If unsure -> forward to a person
Why this works
Keeping it safe

Any auto-reply system needs guardrails:

  • Never reply on sensitive topics without a human.
  • Limit what tools the agent can call.
  • Always let the user reach a person.

Auto-reply is great for routine questions.
For money, legal, or health -> involve a human.

Designing the hand-off point is more important than making the replies clever.

When you have a choice

Rules vs models

Auto-replies can be built two ways:

  • **Rules*: if statements matching keywords or patterns. Fast, predictable, hard to expand.
  • **Models*: a language model reads intent and writes a reply. Flexible, less predictable.

Rule:    exact, cheap, breaks on new phrasing
Model:   flexible, smart, can surprise you

Many systems use both: a model for understanding, rules for guardrails.

Examples

Matching keywords

Reply based on what the user said

text = message.lower()
if "cancel" in text:
    reply("I'll cancel that for you.")
elif "shipping" in text:
    reply("Here's your tracking link.")
else:
    reply("Let me connect you with a person.")

Keyword matching is simple and predictable. It fails when the user phrases things differently.

Watch out: "I'd like to cancel" and "stop please" both mean cancel, but only the first has the word.

Adding a fallback

When the bot doesn't know

score = classify(message)   # 0..1 confidence
if score > 0.8:
    auto_reply(message)
else:
    forward_to_human(message)

A confidence score lets the agent know when to act and when to hand off to a person. That boundary is the key design choice.

High confidence -> auto reply
Low confidence  -> pass to human

Routing to the right team

Send the message to the right team

if 'billing' in text:
    route('billing-team')
elif 'technical' in text:
    route('support')
else:
    route('general')

Routing sends a message to the specialist best suited to help. It saves time and keeps questions from getting lost.

Why it works: the right person solves the right problem faster.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

← What are AI agents?
Previous Lesson
What are AI agents?
Next Lesson
Safe auto-reply design
Safe auto-reply design →