Skip to content

Commit

Permalink
feat: Add tests for tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
whiterabbit1983 committed Jun 21, 2024
1 parent 00a7f02 commit c72546e
Show file tree
Hide file tree
Showing 4 changed files with 319 additions and 1 deletion.
12 changes: 12 additions & 0 deletions agents-api/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,15 @@ def session(user=user, agent=agent, client=client):
agent_id=agent.id,
situation="test situation",
)


@fixture
def task(agent=agent, client=client):
return client.tasks.create(
agent_id=agent.id,
name="task1",
description="task 1",
tools_available=["tool1"],
input_schema={},
main=[],
)
157 changes: 157 additions & 0 deletions agents-api/tests/test_tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import uuid
from typing import List
from ward import test
from tests.fixtures import client, async_client, task, agent
from julep.api.types import Task, Execution


@test("create task")
def _(client=client, agent=agent):
task = client.tasks.create(
agent_id=agent.id,
name="task1",
description="task 1",
tools_available=["tool1"],
input_schema={},
main=[],
)

assert isinstance(task, Task)
assert task.created_at
assert bool(uuid.UUID(str(task.id), version=4))

assert task.agent_id == agent.id
assert task.name == "task1"
assert task.description == "task 1"
assert task.tools_available == ["tool1"]
assert task.input_schema == {}
assert task.main == []


@test("get task")
def _(client=client, agent=agent, task=task):
task = client.tasks.get(
agent_id=agent.id,
task_id=task.id,
)

assert isinstance(task, Task)
assert task.created_at
assert bool(uuid.UUID(str(task.id), version=4))

assert task.agent_id == agent.id
assert task.name == "task1"
assert task.description == "task 1"
assert task.tools_available == ["tool1"]
assert task.input_schema == {}
assert task.main == []


@test("list task")
def _(client=client, agent=agent):
tasks = client.tasks.list(
agent_id=agent.id,
)

assert isinstance(tasks, List[Task])
assert len(tasks) > 0

task = tasks[0]

assert task.created_at
assert bool(uuid.UUID(str(task.id), version=4))

assert task.agent_id == agent.id
assert task.name == "task1"
assert task.description == "task 1"
assert task.tools_available == ["tool1"]
assert task.input_schema == {}
assert task.main == []


@test("start task execution")
def _(client=client, agent=agent, task=task):
execution = client.tasks.start_task_execution(
agent_id=agent.id,
task_id=task.id,
arguments={},
status="enqueued",
)

assert isinstance(execution, Execution)


@test("create task")
async def _(client=async_client, agent=agent):
task = await client.tasks.create(
agent_id=agent.id,
name="task1",
description="task 1",
tools_available=["tool1"],
input_schema={},
main=[],
)

assert isinstance(task, Task)
assert task.created_at
assert bool(uuid.UUID(str(task.id), version=4))

assert task.agent_id == agent.id
assert task.name == "task1"
assert task.description == "task 1"
assert task.tools_available == ["tool1"]
assert task.input_schema == {}
assert task.main == []


@test("get task")
async def _(client=async_client, agent=agent, task=task):
task = await client.tasks.get(
agent_id=agent.id,
task_id=task.id,
)

assert isinstance(task, Task)
assert task.created_at
assert bool(uuid.UUID(str(task.id), version=4))

assert task.agent_id == agent.id
assert task.name == "task1"
assert task.description == "task 1"
assert task.tools_available == ["tool1"]
assert task.input_schema == {}
assert task.main == []


@test("list task")
async def _(client=async_client, agent=agent):
tasks = await client.tasks.list(
agent_id=agent.id,
)

assert isinstance(tasks, List[Task])
assert len(tasks) > 0

task = tasks[0]

assert task.created_at
assert bool(uuid.UUID(str(task.id), version=4))

assert task.agent_id == agent.id
assert task.name == "task1"
assert task.description == "task 1"
assert task.tools_available == ["tool1"]
assert task.input_schema == {}
assert task.main == []


@test("start task execution")
async def _(client=async_client, agent=agent, task=task):
execution = await client.tasks.start_task_execution(
agent_id=agent.id,
task_id=task.id,
arguments={},
status="enqueued",
)

assert isinstance(execution, Execution)
29 changes: 28 additions & 1 deletion sdks/python/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from julep import AsyncClient, Client

