Route
Technical or general
A route picks one specialist. The first step answers with one word, and that word chooses who speaks next.
If the question mentions Python or a function, the word is technical and the technical expert answers. Any other word uses the general assistant. The result prints the word, then the expert, then the answer.
Example
from praisonai import Agent, AgentFlow, route
def label(ctx):
text = ctx.input.lower()
if "python" in text or "function" in text:
return "technical"
return "general"
tech = Agent(name="TechExpert", instructions="Answer technical questions in one sentence.")
general = Agent(name="GeneralAssistant", instructions="Answer in one sentence.")
flow = AgentFlow(steps=[
label,
route({"technical": [tech], "default": [general]}),
])
result = flow.start("How does a Python function work?")
for step in result["steps"]:
print(step["step"])
print(step["output"])
print()Example explained
- route — A map from a label to the agents that should handle it.
- default — The agents used when the label is anything else.
General path
Ask a non-technical question and confirm default routing.
Example
from praisonai import Agent, AgentFlow, route
def label(ctx):
return "general" if "python" not in ctx.input.lower() else "technical"
tech = Agent(name="TechExpert", instructions="Answer technical questions in one sentence.")
general = Agent(name="GeneralAssistant", instructions="Answer in one sentence.")
flow = AgentFlow(steps=[label, route({"technical": [tech], "default": [general]})])
result = flow.start("What is your refund policy?")
print(result["steps"][-1]["output"])Example explained
- from praisonai import Agent, AgentFlow, route — Imports Agent, AgentFlow, route needed for general path.
- def label — Defines `label` used directly in the general path workflow.
- Agent(…) — Instantiates the Agent configured for general path.
- AgentFlow(…) — Chains agents, branches, parallel steps, or loops in a defined order.
Reference: documentation