Skip to content

Condition

junjo.Condition

Kind: Class

SDK version: 0.64.0

Documentation channel: Next source preview

View source

Abstract base class for edge conditions in a workflow graph.

Implement a concrete condition that determines whether a transition along an edge should occur based only on the current state.

This is designed to be used with the Edge class, which represents a directed edge in the workflow graph. The condition is evaluated when determining whether to transition from the tail node to the head node.

StateT is the state type that the condition evaluates against. It should be a subclass of BaseState.

Conditions should follow these rules:

  • The condition should be stateless and depend only on the current state.
  • Do not use side effects in the condition, such as network calls or database queries.
  • The condition should be a pure function of the state.

.. rubric:: Example

``python class MyCondition(Condition[MyState]): def evaluate(self, state: MyState) -> bool: return state.some_property == “some_value”

my_condition = MyCondition() edges = [ Edge(tail=node_1, head=node_2, condition=my_condition), Edge(tail=node_2, head=node_3), ] ``

evaluate(state: StateT) -> bool

View source

Evaluate whether the transition should occur based on the current workflow state.

Name Type Description Default
state StateT The current workflow state.
  • bool: True if the transition should occur, False otherwise.