Skip to content

Listing tasks fails to filter on a list of states #6

@TheRobotCarlson

Description

@TheRobotCarlson

As it says in the title.

Expected behavior: Passing a list of states to the list-typed state var filters to only return tasks with those states.

Actual behavior:

warp_agent_sdk.BadRequestError: Error code: 400 - {'error': "Invalid request: invalid TaskState 'QUEUED,PENDING,CLAIMED,INPROGRESS'. Allowed: QUEUED, PENDING, CLAIMED, INPROGRESS, SUCCEEDED, FAILED"}

It seems like the list of items is improperly passed to the underlying request.

#!/usr/bin/env -S uv run --script
#
# /// script
# requires-python = ">=3.12"
# dependencies = ["warp-agent-sdk", "pydantic-settings"]
# ///

import datetime
from typing import Generator

from pydantic_settings import BaseSettings, SettingsConfigDict
from warp_agent_sdk import WarpAPI
from warp_agent_sdk.types.agent import TaskItem


class WarpSettings(BaseSettings):
    model_config = SettingsConfigDict(env_file=".env", env_prefix="WARP_")

    api_key: str


def get_settings() -> WarpSettings:
    return WarpSettings()


def get_client(settings: WarpSettings) -> WarpAPI:
    return WarpAPI(
        api_key=settings.api_key,
    )


def list_active_tasks(client: WarpAPI) -> Generator[TaskItem, None, None]:
    created_after = (
        datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(days=1)
    ).isoformat()
    filters = {
        "created_after": created_after,
        "state": ["QUEUED", "PENDING", "CLAIMED", "INPROGRESS"],
    }
    response = client.agent.tasks.list(**filters)
    while response.page_info.has_next_page:
        yield from response.tasks

        response = client.agent.tasks.list(
            cursor=response.page_info.next_cursor, **filters
        )

    yield from response.tasks


def main() -> None:
    settings = get_settings()
    client = get_client(settings)
    tasks = list_active_tasks(client)

    for task in tasks:
        print("-------------------------------- ", task.state)
        print(task.prompt)


if __name__ == "__main__":
    main()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions