Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions docs/graphs/routes.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,24 @@ edges=[
you cannot run multiple interactive chat sessions within the same agent
session.

### Route branches
### Route branches and conditional execution

The subsequent rows of the ***edges*** arrays after the START keyword define
additional execution logic for nodes. For branching paths, you define a node,
usually a ***FunctionNode***, that outputs a ***route*** with one or more route
values. In the edges graph, you define the execution logic with route values and
target nodes, as shown in the following code example:
additional execution logic for nodes. For branching paths, which is how you create a conditional node, you define a node,
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:

```python
Comment thread
joefernandez marked this conversation as resolved.
def router(node_input: str):
"""Simulate a routing decision"""
return Event(route="RUN_TASK_C")
"""Route to task B or C based on node_input."""
if condition(node_input):
return Event(route="RUN_TASK_C")
return Event(route="RUN_TASK_B")

task_B_node = Agent(name="task_B_agent") # An agent to execute node B

def task_C_node(node_input: str):
"""A FunctionNode to execute node C."""
return Event(output="Task C completed")

root_agent = Workflow(
name="routing_workflow",
Expand Down
Loading