Yesterday's word_count_of_output measured the response. But the response was unguided — the model could write three paragraphs or three words. How do you constrain what it produces?
A system prompt — like giving the model a rubric before it answers. That's the system_prompt parameter in the Agent constructor.
Exactly. Agent(model, system_prompt="Summarize in 2 sentences.") means every call to that agent returns a two-sentence summary — nothing longer. The system prompt is the rubric you give a TA before they grade:
def summarize_text(text: str) -> str:
agent = Agent(model, system_prompt="Summarize in 2 sentences.")
result = agent.run_sync(text)
return result.outputWhat's the difference between putting the instruction in the system prompt vs. just adding it to the prompt string?
System prompts set the agent's role and constraints — they're stable across calls. The user prompt is the content that changes each call. Mixing them works for one-offs, but if you build a summariser that you call 40 times in a loop, putting the instruction in system_prompt keeps each call's prompt clean — just the text to summarise:
def summarize_text(text: str) -> str:
agent = Agent(model, system_prompt="Summarize in 2 sentences.")
result = agent.run_sync(text)
summary = result.output
print(f"Summary: {summary}")
return summaryI can use this on my 40 abstracts — loop through the list, call summarize_text on each one, get a list of 40 two-sentence summaries. The pre-filtering is now a data pipeline.
That list of summaries becomes your first-pass reading list. You review the summaries first — 40 × 2 sentences is maybe 15 minutes — then open full PDFs only for the ones that survive that pass.
My advisor spends an hour every week summarising new papers. I'm building a function that does it for me.
You're building a tool for your own workflow. The advisor reads for depth and judgment — you're automating the triage layer. Those are different jobs.
system_prompt parameteragent = Agent(model, system_prompt="Summarize in 2 sentences.")
result = agent.run_sync(text)
return result.outputsystem_prompt sets the agent's persistent instruction — it applies to every call this agent makes. The user prompt (passed to run_sync) is the per-call input the model acts on.
"Summarize in two sentences" is a length constraint, not a format constraint. The model decides what to include — the system prompt just caps the output length. For more control, add content instructions: "Focus on the main finding and the method used."
Create the agent once and call run_sync in a loop to summarize multiple texts with the same instruction.
Yesterday's word_count_of_output measured the response. But the response was unguided — the model could write three paragraphs or three words. How do you constrain what it produces?
A system prompt — like giving the model a rubric before it answers. That's the system_prompt parameter in the Agent constructor.
Exactly. Agent(model, system_prompt="Summarize in 2 sentences.") means every call to that agent returns a two-sentence summary — nothing longer. The system prompt is the rubric you give a TA before they grade:
def summarize_text(text: str) -> str:
agent = Agent(model, system_prompt="Summarize in 2 sentences.")
result = agent.run_sync(text)
return result.outputWhat's the difference between putting the instruction in the system prompt vs. just adding it to the prompt string?
System prompts set the agent's role and constraints — they're stable across calls. The user prompt is the content that changes each call. Mixing them works for one-offs, but if you build a summariser that you call 40 times in a loop, putting the instruction in system_prompt keeps each call's prompt clean — just the text to summarise:
def summarize_text(text: str) -> str:
agent = Agent(model, system_prompt="Summarize in 2 sentences.")
result = agent.run_sync(text)
summary = result.output
print(f"Summary: {summary}")
return summaryI can use this on my 40 abstracts — loop through the list, call summarize_text on each one, get a list of 40 two-sentence summaries. The pre-filtering is now a data pipeline.
That list of summaries becomes your first-pass reading list. You review the summaries first — 40 × 2 sentences is maybe 15 minutes — then open full PDFs only for the ones that survive that pass.
My advisor spends an hour every week summarising new papers. I'm building a function that does it for me.
You're building a tool for your own workflow. The advisor reads for depth and judgment — you're automating the triage layer. Those are different jobs.
system_prompt parameteragent = Agent(model, system_prompt="Summarize in 2 sentences.")
result = agent.run_sync(text)
return result.outputsystem_prompt sets the agent's persistent instruction — it applies to every call this agent makes. The user prompt (passed to run_sync) is the per-call input the model acts on.
"Summarize in two sentences" is a length constraint, not a format constraint. The model decides what to include — the system prompt just caps the output length. For more control, add content instructions: "Focus on the main finding and the method used."
Create the agent once and call run_sync in a loop to summarize multiple texts with the same instruction.
Create a free account to get started. Paid plans unlock all tracks.