Loop
Three words
A loop repeats one step for each thing in a list you wrote.
The list is search, memory, and tools. Each pass hands the agent just that one word, and you get one line back.
Example
from praisonai import Agent, AgentFlow, Task, loop
processor = Agent(instructions="Repeat the input word, then two more words.")
step = Task(name="Processor", action="{{item}}", agent=processor)
flow = AgentFlow(
steps=[loop(step, over="items")],
variables={"items": ["search", "memory", "tools"]},
)
result = flow.start()
for item in result["steps"]:
print(item["output"])Example explained
- over — The name of the list to walk.
- variables — The lists and values the flow can read.
- {{item}} — The current element. The default name is item.
Longer list
Add one more item and confirm the loop runs once per element.
Example
from praisonai import Agent, AgentFlow, Task, loop
processor = Agent(instructions="Output only the input word.")
step = Task(name="Processor", action="{{item}}", agent=processor)
flow = AgentFlow(
steps=[loop(step, over="items")],
variables={"items": ["build", "deploy", "observe", "govern"]},
)
result = flow.start()
print(len(result["steps"]), "iterations")Example explained
- from praisonai import Agent, AgentFlow, Task, loop — Imports Agent, AgentFlow, Task, loop needed for longer list.
- Agent(…) — Instantiates the Agent configured for longer list.
- Task(…) — Defines a concrete unit of work assigned to a specific agent.
- AgentFlow(…) — Chains agents, branches, parallel steps, or loops in a defined order.
Reference: documentation