Sub topic 1
The marketing research and reporting workflow
An AI agent is useful only when you know which job it is doing. This chapter describes the manual workflow that marketing teams already run, breaks it into stages, and decides which stages an agent can take on. Later chapters build the pieces: tools, the agent loop, grounding, verification and review.
Prerequisites
This chapter assumes you have the following:
- Familiarity with marketing metrics such as impressions, clicks, conversions and spend.
- Basic Python reading skills. The code here uses lists, dictionaries and functions.
- A general idea of what a large language model (LLM) is and how to prompt one.
- Familiarity with JSON and simple APIs.
You don't need to have built an agent before. This chapter explains the workflow, not the agent internals.
What "research and reporting" means in practice
A typical recurring task reads like this: "Every Monday, tell me how last week's paid campaigns performed, why they changed, and what we should do next." The task looks like one job, but it is a chain of different jobs. They differ in how much judgment they need, how costly a mistake is, and whether the answer can be computed exactly.
Treating the chain as one job is the most common design error. An agent asked to "write the weekly report" with no structure will blend data retrieval, arithmetic and interpretation into a single model response. Arithmetic errors and invented explanations then become hard to spot. The fix is to split the chain and match each stage to the right kind of worker: a script, a model, or a person.
The stages
Most reporting workflows have the same eight stages.
- Frame the question. Decide what the report must answer, for whom, and over what period. Example: "Did the spring promotion lower cost per acquisition (CPA) compared with the previous four weeks?"
- Collect data. Pull rows from ad platforms, web analytics, a CRM (customer relationship management system) and sometimes public web pages such as competitor pricing.
- Clean and join. Align date ranges and time zones, map campaign names across systems, remove duplicates and handle currency.
- Calculate metrics. Compute click-through rate (CTR), cost per click (CPC), CPA, conversion rate and period-over-period changes.
- Interpret. Look for drivers. Did CPA rise because spend moved to a weaker channel, because a landing page changed, or because of seasonality?
- Draft. Write the summary, tables and recommendations in the house format.
- Check. Compare every number and claim in the draft against the underlying data.
- Review and publish. A person approves, edits, or rejects the report, and it goes to its audience.
The loop back from review matters. Reports are rarely right the first time, because the question was often framed loosely. An agent that can't take new framing from a reviewer will keep producing the wrong report faster.
Deciding which stages suit an agent
Three properties of a stage decide who should do it.
- Is the answer computable exactly? If a formula gives the answer, use code. A language model predicts plausible text. It does not calculate, so it can produce a wrong CPA that looks right.
- Does the stage need judgment about wording or relevance? Summarizing, choosing what to highlight and phrasing recommendations are language tasks where a model helps.
- What does a mistake cost? A wrong number sent to a client or used for a budget decision costs far more than a clumsy sentence.
Applying these three tests gives the following assignment.
| Stage | Best worker | Why |
|---|---|---|
| Frame the question | Person, agent assists | The goal and audience come from the business, not from data. |
| Collect data | Script called by the agent as a tool | Pulling from an API is deterministic and must be repeatable. |
| Clean and join | Script, with the agent flagging oddities | Mapping rules should be explicit, versioned code. |
| Calculate metrics | Script only | Exact arithmetic, no model involved. |
| Interpret | Agent proposes, person confirms | Causes are hypotheses that the data may not prove. |
| Draft | Agent | Language generation from supplied facts is the model's strength. |
| Check | Script plus agent | Automated checks catch unsupported numbers. |
| Review and publish | Person | Accountability stays with a human. |
An agent, in this chapter's sense, is a program that uses a language model to decide which tool to call next. Its main value here is stringing the stages together and handling the variable ones, such as odd data or a changed question, without a person typing each step.
The same assignment as code
Encoding the assignment as data makes it reviewable and easy to change. The following script runs as shown.
STAGES = [
{"name": "frame", "worker": "person", "exact": False, "high_stakes": True},
{"name": "collect", "worker": "tool", "exact": True, "high_stakes": False},
{"name": "clean", "worker": "tool", "exact": True, "high_stakes": False},
{"name": "metrics", "worker": "tool", "exact": True, "high_stakes": True},
{"name": "interpret", "worker": "agent", "exact": False, "high_stakes": True},
{"name": "draft", "worker": "agent", "exact": False, "high_stakes": False},
{"name": "check", "worker": "tool", "exact": True, "high_stakes": True},
{"name": "publish", "worker": "person", "exact": False, "high_stakes": True},
]
def needs_human(stage):
"""A person must sign off on any high-stakes stage the model touches."""
return stage["worker"] in ("person", "agent") and stage["high_stakes"]
for stage in STAGES:
flag = "REVIEW" if needs_human(stage) else "auto"
print(f"{stage['name']:10} {stage['worker']:7} {flag}")The output marks frame, interpret and publish as REVIEW. The rule says a stage needs a human when a language-model or human worker does it and a mistake is costly. Stages run by tools stay automatic, because tools are tested like any other code.
Where manual workflows lose time
Knowing where the hours go helps you pick the first stage to automate. In most teams the time sinks are collecting data from several dashboards, copying numbers into a spreadsheet, rebuilding the same charts every week and rewriting the same commentary with new figures. These are repetitive and rule-based, which suits automation. The slow judgment work, such as deciding what a drop in conversions means, is a small share of the hours but carries most of the value.
A sound first project automates stages 2 to 4 and the draft in stage 6, and leaves stages 1, 5 and 8 with people. You then save the hours without handing over the decisions.
Common mistakes at the workflow level
- Letting the model do arithmetic. It will sometimes be right and sometimes not, and you can't tell which from the text. Put every calculation in code.
- Skipping the framing stage. A report that answers an unstated question is rarely read. Write the question down as the first input to the agent.
- Mixing stages in one prompt. "Pull the data, compute the metrics and explain the results" hides which step failed. Keep stages separate so you can test each one.
- No stage 7. Without a check step, a plausible but invented figure reaches the reviewer, who may not notice it. Chapter 11 covers checking in depth.
- Treating review as optional. For anything that influences spend or goes to a client, a named person approves the result.
Defining the baseline
Before automating, record how the manual process performs: hours per report, the number of corrections reviewers request, and how long the report takes to reach its readers. Without these figures you can't tell later whether the agent helped. A rough measurement is enough. One week of timing each stage gives a usable baseline.
What comes next
The following chapters take the stages in order of the agent's involvement. You will see what an agent is, where language models go wrong, which data sources you will connect to, how to give the agent tools, and how the loop runs them. The chapters on grounding, metrics, drafting, checking and review then fill in stages 3 to 8 from this chapter.
Exercise
A teammate proposes one prompt: "Here is last week's raw ad export. Calculate CTR, CPC and CPA, explain why CPA rose, and write the report." Using the three tests from this chapter (exact answer, judgment needed, cost of a mistake), name which parts should go to code, which to the model, and where a person should sign off.
Show answer
CTR, CPC and CPA have exact formulas, so a deterministic tool should calculate them, and the model should receive the results. Explaining why CPA rose requires judgment and is a hypothesis, so the model may propose causes from the supplied data, but a person should confirm them before they are stated as fact. Writing the report is a language task the model can draft from the verified numbers. A check step should compare every number in the draft with the calculated results, and a person should approve the report before it is published, because wrong figures can affect budget decisions.
Exercise
Add a ninth stage named "archive" to the STAGES list in the code example. It is done by a tool, is exact, and is not high-stakes. What does the loop print for it, and why?
Show answer
The loop prints "archive tool auto". The worker is "tool", so needs_human returns False, and the stage is marked auto.