You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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>
Copy file name to clipboardExpand all lines: docs/graphs/routes.md
+13-7Lines changed: 13 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -120,18 +120,24 @@ edges=[
120
120
you cannot run multiple interactive chat sessions within the same agent
121
121
session.
122
122
123
-
### Route branches
123
+
### Route branches and conditional execution
124
124
125
125
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:
130
128
131
129
```python
132
130
defrouter(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
0 commit comments