edit_output.py
Run the Example
1
Set up your virtual environment
2
Install dependencies
3
Export your OpenAI API key
4
Run the example
Save the code above as
edit_output.py, then run:Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Allow humans to edit step output directly instead of retrying, avoiding extra LLM calls.
"""
Edit Output Example
This example demonstrates human editing of step output using the HITL config.
Instead of rejecting and retrying (which costs another LLM call), the human
directly modifies the output before it flows to the next step.
The human can:
- confirm(): Accept the output as-is
- reject(): Reject (skip/cancel/retry depending on on_reject)
- edit(new_output): Accept with modifications
"""
from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.models.openai import OpenAIResponses
from agno.workflow import OnReject
from agno.workflow.step import Step
from agno.workflow.types import HumanReview
from agno.workflow.workflow import Workflow
draft_agent = Agent(
name="Drafter",
model=OpenAIResponses(id="gpt-5.4"),
instructions="You draft short professional emails. Keep it under 3 sentences.",
)
send_agent = Agent(
name="Sender",
model=OpenAIResponses(id="gpt-5.4"),
instructions="You confirm sending the email. Summarize what was sent.",
)
workflow = Workflow(
name="email_edit_workflow",
db=SqliteDb(db_file="tmp/output_review_edit.db"),
steps=[
Step(
name="draft_email",
agent=draft_agent,
human_review=HumanReview(
requires_output_review=True,
output_review_message="Review and optionally edit the email draft",
on_reject=OnReject.cancel,
),
),
Step(
name="send_email",
agent=send_agent,
),
],
)
run_output = workflow.run(
"Draft an email to the team about the Friday standup being moved to Monday"
)
if run_output.is_paused:
for requirement in run_output.steps_requiring_output_review:
print(
f"\nDraft output:\n{requirement.step_output.content if requirement.step_output else 'N/A'}"
)
choice = input("\n[a]pprove / [e]dit / [r]eject: ").strip().lower()
if choice == "a":
requirement.confirm()
elif choice == "e":
edited = input("Enter your edited version:\n")
requirement.edit(edited)
print("Output replaced with your edit.")
else:
requirement.reject()
print("Draft rejected - cancelling workflow.")
run_output = workflow.continue_run(run_output)
print(f"\nFinal status: {run_output.status}")
print(f"Final output: {run_output.content}")
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
Install dependencies
uv pip install -U agno fastapi openai sqlalchemy
Export your OpenAI API key
export OPENAI_API_KEY="your_openai_api_key_here"
$Env:OPENAI_API_KEY="your_openai_api_key_here"
Run the example
edit_output.py, then run:python edit_output.py
Was this page helpful?