Yesterday classify_sentiment took raw customer feedback and returned one word. What happens when the feedback is three paragraphs of mixed praise and complaint?
The classifier probably gets confused. Too much noise. You'd want to trim it down first before asking for a label.
Exactly. You run a summariser agent first, then hand its output to the classifier. The two-agent chain is the backbone of every professional AI pipeline — think of it as a two-step brief: one contractor condenses the material, a second contractor gives you the verdict:
summarizer = Agent(model, system_prompt="Summarize in 2 sentences.")
classifier = Agent(model, system_prompt="Return one word: positive, neutral, or negative.")
summary = summarizer.run_sync(text).output
label = classifier.run_sync(summary).output.strip().lower()Wait — classifier.run_sync(summary) takes a Python string as input? It's not a special agent-to-agent handoff?
It's just a string. summary is a plain Python variable holding the first agent's output. The second agent treats it exactly like any other prompt. That's what makes chaining composable — no framework glue, no special syntax, just function calls:
def summarize_then_classify(text: str) -> str:
summarizer = Agent(model, system_prompt="Summarize in 2 sentences.")
classifier = Agent(model, system_prompt="Return one word: positive, neutral, or negative.")
summary = summarizer.run_sync(text).output
label = classifier.run_sync(summary).output.strip().lower()
return labelSo the chain is just two variables passed sequentially. The second agent never even knows the original text existed.
And that isolation is a feature, not a limitation. The classifier only ever sees a clean two-sentence summary — not three paragraphs of rambling feedback. You've reduced the input noise deliberately. Structured pipelines produce more consistent labels because each agent has a well-scoped job.
I've been sending entire email threads to ChatGPT and wondering why the tone labels come back inconsistent. Summarise first, classify second. I should have built this a week ago.
Two-step chains scale to ten steps. Next week you'll add a third agent that formats the label into a triage email — same pattern, one more variable assignment.
Two agents, two run_sync calls, one intermediate variable.
Why chain? Classification accuracy drops on long, noisy inputs. Summarising first gives the classifier a clean, scoped prompt — the same way a well-written brief produces better contractor output than a wall of raw notes.
Isolation by design: The classifier never receives the original text. It only sees the summary. This scoping is intentional — each agent has a single, well-defined job. Narrow inputs produce more consistent outputs.
The .strip().lower() convention: Always normalise classifier output. Models occasionally return "Positive" or " negative " with extra whitespace or capitalisation. Stripping and lowercasing makes downstream comparisons safe.
Yesterday classify_sentiment took raw customer feedback and returned one word. What happens when the feedback is three paragraphs of mixed praise and complaint?
The classifier probably gets confused. Too much noise. You'd want to trim it down first before asking for a label.
Exactly. You run a summariser agent first, then hand its output to the classifier. The two-agent chain is the backbone of every professional AI pipeline — think of it as a two-step brief: one contractor condenses the material, a second contractor gives you the verdict:
summarizer = Agent(model, system_prompt="Summarize in 2 sentences.")
classifier = Agent(model, system_prompt="Return one word: positive, neutral, or negative.")
summary = summarizer.run_sync(text).output
label = classifier.run_sync(summary).output.strip().lower()Wait — classifier.run_sync(summary) takes a Python string as input? It's not a special agent-to-agent handoff?
It's just a string. summary is a plain Python variable holding the first agent's output. The second agent treats it exactly like any other prompt. That's what makes chaining composable — no framework glue, no special syntax, just function calls:
def summarize_then_classify(text: str) -> str:
summarizer = Agent(model, system_prompt="Summarize in 2 sentences.")
classifier = Agent(model, system_prompt="Return one word: positive, neutral, or negative.")
summary = summarizer.run_sync(text).output
label = classifier.run_sync(summary).output.strip().lower()
return labelSo the chain is just two variables passed sequentially. The second agent never even knows the original text existed.
And that isolation is a feature, not a limitation. The classifier only ever sees a clean two-sentence summary — not three paragraphs of rambling feedback. You've reduced the input noise deliberately. Structured pipelines produce more consistent labels because each agent has a well-scoped job.
I've been sending entire email threads to ChatGPT and wondering why the tone labels come back inconsistent. Summarise first, classify second. I should have built this a week ago.
Two-step chains scale to ten steps. Next week you'll add a third agent that formats the label into a triage email — same pattern, one more variable assignment.
Two agents, two run_sync calls, one intermediate variable.
Why chain? Classification accuracy drops on long, noisy inputs. Summarising first gives the classifier a clean, scoped prompt — the same way a well-written brief produces better contractor output than a wall of raw notes.
Isolation by design: The classifier never receives the original text. It only sees the summary. This scoping is intentional — each agent has a single, well-defined job. Narrow inputs produce more consistent outputs.
The .strip().lower() convention: Always normalise classifier output. Models occasionally return "Positive" or " negative " with extra whitespace or capitalisation. Stripping and lowercasing makes downstream comparisons safe.
Create a free account to get started. Paid plans unlock all tracks.