From b4aa6b531c4d1187195a53eb233deee5595ad39f Mon Sep 17 00:00:00 2001 From: Ahmad Haidar Date: Thu, 30 Jan 2025 09:14:46 +0300 Subject: [PATCH] fix(agents-api): refactor ``test_task_execution_workflow.py`` with ``$`` prefix --- .../workflows/task_execution/__init__.py | 7 +--- .../tests/test_task_execution_workflow.py | 32 +++++++++---------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/agents-api/agents_api/workflows/task_execution/__init__.py b/agents-api/agents_api/workflows/task_execution/__init__.py index b53dc303d..e7b0533ad 100644 --- a/agents-api/agents_api/workflows/task_execution/__init__.py +++ b/agents-api/agents_api/workflows/task_execution/__init__.py @@ -55,7 +55,6 @@ StepOutcome, ) from ...common.retry_policies import DEFAULT_RETRY_POLICY - from ...common.utils.template import render_template from ...env import ( debug, temporal_heartbeat_timeout, @@ -152,11 +151,7 @@ async def eval_step_exprs(self, step_type: WorkflowStep): case SetStep(set=set): expr = set case LogStep(log=log): - output = await render_template( - input=log, - variables=await self.context.prepare_for_step(), - skip_vars=["developer_id"], - ) + expr = log case SwitchStep(switch=switch): output: int = -1 cases: list[str] = [c.case for c in switch] diff --git a/agents-api/tests/test_task_execution_workflow.py b/agents-api/tests/test_task_execution_workflow.py index 36287cb12..484db83a0 100644 --- a/agents-api/tests/test_task_execution_workflow.py +++ b/agents-api/tests/test_task_execution_workflow.py @@ -738,7 +738,7 @@ async def _(): ), ) result = await wf.eval_step_exprs( - ForeachStep(foreach=ForeachDo(in_="1 + 2", do=YieldStep(workflow="wf1"))) + ForeachStep(foreach=ForeachDo(in_="$ 1 + 2", do=YieldStep(workflow="wf1"))) ) assert result == StepOutcome(output=3) @@ -802,7 +802,7 @@ async def _(): ), ) result = await wf.eval_step_exprs( - IfElseWorkflowStep(if_="1 + 2", then=YieldStep(workflow="wf1")), + IfElseWorkflowStep(if_="$ 1 + 2", then=YieldStep(workflow="wf1")), ) assert result == StepOutcome(output=3) @@ -866,7 +866,7 @@ async def _(): ), ) result = await wf.eval_step_exprs( - ReturnStep(return_={"x": "1 + 2"}), + ReturnStep(return_={"x": "$ 1 + 2"}), ) assert result == StepOutcome(output={"x": 3}) @@ -930,7 +930,7 @@ async def _(): ), ) result = await wf.eval_step_exprs( - WaitForInputStep(wait_for_input=WaitForInputInfo(info={"x": "1 + 2"})), + WaitForInputStep(wait_for_input=WaitForInputInfo(info={"x": "$ 1 + 2"})), ) assert result == StepOutcome(output={"x": 3}) @@ -994,7 +994,7 @@ async def _(): ), ) result = await wf.eval_step_exprs( - EvaluateStep(evaluate={"x": "1 + 2"}), + EvaluateStep(evaluate={"x": "$ 1 + 2"}), ) assert result == StepOutcome(output={"x": 3}) @@ -1058,7 +1058,7 @@ async def _(): ), ) result = await wf.eval_step_exprs( - MapReduceStep(over="1 + 2", map=YieldStep(workflow="wf1")), + MapReduceStep(over="$ 1 + 2", map=YieldStep(workflow="wf1")), ) assert result == StepOutcome(output=3) @@ -1121,7 +1121,7 @@ async def _(): ), ), ) - result = await wf.eval_step_exprs(SetStep(set={"x": "1 + 2"})) + result = await wf.eval_step_exprs(SetStep(set={"x": "$ 1 + 2"})) assert result == StepOutcome(output={"x": 3}) @@ -1183,7 +1183,7 @@ async def _(): ), ), ) - result = await wf.eval_step_exprs(LogStep(log="{{_0['x']}}")) + result = await wf.eval_step_exprs(LogStep(log="$ _0['x']")) assert result == StepOutcome(output="5") @@ -1248,8 +1248,8 @@ async def _(): result = await wf.eval_step_exprs( SwitchStep( switch=[ - CaseThen(case="None", then=YieldStep(workflow="wf1")), - CaseThen(case="1 + 3", then=YieldStep(workflow="wf2")), + CaseThen(case="$ None", then=YieldStep(workflow="wf1")), + CaseThen(case="$ 1 + 3", then=YieldStep(workflow="wf2")), ] ), ) @@ -1260,7 +1260,7 @@ async def _(): @test("task execution workflow: evaluate tool call expressions") async def _(): wf = TaskExecutionWorkflow() - step = ToolCallStep(tool="tool1", arguments={"x": "1 + 2"}) + step = ToolCallStep(tool="tool1", arguments={"x": "$ 1 + 2"}) execution_input = ExecutionInput( developer_id=uuid.uuid4(), agent=Agent( @@ -1325,7 +1325,7 @@ async def _(): ), ) result = await wf.eval_step_exprs( - ToolCallStep(tool="tool1", arguments={"x": "1 + 2"}), + ToolCallStep(tool="tool1", arguments={"x": "$ 1 + 2"}), ) assert result == StepOutcome( @@ -1340,7 +1340,7 @@ async def _(): @test("task execution workflow: evaluate yield expressions") async def _(): wf = TaskExecutionWorkflow() - step = YieldStep(arguments={"x": "1 + 2"}, workflow="main") + step = YieldStep(arguments={"x": "$ 1 + 2"}, workflow="main") execution_input = ExecutionInput( developer_id=uuid.uuid4(), agent=Agent( @@ -1394,7 +1394,7 @@ async def _(): ), ), ) - result = await wf.eval_step_exprs(YieldStep(arguments={"x": "1 + 2"}, workflow="main")) + result = await wf.eval_step_exprs(YieldStep(arguments={"x": "$ 1 + 2"}, workflow="main")) assert result == StepOutcome( output={"x": 3}, transition_to=("step", TransitionTarget(step=0, workflow="main")) @@ -1404,7 +1404,7 @@ async def _(): @test("task execution workflow: evaluate yield expressions assertion") async def _(): wf = TaskExecutionWorkflow() - step = step = ToolCallStep(tool="tool1", arguments={"x": "1 + 2"}) + step = ToolCallStep(tool="tool1", arguments={"x": "$ 1 + 2"}) execution_input = ExecutionInput( developer_id=uuid.uuid4(), agent=Agent( @@ -1459,4 +1459,4 @@ async def _(): ), ) with raises(AssertionError): - await wf.eval_step_exprs(YieldStep(arguments={"x": "1 + 2"}, workflow="main")) + await wf.eval_step_exprs(YieldStep(arguments={"x": "$ 1 + 2"}, workflow="main"))