From 8f99dd9f02226a19a1b0eb6fd8a895ea63a6890c Mon Sep 17 00:00:00 2001 From: Ahmad Haidar Date: Tue, 25 Feb 2025 10:35:03 +0300 Subject: [PATCH 1/2] feat(agents-api): enable self recursion --- .../executions/create_execution_transition.py | 2 +- agents-api/tests/test_execution_queries.py | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/agents-api/agents_api/queries/executions/create_execution_transition.py b/agents-api/agents_api/queries/executions/create_execution_transition.py index 263a042d6..07bc73b1a 100644 --- a/agents-api/agents_api/queries/executions/create_execution_transition.py +++ b/agents-api/agents_api/queries/executions/create_execution_transition.py @@ -69,7 +69,7 @@ def validate_transition_targets(data: CreateTransitionRequest) -> None: case "resume" | "step": assert data.next is not None, "Next target must be provided for resume/step" - if data.next.workflow == data.current.workflow: + if data.next.scope_id == data.current.scope_id: assert data.next.step > data.current.step, ( "Next step must be greater than current" ) diff --git a/agents-api/tests/test_execution_queries.py b/agents-api/tests/test_execution_queries.py index 01e2d9386..239f4a1c6 100644 --- a/agents-api/tests/test_execution_queries.py +++ b/agents-api/tests/test_execution_queries.py @@ -138,6 +138,49 @@ async def _(dsn=pg_dsn, developer_id=test_developer_id, execution=test_execution assert result.type == "init_branch" assert result.output == {"result": "test"} +@test("query: create execution transition - validate transition targets") +async def _(dsn=pg_dsn, developer_id=test_developer_id, execution=test_execution): + pool = await create_db_pool(dsn=dsn) + scope_id = uuid7() + await create_execution_transition( + developer_id=developer_id, + execution_id=execution.id, + data=CreateTransitionRequest( + type="init_branch", + output={"result": "test"}, + current={"workflow": "subworkflow", "step": 0, "scope_id": scope_id}, + next={"workflow": "subworkflow", "step": 0, "scope_id": scope_id}, + ), + connection_pool=pool, + ) + + await create_execution_transition( + developer_id=developer_id, + execution_id=execution.id, + data=CreateTransitionRequest( + type="step", + output={"result": "test"}, + current={"workflow": "subworkflow", "step": 0, "scope_id": scope_id}, + next={"workflow": "subworkflow", "step": 1, "scope_id": scope_id}, + ), + connection_pool=pool, + ) + + result = await create_execution_transition( + developer_id=developer_id, + execution_id=execution.id, + data=CreateTransitionRequest( + type="step", + output={"result": "test"}, + current={"workflow": "subworkflow", "step": 1, "scope_id": scope_id}, + next={"workflow": "subworkflow", "step": 0, "scope_id": uuid7()}, + ), + connection_pool=pool, + ) + + assert result is not None + assert result.type == "step" + assert result.output == {"result": "test"} @test("query: create execution transition with execution update") async def _( From 1c06908802a556df5b9716a6931fdfc0e01f3769 Mon Sep 17 00:00:00 2001 From: Ahmad-mtos Date: Tue, 25 Feb 2025 07:36:16 +0000 Subject: [PATCH 2/2] refactor: Lint agents-api (CI) --- agents-api/tests/test_execution_queries.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/agents-api/tests/test_execution_queries.py b/agents-api/tests/test_execution_queries.py index 239f4a1c6..fdf379775 100644 --- a/agents-api/tests/test_execution_queries.py +++ b/agents-api/tests/test_execution_queries.py @@ -138,6 +138,7 @@ async def _(dsn=pg_dsn, developer_id=test_developer_id, execution=test_execution assert result.type == "init_branch" assert result.output == {"result": "test"} + @test("query: create execution transition - validate transition targets") async def _(dsn=pg_dsn, developer_id=test_developer_id, execution=test_execution): pool = await create_db_pool(dsn=dsn) @@ -182,6 +183,7 @@ async def _(dsn=pg_dsn, developer_id=test_developer_id, execution=test_execution assert result.type == "step" assert result.output == {"result": "test"} + @test("query: create execution transition with execution update") async def _( dsn=pg_dsn,