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): updated openapi schema for tasks spec #350

Merged
merged 4 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
169 changes: 167 additions & 2 deletions 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-05-28T03:07:50+00:00
# timestamp: 2024-05-30T00:31:23+00:00

from __future__ import annotations

Expand Down Expand Up @@ -805,7 +805,7 @@ class ImageUrl(BaseModel):
"""
URL or base64 data url (e.g. `data:image/jpeg;base64,<the base64 encoded image>`)
"""
detail: Detail | None = "auto" # pytype: disable=annotation-type-mismatch
detail: Detail | None = "auto"
"""
image detail to feed into the model can be low | high | auto
"""
Expand All @@ -822,6 +822,68 @@ class ChatMLImageContentPart(BaseModel):
"""


class ExecutionTransition(BaseModel):
id: UUID
execution_id: UUID
created_at: AwareDatetime
outputs: Dict[str, Any]
"""
Outputs from an Execution Transition
"""
from_: Annotated[List[str | int], Field(alias="from")]
to: List[str | int]


class CELObject(BaseModel):
pass
model_config = ConfigDict(
extra="allow",
)


class YieldWorkflowStep(BaseModel):
workflow: str
arguments: CELObject


class ToolCallWorkflowStep(BaseModel):
tool_id: str
arguments: CELObject


class ErrorWorkflowStep(BaseModel):
error: str


class IfElseWorkflowStep(BaseModel):
if_: Annotated[str, Field(alias="if")]
then: YieldWorkflowStep
else_: Annotated[YieldWorkflowStep, Field(alias="else")]


class CreateExecution(BaseModel):
task_id: UUID
arguments: Dict[str, Any]
"""
JSON Schema of parameters
"""
status: Annotated[
str,
Field(pattern="^(queued|starting|running|waiting_for_input|success|failed)$"),
]
"""
Execution Status
"""


class ToolResponse(BaseModel):
id: UUID | None = None
"""
Optional Tool ID
"""
output: Dict[str, Any]


class Agent(BaseModel):
name: str
"""
Expand Down Expand Up @@ -1049,3 +1111,106 @@ class PatchToolRequest(BaseModel):
"""
Function definition and parameters
"""


class Execution(BaseModel):
id: UUID
task_id: UUID
created_at: UUID
arguments: Dict[str, Any]
"""
JSON Schema of parameters
"""
status: Annotated[
str,
Field(pattern="^(queued|starting|running|waiting_for_input|success|failed)$"),
]
"""
Execution Status
"""


class PromptWorkflowStep(BaseModel):
prompt: List[InputChatMLMessage]
"""
List of ChatML Messages in Jinja Templates
"""
settings: ChatSettings


class EvaluateWorkflowStep(BaseModel):
evaluate: CELObject


class CreateTask(BaseModel):
"""
Describes a Task
"""

name: str
"""
Name of the Task
"""
description: str | None = None
"""
Optional Description of the Task
"""
tools_available: Set[UUID] | None = None
"""
Available Tools for the Task
"""
input_schema: Dict[str, Any] | None = None
"""
JSON Schema of parameters
"""
main: (
PromptWorkflowStep
| EvaluateWorkflowStep
| YieldWorkflowStep
| ToolCallWorkflowStep
| ErrorWorkflowStep
| IfElseWorkflowStep
)
"""
Entrypoint Workflow for the Task
"""


class Task(BaseModel):
"""
Describes a Task
"""

name: str
"""
Name of the Task
"""
description: str | None = None
"""
Optional Description of the Task
"""
tools_available: Set[UUID] | None = None
"""
Available Tools for the Task
"""
input_schema: Dict[str, Any] | None = None
"""
JSON Schema of parameters
"""
main: List[
PromptWorkflowStep
| EvaluateWorkflowStep
| YieldWorkflowStep
| ToolCallWorkflowStep
| ErrorWorkflowStep
| IfElseWorkflowStep
]
"""
Entrypoint Workflow for the Task
"""
id: UUID
"""
ID of the Task
"""
created_at: AwareDatetime
agent_id: UUID
25 changes: 25 additions & 0 deletions agents-api/agents_api/models/execution/create_execution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from uuid import UUID

from ..utils import cozo_query
from typing import Literal, Dict, Any


@cozo_query
def create_execution_query(
task_id: UUID,
execution_id: UUID,
status: Literal[
"queued", "starting", "running", "waiting-for-input", "success", "failed"
] = "queued",
arguments: Dict[str, Any] = {},
) -> tuple[str, dict]:
query = """"""
return (
query,
{
"task_id": str(task_id),
"execution_id": str(execution_id),
"status": status,
"arguments": arguments,
},
)
12 changes: 12 additions & 0 deletions agents-api/agents_api/models/execution/get_execution_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from typing import Literal
from uuid import UUID

from ..utils import cozo_query


@cozo_query
def get_execution_status_query(task_id: UUID, developer_id: UUID) -> tuple[str, dict]:
task_id = str(task_id)
developer_id = str(developer_id)
query = """"""
return (query, {"task_id": task_id, "developer_id": developer_id})
19 changes: 19 additions & 0 deletions agents-api/agents_api/models/execution/get_execution_transition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from uuid import UUID

from ..utils import cozo_query


@cozo_query
def get_execution_transition_query(
execution_id: UUID, transition_id: UUID, developer_id: UUID
) -> tuple[str, dict]:

query = """"""
return (
query,
{
"execution_id": str(execution_id),
"transition_id": str(transition_id),
"developer_id": str(developer_id),
},
)
24 changes: 24 additions & 0 deletions agents-api/agents_api/models/task/create_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
This module contains the functionality for creating a new Task in the 'cozodb` database.
It constructs and executes a datalog query to insert Task data.
"""

from uuid import UUID
from typing import List, Optional, Dict, Any


from ..utils import cozo_query


@cozo_query
def create_task_query(
task_id: UUID,
developer_id: UUID,
agent_id: UUID,
name: str,
description: str,
input_schema: Dict[str, any],
tools_available: List[UUID] = [],
workflows: List[Dict[str, Any]] = [],
) -> tuple[str, dict]:
pass
9 changes: 9 additions & 0 deletions agents-api/agents_api/models/task/get_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from uuid import UUID

from ..utils import cozo_query


@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)})
24 changes: 24 additions & 0 deletions agents-api/agents_api/models/task/list_tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from typing import Any
from uuid import UUID

from ...common.utils import json
from ..utils import cozo_query


@cozo_query
def list_tasks_query(
developer_id: UUID,
limit: int = 100,
offset: int = 0,
# metadata_filter: dict[str, Any] = {},
) -> tuple[str, dict]:
"""Lists tasks from the 'cozodb' database based on the provided filters.

Parameters:
developer_id (UUID): The developer's ID to filter tasks by.
limit (int): The maximum number of tasks to return.
offset (int): The offset from which to start listing tasks.
Returns:
pd.DataFrame: A DataFrame containing the queried task data.
"""
pass
1 change: 1 addition & 0 deletions agents-api/agents_api/routers/tasks/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .routers import router
Loading
Loading