diff --git a/agents-api/agents_api/autogen/openapi_model.py b/agents-api/agents_api/autogen/openapi_model.py index 5a39972e3..f0bb5c645 100644 --- a/agents-api/agents_api/autogen/openapi_model.py +++ b/agents-api/agents_api/autogen/openapi_model.py @@ -1,6 +1,6 @@ # generated by datamodel-codegen: # filename: openapi.yaml -# timestamp: 2024-06-21T21:41:04+00:00 +# timestamp: 2024-06-27T12:10:13+00:00 from __future__ import annotations @@ -880,6 +880,9 @@ class ErrorWorkflowStep(BaseModel): class IfElseWorkflowStep(BaseModel): + model_config = ConfigDict( + populate_by_name=True, + ) if_: Annotated[str, Field(alias="if")] then: YieldWorkflowStep else_: Annotated[YieldWorkflowStep, Field(alias="else")] diff --git a/agents-api/agents_api/models/task/get_task.py b/agents-api/agents_api/models/task/get_task.py index c46b98434..b6f1a7eaa 100644 --- a/agents-api/agents_api/models/task/get_task.py +++ b/agents-api/agents_api/models/task/get_task.py @@ -12,17 +12,22 @@ def get_task_query( ) -> tuple[str, dict]: # TODO: Check for agent in developer ID; Assert whether dev can access agent and by relation the task query = """ + input[agent_id] <- [[to_uuid($agent_id)]] + ?[ id, name, + agent_id, description, input_schema, tools_available, workflows, created_at, updated_at, - ] := *tasks { - agent_id: to_uuid($agent_id), + ] := + input[agent_id], + *tasks { + agent_id, task_id: to_uuid($task_id), updated_at_ms, name, diff --git a/agents-api/agents_api/models/task/list_tasks.py b/agents-api/agents_api/models/task/list_tasks.py index 730772a17..2a11e1206 100644 --- a/agents-api/agents_api/models/task/list_tasks.py +++ b/agents-api/agents_api/models/task/list_tasks.py @@ -25,8 +25,11 @@ def list_tasks_query( """ # TODO: Accepts developer ID. Checks if the developer can get this agent, by relation can get the tasks. Assert that the agent exists under the developer. query = """ + input[agent_id] <- [[to_uuid($agent_id)]] + ?[ id, + agent_id, name, description, input_schema, @@ -34,8 +37,9 @@ def list_tasks_query( workflows, created_at, updated_at, - ] := *tasks { - agent_id: to_uuid($agent_id), + ] := input[agent_id], + *tasks { + agent_id, task_id: id, updated_at_ms, name, diff --git a/agents-api/agents_api/routers/tasks/routers.py b/agents-api/agents_api/routers/tasks/routers.py index 306a2ef91..013d64026 100644 --- a/agents-api/agents_api/routers/tasks/routers.py +++ b/agents-api/agents_api/routers/tasks/routers.py @@ -50,12 +50,26 @@ class ExecutionTransitionList(BaseModel): async def list_tasks( agent_id: UUID4, x_developer_id: Annotated[UUID4, Depends(get_developer_id)], + limit: int = 100, + offset: int = 0, ) -> TaskList: - query_results = list_tasks_query(agent_id, x_developer_id) - return TaskList( - items=[Task(**row.to_dict()) for _, row in query_results.iterrows()] + query_results = list_tasks_query( + agent_id=agent_id, developer_id=x_developer_id, limit=limit, offset=offset ) + items = [] + for _, row in query_results.iterrows(): + row_dict = row.to_dict() + + for workflow in row_dict["workflows"]: + if workflow["name"] == "main": + row_dict["main"] = workflow["steps"] + break + + items.append(Task(**row_dict)) + + return TaskList(items=items) + @router.post("/agents/{agent_id}/tasks", status_code=HTTP_201_CREATED, tags=["tasks"]) async def create_task( @@ -96,9 +110,16 @@ async def get_task( try: resp = [ row.to_dict() - for _, row in get_task_query(agent_id, task_id, x_developer_id).iterrows() + for _, row in get_task_query( + agent_id=agent_id, task_id=task_id, developer_id=x_developer_id + ).iterrows() ][0] + for workflow in resp["workflows"]: + if workflow["name"] == "main": + resp["main"] = workflow["steps"] + break + return Task(**resp) except (IndexError, KeyError): raise HTTPException( @@ -222,7 +243,8 @@ async def update_execution_transition( @router.get("/executions/{execution_id}/transitions") async def list_execution_transitions(execution_id: UUID4) -> ExecutionTransitionList: - res = list_execution_transition_query(execution_id) + # TODO: implement/replace list_execution_transition_query + res = pd.DataFrame() # list_execution_transition_query(execution_id) return ExecutionTransitionList( items=[ExecutionTransition(**row.to_dict()) for _, row in res.iterrows()] )