Sub topic 12
Chaining Features into Multi-Step Automation
This chapter assumes you know the single features from earlier chapters: drafting, lead scoring, anomaly detection, inbox triage, and forecasting. It also assumes you know what a contact record, a campaign, and a dashboard are. Here you will see what happens when those features are connected into one workflow that acts across platforms.
From single features to workflows
A single AI feature takes one input and returns one output. A lead score takes a contact record and returns a probability. A draft generator takes a prompt and returns text. A person then decides what to do with the result.
A multi-step automation connects several of these outputs so that one result triggers the next action. An AI agent is a program that uses a language model to choose which step to take next, calls tools such as "read CRM record" or "send email", and repeats until a goal is met or it stops.
Two designs are common:
- Fixed workflow. The steps and their order are written in advance. The AI only does work inside individual steps, such as classifying or drafting. This is predictable and easy to test.
- Agentic workflow. The model chooses the steps at run time. This is flexible, but harder to predict, test, and audit.
Most commercial platforms ship fixed workflows with AI steps inside them. Fully agentic behavior is usually limited to a narrow task with a short list of allowed tools.
An example chain
Consider a chain that uses the features from earlier chapters:
- Analytics anomaly detection notices that demo requests from one campaign dropped sharply.
- An automated insight step looks at related metrics and proposes a cause, such as a broken form.
- The CRM scoring step finds open leads from that campaign with high scores.
- A generation step drafts a follow-up email for each of those leads.
- An approval step decides whether each draft is sent or reviewed.
- A logging step records what happened so you can measure it later.
Each arrow is a handoff. The output of one feature becomes the input of the next, and that is where most problems start.
How handoffs work
Platforms connect steps in three main ways.
| Mechanism | How it works | Typical use |
|---|---|---|
| Trigger and action rules | "When event X happens, run action Y" | Fixed workflows, such as "when score exceeds 80, notify the owner" |
| Webhooks and APIs | One system sends a structured message to another when something happens | Linking an analytics tool to a CRM or email platform |
| Tool calling | A language model returns a request to run a named function with arguments, and the platform runs it | Agentic workflows |
In tool calling, the model does not run anything itself. It outputs something like a function name and arguments. The platform checks the request against a list of allowed tools and then executes it. That check is the first control point, so keep the allowed list small.
The main failure mode: compounding errors
Each step has some error rate. In a chain, errors multiply. If five steps are each right 90% of the time, and errors are independent, the whole chain is right about 0.9^5, or 59% of the time.
step_accuracies = [0.90, 0.90, 0.90, 0.90, 0.90]
chain_accuracy = 1.0
for accuracy in step_accuracies:
chain_accuracy *= accuracy
print(f"Chain accuracy: {chain_accuracy:.2f}")The result is about 0.59. Real errors are not always independent, so treat this as a rough guide. The lesson holds: longer chains need stronger checks, and a mistake early in the chain spreads to every later step.
Other failure modes to plan for:
- Bad input from an earlier step. An anomaly alert based on a tracking outage leads to a pointless email campaign.
- Stale data. A step reads a CRM record that changed minutes ago.
- Repeated actions. A retry after a timeout sends the same email twice. Design actions to be idempotent, meaning running them twice has the same effect as running them once. A common method is to store a unique key for each action and skip it if the key already exists.
- Loops. An agent that keeps retrying a failing step can run up costs or message a contact repeatedly. Set a maximum number of steps and a maximum number of messages per contact.
- Hallucinated details. A drafted email may state a discount or a fact that is not in the source data. Generation steps should draw their facts from retrieved records, and a check should compare the draft against them.
Controls for chained actions
Place controls where the cost of a mistake is highest. The usual points are:
- Before any external message. An email to a customer cannot be recalled. The next chapter covers how to set approval thresholds in detail.
- Before any write to shared data. Changing a CRM field or merging duplicate records can be hard to undo. Log the old value first.
- Before anything that spends money. Budget changes and discount offers should have limits set in code, not in a prompt.
- At the end of the chain. Log the inputs, outputs, and decisions of every step, so a person can reconstruct what happened.
The approval gate from the example can be written as a short function. It sends automatically only when the draft is internal and confidence is high. Everything else goes to a person.
def route_draft(confidence: float, is_external: bool, threshold: float = 0.9) -> str:
"""Decide whether an AI-generated email draft is sent or reviewed."""
if is_external:
return "human_review"
return "auto_send" if confidence >= threshold else "human_review"
print(route_draft(0.95, is_external=False))
print(route_draft(0.95, is_external=True))
print(route_draft(0.70, is_external=False))This prints auto_send, human_review, and human_review. Notice that the external check comes first, so high confidence never overrides it. Also remember that a model's confidence number is not always well calibrated, so a score of 0.95 does not guarantee 95% accuracy.
A chained version can add a budget limit and an action log. The sketch below wraps the gate with a cap on automatic sends and a record of every decision.
from datetime import datetime, timezone
MAX_AUTO_SENDS = 2
audit_log = []
auto_sends = 0
def route_draft(confidence: float, is_external: bool, threshold: float = 0.9) -> str:
if is_external:
return "human_review"
return "auto_send" if confidence >= threshold else "human_review"
def handle(draft_id: str, confidence: float, is_external: bool) -> str:
global auto_sends
decision = route_draft(confidence, is_external)
if decision == "auto_send" and auto_sends >= MAX_AUTO_SENDS:
decision = "human_review" # cap reached, so a person decides
if decision == "auto_send":
auto_sends += 1
audit_log.append({
"draft": draft_id,
"decision": decision,
"time": datetime.now(timezone.utc).isoformat(),
})
return decision
for i in range(4):
print(i, handle(f"d{i}", 0.95, is_external=False))
print(len(audit_log), "entries logged")The first two drafts are sent automatically, and the next two go to review because the cap is reached. Every decision is logged.
Choosing between fixed and agentic designs
Use these criteria when you decide how much freedom to give a workflow.
| Question | Points to a fixed workflow | Points to an agentic workflow |
|---|---|---|
| Are the steps the same every time? | Yes | No, they depend on the situation |
| Is a mistake costly or public? | Yes | No, or easily undone |
| Do you need to explain each decision to an auditor? | Yes | Logging is still possible, but harder to read |
| Is the task open-ended, such as researching an account? | No | Yes |
A sensible start is a fixed workflow with AI inside single steps. Add model-chosen steps only for narrow, low-risk tasks, such as gathering background on an account before a call. Keep read-only tools separate from tools that write or send.
Testing a chain
Test each step alone, then test the whole chain. Step-level tests find which feature is failing. Chain-level tests find handoff problems, such as a field name that one step outputs and the next step does not expect.
- Run the chain on past events where you know the right outcome.
- Run it in a "dry run" mode where actions are written to the log but not executed.
- Compare results against a baseline, such as the same task done manually. Chapter 14 covers baselines and holdout groups.
Exercises
Exercise
A chain has four steps with accuracies of 95%, 90%, 90%, and 85%. Assuming independent errors, about how accurate is the whole chain, and what does this tell you about where to place review?
Show answer
Multiply: 0.95 × 0.90 × 0.90 × 0.85 ≈ 0.65, so about 65%. Errors compound, so the chain is much less reliable than any single step. Place review before irreversible actions, such as sending external email, and consider checking early steps, because their mistakes spread to every later step.
Exercise
An automation retries a failed "send email" action three times after a timeout. Some contacts receive the same email twice. Name the design property that prevents this and describe one way to implement it.
Show answer
The action should be idempotent. One way is to create a unique key for each intended send, such as contact ID plus campaign ID. Store the key when the send is made and skip any later attempt with the same key.