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.
Reference: documentation