Sub topic 12
Chaining features into multi-step automation
This chapter assumes you know what a contact record, a campaign, and a dashboard are. It also assumes you know the basics of machine learning and large language models. It builds on the earlier chapters about drafting, triage, scoring, forecasting, and automated insights. Here those features are linked together.
From single features to workflows
A single AI feature does one job. A model scores a lead. A language model drafts an email. A workflow connects several of these so that one result triggers the next step. An AI agent is a workflow in which a language model chooses some of the steps, such as which tool to call or which action comes next, instead of following a fixed path.
Chaining is useful because the features already share data. A score from the CRM can decide which email is drafted. A flagged metric in analytics can open a task in the CRM.
A worked chain
Suppose an analytics platform flags a drop in demo requests. The chain below turns that alert into a follow-up.
Each step uses a different kind of feature:
- The anomaly check is a statistical, predictive step.
- The CRM lookup is retrieval of records.
- Scoring is a predictive model.
- Drafting is generative.
- Routing is plain rules.
Not every step needs AI. Fixed rules are cheaper, faster, and easier to test, so use a model only where the step needs judgment or language.
Routing with an approval gate
The last step decides what happens to the draft. This function sends a draft automatically only when it is internal and the confidence is high. Every other draft 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))The output is auto_send, human_review, and human_review. The external draft is reviewed even at high confidence, because a mistake there reaches a customer. The next chapter covers how to choose such thresholds.
Common errors in chained automation
Errors in a chain pile up, because each step trusts the output of the one before it.
| Problem | What happens | Mitigation |
|---|---|---|
| Compounding errors | A wrong score leads to a wrong audience, then a wrong email | Check outputs between steps |
| Silent failure | A step returns empty data and later steps run on nothing | Stop the chain on empty or malformed input |
| Runaway loops | An agent keeps retrying or re-sending | Set a step limit and a send limit |
| Stale data | The CRM and email platform disagree about a contact | Re-read the record just before acting |
| Unclear ownership | No one knows who approved an action | Log each step and each approval |
Design habits
- Start with read-only steps, such as summaries and alerts, and add actions later.
- Keep the model's output structured, for example a label from a fixed list, so the next step can check it.
- Log the input and output of every step so a bad result can be traced back.
- Limit what the agent can do to the permissions that the task needs.
Exercise
A chain scores leads, drafts a follow-up for each top lead, and sends it. The scoring step starts returning an empty list after a data sync fails. Name one control that would prevent harm, and say where it belongs in the chain.
Show answer
Stop the chain when the scoring step returns empty or malformed output, so the drafting and sending steps never run on nothing. Place this check between scoring and drafting. An approval gate before sending, like route_draft, is a second control, since external email should go to human review.