Documentation Index
Fetch the complete documentation index at: https://agno-v2-team-approvals.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Each iteration receives the previous iteration’s output via step_input.get_last_step_content(), enabling iterative processing patterns like accumulation, refinement, and convergence.
This example increments a numeric value by 10 each iteration, stopping when it reaches 50 or more.
loop_iterative_accumulation.py
from agno.workflow import Loop, Step, Workflow
from agno.workflow.types import StepInput, StepOutput
def increment_executor(step_input: StepInput) -> StepOutput:
"""Increment the previous step's numeric content by 10."""
last_content = step_input.get_last_step_content()
if last_content and last_content.isdigit():
new_value = int(last_content) + 10
return StepOutput(content=str(new_value))
return StepOutput(content="0")
workflow = Workflow(
name="Iterative Accumulation Workflow",
steps=[
Step(
name="Initial Value",
executor=lambda step_input: StepOutput(content=step_input.input),
),
Loop(
name="Increment Loop",
steps=[
Step(
name="Increment Step",
executor=increment_executor,
)
],
end_condition=lambda step_outputs: int(step_outputs[-1].content) >= 50,
max_iterations=10,
forward_iteration_output=True, # Default: each iteration gets previous output
),
],
)
if __name__ == "__main__":
# Starting from 35: iteration 1 -> 45, iteration 2 -> 55 (>= 50, stops)
workflow.print_response("35")