Skip to content

Commit

Permalink
fix: Apply fixes to tasks CRUD
Browse files Browse the repository at this point in the history
  • Loading branch information
whiterabbit1983 committed Jun 27, 2024
1 parent 3c286f9 commit 112d101
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 10 deletions.
5 changes: 4 additions & 1 deletion agents-api/agents_api/autogen/openapi_model.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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")]
Expand Down
9 changes: 7 additions & 2 deletions agents-api/agents_api/models/task/get_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions agents-api/agents_api/models/task/list_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,21 @@ 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,
tools_available,
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,
Expand Down
32 changes: 27 additions & 5 deletions agents-api/agents_api/routers/tasks/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()]
)

0 comments on commit 112d101

Please sign in to comment.