Build applications that make decisions (chatbots, agents, simulations, etc...). Monitor, trace, persist, and execute on your own infrastructure.
Python aiburrchatbot-frameworkdagsgenerative-aigraphshacktoberfestllmopsllmsmlopspersistent-data-structurestate-machinestate-managementvisibility
Adds default state() implementation for MapActions
elijahbenizzy3b1840e5700b
diff --git a/burr/core/parallelism.py b/burr/core/parallelism.pyindex e0a6beb7..6c83326d 100644--- a/burr/core/parallelism.py+++ b/burr/core/parallelism.py@@ -628,15 +628,17 @@ class MapActions(MapActionsAndStates, abc.ABC)::return: Generator of actions to run"""- @abc.abstractmethoddef state(self, state: State, inputs: Dict[str, Any]):- """Gives the state for each of the actions+ """Gives the state for each of the actions.+ By default, this will give out the current state. That said,+ you may want to adjust this -- E.G. to translate state into+ a format the sub-actions would expect.:param state: State at the time of running the action:param inputs: Runtime inputs to the action:return: State for the action"""- pass+ return statedef states(self, state: State, context: ApplicationContext, inputs: Dict[str, Any]diff --git a/tests/core/test_parallelism.py b/tests/core/test_parallelism.pyindex 6404414b..4c1f15f3 100644--- a/tests/core/test_parallelism.py+++ b/tests/core/test_parallelism.py@@ -370,6 +370,28 @@ def _group_events_by_app_id(return grouped_events+def test_map_actions_default_state():+ class MapActionsAllApproaches(MapActions):+ def actions(+ self, state: State, inputs: Dict[str, Any], context: ApplicationContext+ ) -> Generator[Union[Action, Callable, RunnableGraph], None, None]:+ ...++ def reduce(self, state: State, states: Generator[State, None, None]) -> State:+ ...++ @property+ def writes(self) -> list[str]:+ return []++ @property+ def reads(self) -> list[str]:+ return []++ state_to_test = State({"foo": "bar", "baz": "qux"})+ assert MapActionsAllApproaches().state(state_to_test, {}).get_all() == state_to_test.get_all()++def test_e2e_map_actions_sync_subgraph():"""Tests map actions over multiple action types (runnable graph, function, action class...)"""