Metadata-Version: 2.4
Name: phthos-task
Version: 0.1.0
Summary: Python SDK for the Task AI public API (start_pipeline / get_pl_run, agents).
Author: PhthosAI
License: MIT License
        
        Copyright (c) 2026 PhthosAI
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/PhthosAI/task-ai-sdk
Project-URL: Repository, https://github.com/PhthosAI/task-ai-sdk
Keywords: phthos,task-ai,workflows,agents,sdk
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: httpx>=0.27
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"
Requires-Dist: ruff>=0.8; extra == "dev"
Dynamic: license-file

# Task AI Python SDK

Public HTTP client for Task AI workflows and agents (`/api/v1`).

Gumloop equivalents: `start_pipeline` → start a workbook run; `get_pl_run` → poll status, log, and outputs.

## Install

```bash
pip install phthos-task
```

Requires Python 3.11+.

## Auth

1. In Task AI, open **Settings → API keys** and create a key (`tai_…`).
2. Enable scope **`v1:workflow:run`** to start or kill workflow runs.
3. Pass the key and your Task AI origin (the same host as the web app).

```python
from phthos_task import TaskAI

client = TaskAI(
    api_key="tai_...",           # or TASK_AI_API_KEY
    base_url="https://tasks.example.com",  # or TASK_AI_BASE_URL
)
```

Local default `base_url` is `http://localhost:3012`.

Short runnable scripts: [`examples/`](examples/).

## Workflows (start_pipeline / get_pl_run)

```python
from phthos_task import TaskAI

with TaskAI(api_key="tai_...", base_url="https://tasks.example.com") as client:
    flows = client.list_workflows()
    wb = flows[0]
    tab = wb.tabs[0]

    started = client.start_pipeline(wb.id, tab_id=tab.id, inputs={"input": "hello"})
    run = client.wait_for_run(started.run_id)
    print(run.state, run.outputs)

    # one-shot
    done = client.run_pipeline(wb.id, tab_id=tab.id, input="hello")
```

Named Start fields can be passed as kwargs (`input="hello"`) or as `inputs={...}`. API runs use the tab’s **live checkpoint** (save/sync on the canvas first) — not unsaved editor state.

`PipelineRun.state` matches Gumloop: `RUNNING`, `DONE`, `FAILED`, `TERMINATED`.

```python
status = client.get_pl_run(started.run_id)
client.kill_run(started.run_id)
```

## Connected WORKFLOW tasks

Sync run of a child workflow task (already waits server-side):

```python
result = client.run_workflow("task_...", inputs={"input": "hello"})
print(result.outputs)
```

## Agents

```python
started = client.start_agent("task_...", "Summarize yesterday's leads")
done = client.wait_for_agent(started.task_id, started.interaction_id)
print(done.response)
```

Agent start/status need `v1:agent:start` and `v1:agent:read`.

## HTTP map

| SDK | Method | Path |
|-----|--------|------|
| `list_workflows` | GET | `/api/v1/workflows` |
| `start_pipeline` | POST | `/api/v1/workflows/:workbookId/run` |
| `get_pl_run` | GET | `/api/v1/runs/:runId` |
| `kill_run` | POST | `/api/v1/runs/:runId/kill` |
| `run_workflow` | POST | `/api/v1/tasks/:taskId/run_workflow` |
| `start_agent` | POST | `/api/v1/tasks/:taskId/start_agent` |
| `agent_status` | GET | `/api/v1/tasks/:taskId/agent_status/:interactionId` |

## Develop

```bash
cd python
python -m pip install -e ".[dev]"
python -m ruff check src tests
python -m pytest
python -m build
```

PyPI: from the `python/` directory, `python -m build` then upload (`twine` or the `publish-pypi` workflow).
