Day 13 summarized a ticket and then classified its urgency — but only returned the urgency. What changes if callers want both the summary and the label?
You'd store the summary in a variable instead of discarding it, then return both in a dict?
Exactly the pipeline mindset — keep every step's output, bundle them at the end. The chain doesn't change; you just stop throwing the intermediate away. Same two agents as Day 13 with one extra key in the return:
summary = summarize_agent.run_sync(text).output
urgency = urgency_agent.run_sync(summary).output
return {"summary": summary, "urgency": urgency}That is the whole pipeline pattern? Just don't throw intermediate results away?
That is most of it. The real discipline is deciding what to keep. The summary is valuable — callers can show it in a dashboard, log it, or feed it into a third agent. If you only return the urgency, the caller has to regenerate the summary next time. Keeping both is free because the value is already in memory:
from typing import Literal
def ai_pipeline(text: str) -> dict:
summarize_agent = Agent(model, system_prompt="Summarize the following text in 1-2 sentences.")
summary = summarize_agent.run_sync(text).output
urgency_agent = Agent(model, result_type=Literal["high", "medium", "low"])
urgency = urgency_agent.run_sync(summary).output
return {"summary": summary, "urgency": urgency}And the return is a plain dict — no Pydantic because the keys are fixed and the values are already typed strings?
Exactly. Pydantic earns its weight when the model fills in fields; here your code assembles the dict from two known variables. A dict literal is cheaper and reads clearly.
So a content-moderation pipeline would be the same pattern — summarize, classify, score toxicity, store all three and return them together?
That shape scales. Every additional step is one more variable, one more key. Add a topic classifier, add a language detector — the code extends linearly. Write ai_pipeline(text) now: two agents, keep both, return {"summary": summary, "urgency": urgency}.
TL;DR: chain agents and bundle every intermediate into the return dict.
Literal-typed label for routing| Return | Callers can |
|---|---|
Only urgency | Route, but regenerate the summary later |
{summary, urgency} | Display, route, and log — free |
Pipeline mindset: preserve intermediates, because the cost of keeping them is zero.
Day 13 summarized a ticket and then classified its urgency — but only returned the urgency. What changes if callers want both the summary and the label?
You'd store the summary in a variable instead of discarding it, then return both in a dict?
Exactly the pipeline mindset — keep every step's output, bundle them at the end. The chain doesn't change; you just stop throwing the intermediate away. Same two agents as Day 13 with one extra key in the return:
summary = summarize_agent.run_sync(text).output
urgency = urgency_agent.run_sync(summary).output
return {"summary": summary, "urgency": urgency}That is the whole pipeline pattern? Just don't throw intermediate results away?
That is most of it. The real discipline is deciding what to keep. The summary is valuable — callers can show it in a dashboard, log it, or feed it into a third agent. If you only return the urgency, the caller has to regenerate the summary next time. Keeping both is free because the value is already in memory:
from typing import Literal
def ai_pipeline(text: str) -> dict:
summarize_agent = Agent(model, system_prompt="Summarize the following text in 1-2 sentences.")
summary = summarize_agent.run_sync(text).output
urgency_agent = Agent(model, result_type=Literal["high", "medium", "low"])
urgency = urgency_agent.run_sync(summary).output
return {"summary": summary, "urgency": urgency}And the return is a plain dict — no Pydantic because the keys are fixed and the values are already typed strings?
Exactly. Pydantic earns its weight when the model fills in fields; here your code assembles the dict from two known variables. A dict literal is cheaper and reads clearly.
So a content-moderation pipeline would be the same pattern — summarize, classify, score toxicity, store all three and return them together?
That shape scales. Every additional step is one more variable, one more key. Add a topic classifier, add a language detector — the code extends linearly. Write ai_pipeline(text) now: two agents, keep both, return {"summary": summary, "urgency": urgency}.
TL;DR: chain agents and bundle every intermediate into the return dict.
Literal-typed label for routing| Return | Callers can |
|---|---|
Only urgency | Route, but regenerate the summary later |
{summary, urgency} | Display, route, and log — free |
Pipeline mindset: preserve intermediates, because the cost of keeping them is zero.
Create a free account to get started. Paid plans unlock all tracks.