BotsOnRails Quickstart
This guide will walk you through the key steps and concepts for building a workflow using BotsOnRails.
Defining Nodes
The key building block in BotsOnRails is a node, which represents a single task or decision point in your workflow. Nodes are defined using normal Python functions, with a few key additions:
- Use the
@node
decorator to indicate that a function is a workflow node. At least one node must havepath_start=True
- Add type annotations to the function indicating the expected input and output types
- Optionally specify a
next_step
argument indicating which node(s) to execute next
Here's an example node definition:
# Compile the execution tree
from BotsOnRails import ExecutionPath, step_decorator_for_path
path = ExecutionPath()
step = step_decorator_for_path(path)
@step(next_nodes="process_text", path_start=True)
def get_user_input() -> str:
return input("Please enter some text: ")
@step()
def process_text(text: str) -> str:
return text.upper()
path.compile(type_checking=True)
path.visualize_via_graphviz()
Building a Workflow
To build a complete workflow, define an ExecutionPath
and add your node functions to it:
from BotsOnRails import ExecutionPath, step_decorator_for_path
path = ExecutionPath()
step = step_decorator_for_path(path)
@step(path_start=True, next_step="process_text")
def get_user_input() -> str:
return input("Please enter some text: ")
@step()
def process_text(text: str) -> str:
return text.upper()
Use the path_start=True
argument to indicate which step is the entry point for the path.
Executing a Workflow
To run the workflow, first compile it (you only have to do this once), then call the run
method:
path.compile()
path.run()
This will execute the workflow starting from the designated start node.
Next Steps
That covers the basic concepts! For more advanced topics, check out:
- The Node Syntax Guide to learn more techniques for defining nodes and routing
- The For Each Guide to understand BotsOnRails' looping functionality
- The Validation Rules to understand the guardrails BotsOnRails provides
Happy bot building!