transition_builder#

class besser.agent.core.transition.transition_builder.TransitionBuilder(source, event=None, condition=None)[source]#

Bases: object

A transition builder.

This class is used to build agent transitions, allowing for a “fluent api” syntax where consecutive calls can be made on the same object.

Parameters:
  • source (State) – the source state of the transition

  • event (Event) – the event linked to the transition (can be None)

  • condition (Condition) – the condition associated to the transition (can be None)

source#

The source state of the transition

Type:

State

event#

The event linked to the transition (can be None)

Type:

Event

condition#

The condition associated to the transition (can be None)

Type:

Condition

go_to(dest)[source]#

Set the destination state of the transition.

Completes the transition builder and effectively adds the source state.

Parameters:

dest (State) – the destination state

with_condition(function, params=None)[source]#

Adds a condition to the transition builder.

Parameters:
  • function (Union[Callable[[Session], bool], Callable[[Session, dict], bool]]) – the condition function to add to the transition. Allowed function arguments are (Session) or (Session, dict) to add parameters within the dict argument. The function must return a boolean value

  • params (dict, optional) – the parameters for the condition function, necessary if the function has (Session, dict) arguments

Returns:

the transition builder with the new condition added

Return type:

TransitionBuilder