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.

Adds inputs as parameter to pre-run-step hook

elijahbenizzyc3ac9ec10733
diff --git a/burr/core/application.py b/burr/core/application.py
index 89bb529a..84936738 100644
--- a/burr/core/application.py
+++ b/burr/core/application.py
@@ -224,7 +224,7 @@ class Application:
inputs = {}
if _run_hooks:
self._adapter_set.call_all_lifecycle_hooks_sync(
- "pre_run_step", action=next_action, state=self._state
+ "pre_run_step", action=next_action, state=self._state, inputs=inputs
)
exc = None
result = None
@@ -266,7 +266,7 @@ class Application:
if next_action is None:
return None
await self._adapter_set.call_all_lifecycle_hooks_sync_and_async(
- "pre_run_step", action=next_action, state=self._state
+ "pre_run_step", action=next_action, state=self._state, inputs=inputs
)
exc = None
result = None
diff --git a/burr/lifecycle/base.py b/burr/lifecycle/base.py
index 43644713..de8f23f6 100644
--- a/burr/lifecycle/base.py
+++ b/burr/lifecycle/base.py
@@ -1,5 +1,5 @@
import abc
-from typing import TYPE_CHECKING, Any, Optional, Union
+from typing import TYPE_CHECKING, Any, Dict, Optional, Union
if TYPE_CHECKING:
# type-checking-only for a circular import
@@ -13,11 +13,14 @@ class PreRunStepHook(abc.ABC):
"""Hook that runs before a step is executed"""
@abc.abstractmethod
- def pre_run_step(self, *, state: "State", action: "Action", **future_kwargs: Any):
+ def pre_run_step(
+ self, *, state: "State", action: "Action", inputs: Dict[str, Any], **future_kwargs: Any
+ ):
"""Run before a step is executed.
:param state: State prior to step execution
:param action: Action to be executed
+ :param inputs: Inputs to the action
:param future_kwargs: Future keyword arguments
"""
pass
@@ -28,11 +31,14 @@ class PreRunStepHookAsync(abc.ABC):
"""Async hook that runs before a step is executed"""
@abc.abstractmethod
- async def pre_run_step(self, *, state: "State", action: "Action", **future_kwargs: Any):
+ async def pre_run_step(
+ self, *, state: "State", action: "Action", inputs: Dict[str, Any], **future_kwargs: Any
+ ):
"""Async run before a step is executed.
:param state: State prior to step execution
:param action: Action to be executed
+ :param inputs: Inputs to the action
:param future_kwargs: Future keyword arguments
"""
pass
@@ -48,7 +54,7 @@ class PostRunStepHook(abc.ABC):
*,
state: "State",
action: "Action",
- result: Optional[dict],
+ result: Optional[Dict[str, Any]],
exception: Exception,
**future_kwargs: Any,
):