Skip to content

armgit / burr

Public Imported from GitHub
0

Build applications that make decisions (chatbots, agents, simulations, etc...). Monitor, trace, persist, and execute on your own infrastructure.

Ensures all keyword arguments are passed to pre/post run call for streaming

elijahbenizzyc6242f06664c
diff --git a/burr/core/application.py b/burr/core/application.py
index c0c22d72..004264f0 100644
--- a/burr/core/application.py
+++ b/burr/core/application.py
@@ -859,7 +859,10 @@ class Application:
state=self._state,
inputs=inputs,
sequence_id=self.sequence_id,
+ app_id=self._uid,
+ partition_key=self._partition_key,
)
+
# we need to track if there's any exceptions that occur during this
try:
@@ -872,10 +875,11 @@ class Application:
result: Optional[dict],
state: State,
exc: Optional[Exception] = None,
- # seq_id=self.sequence_id,
):
self._adapter_set.call_all_lifecycle_hooks_sync(
"post_run_step",
+ app_id=self._uid,
+ partition_key=self._partition_key,
action=next_action,
state=state,
result=result,
@@ -890,6 +894,8 @@ class Application:
action, result, state = self._step(inputs=inputs, _run_hooks=False)
self._adapter_set.call_all_lifecycle_hooks_sync(
"post_run_step",
+ app_id=self._uid,
+ partition_key=self._partition_key,
action=next_action,
state=self._state,
result=result,
@@ -918,6 +924,8 @@ class Application:
# block of the streaming result container
self._adapter_set.call_all_lifecycle_hooks_sync(
"post_run_step",
+ app_id=self._uid,
+ partition_key=self._partition_key,
action=next_action,
state=self._state,
result=None,
diff --git a/tests/core/test_application.py b/tests/core/test_application.py
index e63f9981..68e18575 100644
--- a/tests/core/test_application.py
+++ b/tests/core/test_application.py
@@ -121,11 +121,33 @@ class ActionTracker(PreRunStepHook, PostRunStepHook):
self.pre_called = []
self.post_called = []
- def pre_run_step(self, action: Action, **future_kwargs):
- self.pre_called.append((action.name, future_kwargs))
+ def pre_run_step(
+ self,
+ *,
+ app_id: str,
+ partition_key: str,
+ sequence_id: int,
+ state: "State",
+ action: "Action",
+ inputs: Dict[str, Any],
+ **future_kwargs: Any,
+ ):
+ self.pre_called.append((action.name, locals()))
- def post_run_step(self, action: Action, **future_kwargs):
- self.post_called.append((action.name, future_kwargs))
+ def post_run_step(
+ self,
+ *,
+ app_id: str,
+ partition_key: str,
+ sequence_id: int,
+ state: "State",
+ action: "Action",
+ result: Optional[Dict[str, Any]],
+ exception: Exception,
+ **future_kwargs: Any,
+ ):
+ locals()
+ self.post_called.append((action.name, locals()))
class ActionTrackerAsync(PreRunStepHookAsync, PostRunStepHookAsync):
@@ -1571,21 +1593,22 @@ def test_application_run_step_hooks_sync():
# assert sequence id is incremented
assert tracker.pre_called[0][1]["sequence_id"] == 1
assert tracker.post_called[0][1]["sequence_id"] == 1
- assert set(tracker.pre_called[0][1].keys()) == {
+ assert {
+ "action",
"sequence_id",
"state",
"inputs",
"app_id",
"partition_key",
- }
- assert set(tracker.post_called[0][1].keys()) == {
+ }.issubset(set(tracker.pre_called[0][1].keys()))
+ assert {
"sequence_id",
"result",
"state",
"exception",
"app_id",
"partition_key",
- }
+ }.issubset(set(tracker.post_called[0][1].keys()))
assert len(tracker.pre_called) == 11
assert len(tracker.post_called) == 11
# quick inclusion to ensure that the action is not called when we're done running
@@ -1615,21 +1638,21 @@ async def test_application_run_step_hooks_async():
# assert sequence id is incremented
assert tracker.pre_called[0][1]["sequence_id"] == 1
assert tracker.post_called[0][1]["sequence_id"] == 1
- assert set(tracker.pre_called[0][1].keys()) == {
+ assert {
"sequence_id",
"state",
"inputs",
"app_id",
"partition_key",
- }
- assert set(tracker.post_called[0][1].keys()) == {
+ }.issubset(set(tracker.pre_called[0][1].keys()))
+ assert {
"sequence_id",
"result",
"state",
"exception",
"app_id",
"partition_key",
- }
+ }.issubset(set(tracker.post_called[0][1].keys()))
assert len(tracker.pre_called) == 11
assert len(tracker.post_called) == 11
@@ -1656,36 +1679,37 @@ async def test_application_run_step_runs_hooks():
# assert sequence id is incremented
assert hooks[0].pre_called[0][1]["sequence_id"] == 1
assert hooks[0].post_called[0][1]["sequence_id"] == 1
- assert set(hooks[0].pre_called[0][1].keys()) == {
+ assert {
"sequence_id",
"state",
"inputs",
"app_id",
"partition_key",
- }
- assert set(hooks[1].pre_called[0][1].keys()) == {
+ "action",
+ }.issubset(set(hooks[0].pre_called[0][1].keys()))
+ assert {
"sequence_id",
"state",
"inputs",
"app_id",
"partition_key",
- }
- assert set(hooks[0].post_called[0][1].keys()) == {
+ }.issubset(set(hooks[1].pre_called[0][1].keys()))
+ assert {
"sequence_id",
"result",
"state",
"exception",
"app_id",
"partition_key",
- }
- assert set(hooks[1].post_called[0][1].keys()) == {
+ }.issubset(set(hooks[0].post_called[0][1].keys()))
+ assert {
"sequence_id",
"result",
"state",
"exception",
"app_id",
"partition_key",
- }
+ }.issubset(set(hooks[1].post_called[0][1].keys()))
assert len(hooks[1].pre_called) == 1
assert len(hooks[1].post_called) == 1