You've run one agent per call. What happens when you need to see the same content rendered two different ways — a formal abstract summary and a plain-language version for a general audience?
Create two agents with different system prompts — one with 'Write in formal academic English' and one with 'Explain in plain language for a non-specialist'. Run both on the same text and return a dict with both outputs.
That's the two-persona pattern. Two agents, one input, two outputs in a single dict. The code is just two agent instantiations and two run_sync calls:
def compare_tones(text: str) -> dict:
formal = Agent(model, system_prompt="Summarize in formal academic English in 2 sentences.")
casual = Agent(model, system_prompt="Explain in plain language for a non-specialist in 2 sentences.")
formal_out = formal.run_sync(text).output
casual_out = casual.run_sync(text).output
return {"formal": formal_out, "casual": casual_out}Why not just change the system prompt between calls? Why create two separate agent objects?
Creating two agents makes the code readable and each agent reusable. If you need to run 40 abstracts through both tones, you create the two agent objects once outside the loop and call .run_sync(abstract) in the loop body. Creating them inside the function works fine for a single call — both approaches are valid:
def compare_tones(text: str) -> dict:
formal = Agent(model, system_prompt="Summarize in formal academic English in 2 sentences.")
casual = Agent(model, system_prompt="Explain in plain language for a non-specialist in 2 sentences.")
formal_out = formal.run_sync(text).output
casual_out = casual.run_sync(text).output
print(f"Formal: {formal_out[:50]}...")
print(f"Casual: {casual_out[:50]}...")
return {"formal": formal_out, "casual": casual_out}I can use this to generate a thesis abstract version and a lay summary version of the same section — both from one function call. Many journals require both.
Journal lay summaries are increasingly required for open-access publications. Having a function that generates both from the same input is practically useful — not just an exercise.
My university's communications office asks for a 'plain English' version of every thesis abstract. Now I have a function for that.
You'd still review and edit the casual version before submitting it. The agent produces a draft — the judgment of what's accurate and accessible is yours.
formal = Agent(model, system_prompt="Formal academic...")
casual = Agent(model, system_prompt="Plain language...")
return {"formal": formal.run_sync(text).output, "casual": casual.run_sync(text).output}Each agent has one job defined by its system prompt. The same model produces different tones because the system prompt shifts its register. You don't need different models — one model, two prompts, two outputs.
Return a dict when both outputs are useful to the caller. Keys become column names in a DataFrame or table. The caller can display both and let a human choose the preferred tone.
You've run one agent per call. What happens when you need to see the same content rendered two different ways — a formal abstract summary and a plain-language version for a general audience?
Create two agents with different system prompts — one with 'Write in formal academic English' and one with 'Explain in plain language for a non-specialist'. Run both on the same text and return a dict with both outputs.
That's the two-persona pattern. Two agents, one input, two outputs in a single dict. The code is just two agent instantiations and two run_sync calls:
def compare_tones(text: str) -> dict:
formal = Agent(model, system_prompt="Summarize in formal academic English in 2 sentences.")
casual = Agent(model, system_prompt="Explain in plain language for a non-specialist in 2 sentences.")
formal_out = formal.run_sync(text).output
casual_out = casual.run_sync(text).output
return {"formal": formal_out, "casual": casual_out}Why not just change the system prompt between calls? Why create two separate agent objects?
Creating two agents makes the code readable and each agent reusable. If you need to run 40 abstracts through both tones, you create the two agent objects once outside the loop and call .run_sync(abstract) in the loop body. Creating them inside the function works fine for a single call — both approaches are valid:
def compare_tones(text: str) -> dict:
formal = Agent(model, system_prompt="Summarize in formal academic English in 2 sentences.")
casual = Agent(model, system_prompt="Explain in plain language for a non-specialist in 2 sentences.")
formal_out = formal.run_sync(text).output
casual_out = casual.run_sync(text).output
print(f"Formal: {formal_out[:50]}...")
print(f"Casual: {casual_out[:50]}...")
return {"formal": formal_out, "casual": casual_out}I can use this to generate a thesis abstract version and a lay summary version of the same section — both from one function call. Many journals require both.
Journal lay summaries are increasingly required for open-access publications. Having a function that generates both from the same input is practically useful — not just an exercise.
My university's communications office asks for a 'plain English' version of every thesis abstract. Now I have a function for that.
You'd still review and edit the casual version before submitting it. The agent produces a draft — the judgment of what's accurate and accessible is yours.
formal = Agent(model, system_prompt="Formal academic...")
casual = Agent(model, system_prompt="Plain language...")
return {"formal": formal.run_sync(text).output, "casual": casual.run_sync(text).output}Each agent has one job defined by its system prompt. The same model produces different tones because the system prompt shifts its register. You don't need different models — one model, two prompts, two outputs.
Return a dict when both outputs are useful to the caller. Keys become column names in a DataFrame or table. The caller can display both and let a human choose the preferred tone.
Create a free account to get started. Paid plans unlock all tracks.