haive.core.graph.branchesΒΆ

Branch system for dynamic routing based on state values.

SubmodulesΒΆ

FunctionsΒΆ

chain(*branches[, default])

Chain multiple branches together, evaluating them in sequence.

conditional(condition, if_true, if_false[, default])

Create a Branch with conditional evaluation.

create_from_send_function(mapper_function)

Create a Send mapper branch from a function that returns Send objects.

from_function(function[, destinations, default])

Create a Branch from a function.

key_equals(key, value[, true_dest, false_dest])

Create a Branch that checks if a key equals a value.

key_exists(key[, true_dest, false_dest])

Create a Branch that checks if a key exists in the state.

message_contains(text[, true_dest, false_dest, ...])

Create a Branch that checks if the last message contains specific text.

send_mapper([function, mappings, generators])

Create a Branch that generates Send objects.

Package ContentsΒΆ

haive.core.graph.branches.chain(*branches, default='END')[source]ΒΆ

Chain multiple branches together, evaluating them in sequence.

Parameters:
Return type:

branch.Branch

haive.core.graph.branches.conditional(condition, if_true, if_false, default='END')[source]ΒΆ

Create a Branch with conditional evaluation.

Parameters:
Return type:

branch.Branch

haive.core.graph.branches.create_from_send_function(mapper_function)[source]ΒΆ

Create a Send mapper branch from a function that returns Send objects.

Parameters:

mapper_function (collections.abc.Callable[[haive.core.graph.common.types.StateLike], list[Any]])

Return type:

branch.Branch

haive.core.graph.branches.from_function(function, destinations=None, default='END')[source]ΒΆ

Create a Branch from a function.

Parameters:
Return type:

branch.Branch

haive.core.graph.branches.key_equals(key, value, true_dest='continue', false_dest='END')[source]ΒΆ

Create a Branch that checks if a key equals a value.

Parameters:
  • key (str)

  • value (Any)

  • true_dest (str)

  • false_dest (str)

Return type:

branch.Branch

haive.core.graph.branches.key_exists(key, true_dest='continue', false_dest='END')[source]ΒΆ

Create a Branch that checks if a key exists in the state.

Parameters:
Return type:

branch.Branch

haive.core.graph.branches.message_contains(text, true_dest='continue', false_dest='END', message_key='messages')[source]ΒΆ

Create a Branch that checks if the last message contains specific text.

Parameters:
  • text (str)

  • true_dest (str)

  • false_dest (str)

  • message_key (str)

Return type:

branch.Branch

haive.core.graph.branches.send_mapper(function=None, mappings=None, generators=None)[source]ΒΆ

Create a Branch that generates Send objects.

Parameters:
Return type:

branch.Branch