from julep.api.types import Agent, User, Session
from julep.api.types import Agent, User, Session, Task

env = Env()

Expand Down Expand Up @@ -103,6 +103,15 @@
"metadata": {"type": "test"},
}

mock_task = {
"name": "task 1",
"description": "task 1 description",
"tools_available": ["tool 1"],
"input_schema": {"key", "val"},
"main": [],
"agent_id": "e4509e29-c412-4304-bbb9-0a27c0765cf2",
}


def cleanup(client: Client):
for session in client.sessions.list(metadata_filter={"type": "test"}):
Expand Down Expand Up @@ -157,6 +166,24 @@ def test_agent(client=client) -> Agent:
client.agents.delete(agent.id)


@fixture
def test_task(client=client) -> Task:
task = client.tasks.create(
**mock_task,
)

yield task


@fixture
async def test_task_async(client=client) -> Task:
task = await client.tasks.create(
**mock_task,
)

yield task


@fixture
def test_gpt_4o_agent(client=client) -> Agent:
agent = client.agents.create(
Expand Down
122 changes: 122 additions & 0 deletions sdks/python/tests/test_tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
from ward import test
from uuid import uuid4
from typing import List

from julep.api.types import (
Task,
Execution,
)

from .fixtures import (
client,
async_client,
test_task,
test_task_async,
mock_task,
)


@test("tasks: tasks.create")
def _(task=test_task):
assert isinstance(task, Task)
assert hasattr(task, "created_at")

assert task.name == mock_task["name"]
assert task.description == mock_task["description"]
assert task.tools_available == mock_task["tools_available"]
assert task.input_schema == mock_task["input_schema"]
assert task.main == mock_task["main"]
assert task.agent_id == mock_task["agent_id"]


@test("tasks: tasks.get")
def _(client=client, task=test_task):
response = client.tasks.get(task.id)
assert isinstance(response, Task)

assert task.name == response.name
assert task.description == response.description
assert task.tools_available == response.tools_available
assert task.input_schema == response.input_schema
assert task.main == response.main
assert task.agent_id == response.agent_id


@test("tasks: tasks.list")
def _(client=client, _=test_task):
response = client.tasks.list()
assert len(response) > 0
assert isinstance(response[0], Task)


@test("tasks: tasks.start_task_execution")
def _(client=client, _=test_task):
response = client.tasks.start_task_execution(
agent_id=uuid4(),
task_id=uuid4(),
arguments={},
status="enqueued",
)
assert isinstance(response[0], Execution)


@test("tasks: tasks.get_task_execution")
def _(client=client, _=test_task):
response = client.tasks.get_task_execution(
task_id=uuid4(),
execution_id=uuid4(),
)
assert isinstance(response[0], List[Execution])


@test("async tasks: tasks.create")
async def _(task=test_task_async):
assert isinstance(task, Task)
assert hasattr(task, "created_at")

assert task.name == mock_task["name"]
assert task.description == mock_task["description"]
assert task.tools_available == mock_task["tools_available"]
assert task.input_schema == mock_task["input_schema"]
assert task.main == mock_task["main"]
assert task.agent_id == mock_task["agent_id"]


@test("async tasks: tasks.get")
async def _(client=async_client, task=test_task_async):
response = await client.tasks.get(task.id)
assert isinstance(response, Task)

assert task.name == response.name
assert task.description == response.description
assert task.tools_available == response.tools_available
assert task.input_schema == response.input_schema
assert task.main == response.main
assert task.agent_id == response.agent_id


@test("async tasks: tasks.list")
async def _(client=async_client, _=test_task_async):
response = await client.tasks.list()
assert len(response) > 0
assert isinstance(response[0], Task)


@test("async tasks: tasks.start_task_execution")
async def _(client=async_client, _=test_task_async):
response = await client.tasks.start_task_execution(
agent_id=uuid4(),
task_id=uuid4(),
arguments={},
status="enqueued",
)
assert isinstance(response[0], Execution)


@test("async tasks: tasks.get_task_execution")
async def _(client=async_client, _=test_task_async):
response = await client.tasks.get_task_execution(
task_id=uuid4(),
execution_id=uuid4(),
)
assert isinstance(response[0], List[Execution])

0 comments on commit c72546e

Please sign in to comment.