Skip to content

Commit bc85c88

Browse files
Updated the python code sample for routing. (#1779)
* Updated the python code sample for routing. * Simplified the routing sample * Update routes.md add more indent to "if" statement return for readability --------- Co-authored-by: Joe Fernandez <joefernandez@users.noreply.github.com>
1 parent 74c2a2c commit bc85c88

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

docs/graphs/routes.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,24 @@ edges=[
120120
you cannot run multiple interactive chat sessions within the same agent
121121
session.
122122

123-
### Route branches
123+
### Route branches and conditional execution
124124

125125
The subsequent rows of the ***edges*** arrays after the START keyword define
126-
additional execution logic for nodes. For branching paths, you define a node,
127-
usually a ***FunctionNode***, that outputs a ***route*** with one or more route
128-
values. In the edges graph, you define the execution logic with route values and
129-
target nodes, as shown in the following code example:
126+
additional execution logic for nodes. For branching paths, which is how you create a conditional node, you define a node,
127+
usually a ***FunctionNode***, that outputs an Event with a specific ***route*** value. In the edges graph, you then define the conditional execution logic by mapping these route values to target nodes, as shown in the following code example:
130128

131129
```python
132130
def router(node_input: str):
133-
"""Simulate a routing decision"""
134-
return Event(route="RUN_TASK_C")
131+
"""Route to task B or C based on node_input."""
132+
if condition(node_input):
133+
return Event(route="RUN_TASK_C")
134+
return Event(route="RUN_TASK_B")
135+
136+
task_B_node = Agent(name="task_B_agent") # An agent to execute node B
137+
138+
def task_C_node(node_input: str):
139+
"""A FunctionNode to execute node C."""
140+
return Event(output="Task C completed")
135141

136142
root_agent = Workflow(
137143
name="routing_workflow",

0 commit comments

Comments
 (0)