extract_action_items from yesterday returns a structured list. For your systematic review inclusion step, you need a two-step chain: summarise the abstract, then classify whether it's in scope. summarize_then_classify from Day 7 used system prompts for both. What changes when the classifier uses result_type=Literal?
The summary step stays the same — Agent A with system_prompt="Summarize in 2 sentences.". The classify step replaces the system-prompt approach with result_type=Literal["in scope","out of scope","borderline"]. The Literal guarantees exactly one of those three strings.
Exactly. Agent A produces a string summary; Agent B returns a guaranteed Literal:
summary_agent = Agent(model, system_prompt="Summarize in 2 sentences.")
summary = summary_agent.run_sync(text).output
classify_agent = Agent(model, result_type=Literal["in scope", "out of scope", "borderline"])
return classify_agent.run_sync(summary).outputThe classify agent has no system prompt. How does it know what "in scope" means without context?
Good catch. Without a system prompt, the model uses its own interpretation of the Literal labels. For a systematic review with a specific inclusion criterion, add a system prompt: "You are reviewing abstracts for a meta-analysis on early childhood interventions. Classify as in scope, out of scope, or borderline." The system prompt provides the criterion; the Literal enforces the output shape.
So the system prompt is my inclusion criterion document, and the Literal is my response format. Separated into two clean parameters.
That's the design. Criterion goes in system_prompt; allowed values go in result_type. Both are independently editable.
I could change the inclusion criterion for a different review by just changing the system prompt string. The pipeline structure doesn't change at all.
The reusable filter looks like this:
result = summarize_and_classify(abstract)
if result == "in scope":
included.append(abstract)Same pipeline, different codebook. That's reproducibility in AI-assisted research.
from typing import Literal
summary_agent = Agent(model, system_prompt="Summarize in 2 sentences.")
summary = summary_agent.run_sync(text).output
classify_agent = Agent(
model,
system_prompt="Classify relevance to early childhood intervention research.",
result_type=Literal["in scope", "out of scope", "borderline"]
)
return classify_agent.run_sync(summary).outputsystem_prompt = the inclusion criterion (what counts as relevant)result_type = the allowed output categories (what the model can return)For production systematic reviews, add your inclusion criterion to the classify agent's system prompt: "You are reviewing abstracts for a meta-analysis on structured early childhood interventions aged 0-5. Classify as: in scope, out of scope, or borderline." The Literal constrains the output; the system prompt provides the scientific criterion.
extract_action_items from yesterday returns a structured list. For your systematic review inclusion step, you need a two-step chain: summarise the abstract, then classify whether it's in scope. summarize_then_classify from Day 7 used system prompts for both. What changes when the classifier uses result_type=Literal?
The summary step stays the same — Agent A with system_prompt="Summarize in 2 sentences.". The classify step replaces the system-prompt approach with result_type=Literal["in scope","out of scope","borderline"]. The Literal guarantees exactly one of those three strings.
Exactly. Agent A produces a string summary; Agent B returns a guaranteed Literal:
summary_agent = Agent(model, system_prompt="Summarize in 2 sentences.")
summary = summary_agent.run_sync(text).output
classify_agent = Agent(model, result_type=Literal["in scope", "out of scope", "borderline"])
return classify_agent.run_sync(summary).outputThe classify agent has no system prompt. How does it know what "in scope" means without context?
Good catch. Without a system prompt, the model uses its own interpretation of the Literal labels. For a systematic review with a specific inclusion criterion, add a system prompt: "You are reviewing abstracts for a meta-analysis on early childhood interventions. Classify as in scope, out of scope, or borderline." The system prompt provides the criterion; the Literal enforces the output shape.
So the system prompt is my inclusion criterion document, and the Literal is my response format. Separated into two clean parameters.
That's the design. Criterion goes in system_prompt; allowed values go in result_type. Both are independently editable.
I could change the inclusion criterion for a different review by just changing the system prompt string. The pipeline structure doesn't change at all.
The reusable filter looks like this:
result = summarize_and_classify(abstract)
if result == "in scope":
included.append(abstract)Same pipeline, different codebook. That's reproducibility in AI-assisted research.
from typing import Literal
summary_agent = Agent(model, system_prompt="Summarize in 2 sentences.")
summary = summary_agent.run_sync(text).output
classify_agent = Agent(
model,
system_prompt="Classify relevance to early childhood intervention research.",
result_type=Literal["in scope", "out of scope", "borderline"]
)
return classify_agent.run_sync(summary).outputsystem_prompt = the inclusion criterion (what counts as relevant)result_type = the allowed output categories (what the model can return)For production systematic reviews, add your inclusion criterion to the classify agent's system prompt: "You are reviewing abstracts for a meta-analysis on structured early childhood interventions aged 0-5. Classify as: in scope, out of scope, or borderline." The Literal constrains the output; the system prompt provides the scientific criterion.
Create a free account to get started. Paid plans unlock all tracks.