You have a summarizer agent and a sentiment classifier agent. What happens if you feed the output of the first one directly into the second?
You'd get sentiment based on the summary instead of the full text — a classifier reading a condensed version of the input?
Exactly. And here is the key point — there is no special "pipeline" syntax for this. It is Python variables. You run the first agent, store its output, then pass that string to the second agent's run_sync:
summary = summarize_agent.run_sync(text).output
label = classify_agent.run_sync(summary).outputTwo calls, two outputs, one variable connecting them. That is the entire pattern.
Two separate Agent objects, not one reused?
Two separate ones because they have different roles — one summarizes, one classifies. Each Agent holds a system_prompt, so one agent per role keeps the prompts distinct. The calls themselves are independent; agents do not share memory across run_sync:
def summarize_then_classify(text: str) -> str:
summarize_agent = Agent(model, system_prompt="Summarize the text in 1-2 sentences. Return only the summary.")
summary = summarize_agent.run_sync(text).output
classify_agent = Agent(model, system_prompt="Classify the sentiment of the text. Reply with exactly one word: positive, neutral, or negative.")
return classify_agent.run_sync(summary).output.strip().lower()Why summarize first? Can't the classifier read the full text?
It can, but accuracy drops on noisy input. A five-paragraph complaint has timestamps, order numbers, pleasantries — a lot of signal the classifier has to wade through. Summarizing first strips the noise so the classifier sees a clean 1-2 sentence version. Cheaper and more accurate.
So this is the building block for any multi-step AI pipeline — any number of agents wired in series?
Every complex AI pipeline in production is built from this shape: run an agent, store the output, pass it to the next. Write summarize_then_classify(text) now — two agents, two run_sync calls, the summary flowing into the classifier.
TL;DR: chain agents by passing one's .output as the next one's input.
| Step | Call | Output |
|---|---|---|
| 1 | summarize_agent.run_sync(text) | summary string |
| 2 | classify_agent.run_sync(summary) | sentiment label |
| 3 | .strip().lower() on label | clean string |
Each run_sync is stateless — agents never see each other's conversations.
You have a summarizer agent and a sentiment classifier agent. What happens if you feed the output of the first one directly into the second?
You'd get sentiment based on the summary instead of the full text — a classifier reading a condensed version of the input?
Exactly. And here is the key point — there is no special "pipeline" syntax for this. It is Python variables. You run the first agent, store its output, then pass that string to the second agent's run_sync:
summary = summarize_agent.run_sync(text).output
label = classify_agent.run_sync(summary).outputTwo calls, two outputs, one variable connecting them. That is the entire pattern.
Two separate Agent objects, not one reused?
Two separate ones because they have different roles — one summarizes, one classifies. Each Agent holds a system_prompt, so one agent per role keeps the prompts distinct. The calls themselves are independent; agents do not share memory across run_sync:
def summarize_then_classify(text: str) -> str:
summarize_agent = Agent(model, system_prompt="Summarize the text in 1-2 sentences. Return only the summary.")
summary = summarize_agent.run_sync(text).output
classify_agent = Agent(model, system_prompt="Classify the sentiment of the text. Reply with exactly one word: positive, neutral, or negative.")
return classify_agent.run_sync(summary).output.strip().lower()Why summarize first? Can't the classifier read the full text?
It can, but accuracy drops on noisy input. A five-paragraph complaint has timestamps, order numbers, pleasantries — a lot of signal the classifier has to wade through. Summarizing first strips the noise so the classifier sees a clean 1-2 sentence version. Cheaper and more accurate.
So this is the building block for any multi-step AI pipeline — any number of agents wired in series?
Every complex AI pipeline in production is built from this shape: run an agent, store the output, pass it to the next. Write summarize_then_classify(text) now — two agents, two run_sync calls, the summary flowing into the classifier.
TL;DR: chain agents by passing one's .output as the next one's input.
| Step | Call | Output |
|---|---|---|
| 1 | summarize_agent.run_sync(text) | summary string |
| 2 | classify_agent.run_sync(summary) | sentiment label |
| 3 | .strip().lower() on label | clean string |
Each run_sync is stateless — agents never see each other's conversations.
Create a free account to get started. Paid plans unlock all tracks.