From 31e97d40aa4a660216832a06a931d3812f31dc8c Mon Sep 17 00:00:00 2001 From: Diwank Singh Tomer Date: Tue, 3 Sep 2024 16:32:27 -0400 Subject: [PATCH 1/2] fix: Change log-step to a jinja template rather than a simpleeval expression Signed-off-by: Diwank Singh Tomer --- agents-api/agents_api/activities/task_steps/log_step.py | 6 +++--- agents-api/tests/test_execution_workflow.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/agents-api/agents_api/activities/task_steps/log_step.py b/agents-api/agents_api/activities/task_steps/log_step.py index b33409474..4793c9760 100644 --- a/agents-api/agents_api/activities/task_steps/log_step.py +++ b/agents-api/agents_api/activities/task_steps/log_step.py @@ -6,8 +6,8 @@ StepContext, StepOutcome, ) +from ...common.utils.template import render_template from ...env import testing -from .base_evaluate import base_evaluate @beartype @@ -17,8 +17,8 @@ async def log_step(context: StepContext) -> StepOutcome: try: assert isinstance(context.current_step, LogStep) - expr: str = context.current_step.log - output = await base_evaluate(expr, context.model_dump()) + template: str = context.current_step.log + output = await render_template(template, context.model_dump(), skip_vars=["developer_id"]) result = StepOutcome(output=output) return result diff --git a/agents-api/tests/test_execution_workflow.py b/agents-api/tests/test_execution_workflow.py index 9cd12bb8f..0aab5a42f 100644 --- a/agents-api/tests/test_execution_workflow.py +++ b/agents-api/tests/test_execution_workflow.py @@ -407,7 +407,7 @@ async def _( "other_workflow": [ # Testing that we can access the input {"evaluate": {"hello": '_["test"]'}}, - {"log": '_["hell"]'}, # <--- The "hell" key does not exist + {"log": '{{_["hello"]}}'}, # <--- The "hell" key does not exist ], "main": [ # Testing that we can access the input @@ -422,7 +422,7 @@ async def _( ) async with patch_testing_temporal() as (_, mock_run_task_execution_workflow): - with raises(BaseException): + # with raises(BaseException): execution, handle = await start_execution( developer_id=developer_id, task_id=task.id, From df220b4fa3df891fcd1ecc0f9264a78364c9f0d9 Mon Sep 17 00:00:00 2001 From: HamadaSalhab Date: Thu, 5 Sep 2024 02:11:27 +0300 Subject: [PATCH 2/2] Fix 'workflow: log step expression fail' test & run poe check --- .../agents_api/activities/task_steps/get_value_step.py | 1 - agents-api/agents_api/activities/task_steps/log_step.py | 4 +++- agents-api/tests/test_execution_workflow.py | 6 ++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/agents-api/agents_api/activities/task_steps/get_value_step.py b/agents-api/agents_api/activities/task_steps/get_value_step.py index 6f505cb49..cda00789e 100644 --- a/agents-api/agents_api/activities/task_steps/get_value_step.py +++ b/agents-api/agents_api/activities/task_steps/get_value_step.py @@ -1,4 +1,3 @@ - from beartype import beartype from temporalio import activity diff --git a/agents-api/agents_api/activities/task_steps/log_step.py b/agents-api/agents_api/activities/task_steps/log_step.py index 4793c9760..34def9bf2 100644 --- a/agents-api/agents_api/activities/task_steps/log_step.py +++ b/agents-api/agents_api/activities/task_steps/log_step.py @@ -18,7 +18,9 @@ async def log_step(context: StepContext) -> StepOutcome: assert isinstance(context.current_step, LogStep) template: str = context.current_step.log - output = await render_template(template, context.model_dump(), skip_vars=["developer_id"]) + output = await render_template( + template, context.model_dump(), skip_vars=["developer_id"] + ) result = StepOutcome(output=output) return result diff --git a/agents-api/tests/test_execution_workflow.py b/agents-api/tests/test_execution_workflow.py index 0aab5a42f..74ae70f29 100644 --- a/agents-api/tests/test_execution_workflow.py +++ b/agents-api/tests/test_execution_workflow.py @@ -407,7 +407,9 @@ async def _( "other_workflow": [ # Testing that we can access the input {"evaluate": {"hello": '_["test"]'}}, - {"log": '{{_["hello"]}}'}, # <--- The "hell" key does not exist + { + "log": '{{_["hell"].strip()}}' + }, # <--- The "hell" key does not exist ], "main": [ # Testing that we can access the input @@ -422,7 +424,7 @@ async def _( ) async with patch_testing_temporal() as (_, mock_run_task_execution_workflow): - # with raises(BaseException): + with raises(BaseException): execution, handle = await start_execution( developer_id=developer_id, task_id=task.id,