Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(agents-api): cozo queries for tasks #352

Merged
merged 7 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Empty file.
28 changes: 25 additions & 3 deletions agents-api/agents_api/models/task/get_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,28 @@


@cozo_query
def get_task_query(developer_id: UUID, task_id: UUID) -> tuple[str, dict]:
query = """"""
return (query, {"developer_id": str(developer_id), "task_id": str(task_id)})
def get_task_query(agent_id: UUID, task_id: UUID) -> tuple[str, dict]:
query = """
?[
name,
description,
input_schema,
tools_available,
workflows,
created_at,
updated_at,
] := *tasks {
agent_id: to_uuid($agent_id),
task_id: to_uuid($task_id),
updated_at_ms,
name,
description,
input_schema,
tools_available,
workflows,
created_at,
@ 'NOW'
}, updated_at = to_int(updated_at_ms) / 1000
"""

return (query, {"agent_id": str(agent_id), "task_id": str(task_id)})
32 changes: 30 additions & 2 deletions agents-api/agents_api/models/task/list_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@cozo_query
def list_tasks_query(
developer_id: UUID,
agent_id: UUID,
limit: int = 100,
offset: int = 0,
# metadata_filter: dict[str, Any] = {},
Expand All @@ -21,4 +21,32 @@ def list_tasks_query(
Returns:
creatorrr marked this conversation as resolved.
Show resolved Hide resolved
pd.DataFrame: A DataFrame containing the queried task data.
"""
pass

query = """
?[
task_id,
name,
description,
input_schema,
tools_available,
workflows,
created_at,
updated_at,
] := *tasks {
agent_id: to_uuid($agent_id),
task_id,
updated_at_ms,
name,
description,
input_schema,
tools_available,
workflows,
created_at,
@ 'NOW'
}, updated_at = to_int(updated_at_ms) / 1000

:limit $limit
:offset $offset
"""

return (query, {"agent_id": str(agent_id), "limit": limit, "offset": offset})
10 changes: 10 additions & 0 deletions agents-api/agents_api/routers/tasks/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ async def create_task(
x_developer_id: Annotated[UUID4, Depends(get_developer_id)],
) -> ResourceCreatedResponse:
task_id = uuid4()

# TODO: Do thorough validation of the task spec

resp: pd.DataFrame = create_task_query(
task_id=task_id,
developer_id=x_developer_id,
Expand All @@ -73,6 +76,9 @@ async def create_task_execution(
request: CreateExecution,
x_developer_id: Annotated[UUID4, Depends(get_developer_id)],
) -> ResourceCreatedResponse:
# TODO: Do thorough validation of the input against task input schema
# DO NOT let the user specify the status

resp = create_execution_query()
return ResourceCreatedResponse(
id=resp["execution_id"][0], created_at=resp["created_at"][0]
Expand All @@ -98,3 +104,7 @@ async def get_execution_transition(
resp = get_execution_transition_query(execution_id, transition_id, x_developer_id)

pass

# @router.get("/executions/{execution_id}") # -> get the execution object
# @router.put("/executions/{execution_id}/transitions/{transition_id}") # -> update a waiting transition
# @router.get("/executions/{execution_id}/transitions") # -> get all transitions for an execution
Loading