-
-
Notifications
You must be signed in to change notification settings - Fork 772
Expand file tree
/
Copy pathworkflow_branching.py
More file actions
51 lines (45 loc) · 1.52 KB
/
workflow_branching.py
File metadata and controls
51 lines (45 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""
Workflow Branching Example
Demonstrates conditional branching in workflows where steps can route
to different next steps based on output content.
"""
from praisonaiagents import AgentFlow, Task
from praisonaiagents import AgentFlowManager
# Create a workflow with branching
workflow = AgentFlow(
name="Decision Workflow",
description="A workflow that branches based on validation result",
steps=[
Task(
name="validate",
action="Check if the number 42 is positive. Reply with 'valid' or 'invalid'.",
routing={
"next_steps": ["success_handler", "error_handler"],
"branches": {
"valid": ["success_handler"],
"invalid": ["error_handler"]
}
}
),
Task(
name="success_handler",
action="The validation passed! Generate a success message."
),
Task(
name="error_handler",
action="The validation failed. Generate an error message."
)
]
)
if __name__ == "__main__":
# Create manager and register workflow
manager = WorkflowManager()
manager.workflows["Decision Workflow"] = workflow
# Execute - will branch to success_handler since 42 is positive
result = manager.execute(
"Decision Workflow",
default_llm="gpt-4o-mini"
)
print("Workflow completed!")
for step_result in result["results"]:
print(f" {step_result['step']}: {step_result['status']}")