Add multiple "to"s in transitions #339
-
|
I noticed that the "from" in a transition can be a list of strings. So multiple actions can go to the same action if a certain condition is met: def with_transitions(
self,
*transitions: Union[
Tuple[Union[str, list[str]], Union[str, list[str]]],
Tuple[Union[str, list[str]], Union[str, list[str]], Condition],
],
) -> "GraphBuilder":
"""Adds transitions to the graph. Transitions are specified as tuples of either:
1. (from, to, condition)
2. (from, to) -- condition is set to DEFAULT (which is a fallback)
Transitions will be evaluated in order of specification -- if one is met, the others will not be evaluated.
Note that one transition can be terminal -- the system doesn't have
:param transitions: Transitions to add
:return: The application builder for future chaining.
"""
if self.transitions is None:
self.transitions = []
for transition in transitions:
from_, to_, *conditions = transition
if len(conditions) > 0:
condition = conditions[0]
else:
condition = default
if not isinstance(from_, list):
from_ = [from_]
if not isinstance(to_, list):
to_ = [to_]
for action_from in from_:
for action_to in to_:
if not isinstance(action_from, str):
raise ValueError(
f"Transition source must be a string, not {action_from}"
)
if not isinstance(action_to, str):
raise ValueError(
f"Transition target must be a string, not {action_to}"
)
self.transitions.append((action_from, action_to, condition))
return self |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 14 replies
-
|
[post script] after Elijah's comment below, yeah what's the context that this would make sense for? [/post script] |
Beta Was this translation helpful? Give feedback.
-
|
FYI Parallelism V1 shipped with shipped with |
Beta Was this translation helpful? Give feedback.

OK. So the way I'd model it is, given:
get_question,A)answer_question,B)evaluate_answer,C)final,D)A->B(always try to answer first)B->C(then always evaluate the answerC->B, if attempts < max_attempts (make sureCincrements attempts as well, or stores a history of actions)C->Dif attempts >= max_attemptsNote that you could also go
A->B,B->C, andC->A, while also goingA->Dif ready. I'm not 100% sure this captures your case though...My issue with the phrasing of "AND" is it's really to a chain of them (which is fair), but
ANDcould mean parallel, in series, etc... And it's not clear from this.One other o…