Hierarchical teams and handoff filters
Add a manager with process='hierarchical'
In a sequential team, tasks always run 1 -> 2 -> 3. When the order should adapt dynamically, set process='hierarchical' on AgentTeam so a manager model delegates tasks to the right specialist and reviews their work.
Expected output: the manager coordinates the researcher and writer to deliver one polished answer.
Example
from praisonai import Agent, Task, AgentTeam
researcher = Agent(name='Researcher', instructions='Find two crisp facts.')
writer = Agent(name='Writer', instructions='Turn facts into one short sentence.')
team = AgentTeam(
agents=[researcher, writer],
tasks=[
Task(description='Gather two facts about SQLite.', agent=researcher),
Task(description='Summarize those facts for a beginner.', agent=writer),
],
process='hierarchical',
manager_model='gpt-4o-mini',
)
print(team.start())Example explained
- process='hierarchical' — Adds an automatic manager that delegates tasks and checks quality.
- manager_model='gpt-4o-mini' — Selects the LLM model used by the coordinating manager.
Control what crosses a handoff with handoff(…)
When delegating between specialist agents, wrap a target agent in handoff(agent, max_depth=3, detect_cycles=True) to prevent infinite handoff loops and control context policies.
Expected output: the front-desk agent hands off cleanly within safe depth limits.
Example
from praisonai import Agent, handoff
billing = Agent(name='Billing', instructions='Answer refund questions in one sentence.')
triage = Agent(
name='Triage',
instructions='Hand off billing questions to Billing.',
handoffs=[handoff(billing, detect_cycles=True, max_depth=3)],
)
print(triage.start('How long do refunds take?'))Example explained
- handoff(billing, detect_cycles=True, max_depth=3) — Configures safe specialist delegation with loop and depth guards.
Reference: documentation