diff --git a/bedrock/entity/workflows.py b/bedrock/entity/workflows.py index 710f09160..d705faa68 100644 --- a/bedrock/entity/workflows.py +++ b/bedrock/entity/workflows.py @@ -18,7 +18,11 @@ class BedrockParams: @workflow.defn class EntityBedrockWorkflow: - def __init__(self) -> None: + # Using @workflow.init means this constructor runs before any signal or + # query handler, so the workflow arguments are applied to the state before a + # message can observe or mutate it. + @workflow.init + def __init__(self, params: BedrockParams) -> None: # List to store prompt history self.conversation_history: List[Tuple[str, str]] = [] self.prompt_queue: Deque[str] = deque() @@ -26,11 +30,6 @@ def __init__(self) -> None: self.continue_as_new_per_turns: int = 6 self.chat_ended: bool = False - @workflow.run - async def run( - self, - params: BedrockParams, - ) -> str: if params and params.conversation_summary: self.conversation_history.append( ("conversation_summary", params.conversation_summary) @@ -41,6 +40,11 @@ async def run( if params and params.prompt_queue: self.prompt_queue.extend(params.prompt_queue) + @workflow.run + async def run( + self, + params: BedrockParams, + ) -> str: while True: workflow.logger.info("Waiting for prompts...")