> ## Documentation Index
> Fetch the complete documentation index at: https://docs.harmonic.fun/llms.txt
> Use this file to discover all available pages before exploring further.

# SDK reference

> The aristotlelib Python package: projects, tasks, questions, events, and errors.

`aristotlelib` is the official Python client for the Aristotle API. Every method that issues a network request is `async`.

For a private deployment, set `ARISTOTLE_WEB_URL` to its HTTPS web origin before logging in or starting a Python process. See [the installation guide](https://docs.harmonic.fun/installation.md#use-the-cli) for selecting this deployment.

The library reports what it does, such as a task's snapshot or how a wait ended, through the `aristotle` logger, and configures no logging of its own. To see those messages, configure logging in your program, for example with `logging.basicConfig(level=logging.INFO)`.

```python wrap theme={null}
import aristotlelib
from aristotlelib import (
    Project,
    ProjectStatus,
    AgentQuestionsSetting,
    AgentTask,
    TaskStatus,
    Event,
    EventType,
    EventStatus,
    Question,
    AristotleAPIError,
)
```

## Authentication

The library looks for a key in three places, in this order: one set programmatically, the `ARISTOTLE_API_KEY` environment variable, and the credentials `aristotle login` stored. So on a machine you have logged in on there is nothing to do, and a deployment can still hand the process its own key.

```python wrap theme={null}
# Option 1: environment variable
# export ARISTOTLE_API_KEY='arstl_...'

# Option 2: set programmatically, which overrides the other two
aristotlelib.set_api_key("arstl_...")
```

`aristotle login` prints a code that you approve in the browser, on any device, so it works over SSH and in containers too. The code expires after 10 minutes. Logging in again in the browser on the same machine retires the key the last browser login stored there, when the same account approves it. To store a key you already have instead, pipe it in: `printf '%s\n' "$KEY" | aristotle login`. A key you pipe in is never retired this way.

## `Project`

### `Project.create(prompt, tar_file_path=None, public_file_path=None, agent_questions_setting=AgentQuestionsSetting.TIMEOUT_15_MIN, name=None)`

Submits a new project. `tar_file_path` is a `.tar.gz` of the code to verify, at most 100 MB. Leave it out only when the prompt contains the source itself. A run with no source in a supported language ends at once with a notice. `public_file_path` sets the filename recorded by Aristotle. `name` names the project, as `aristotle list` and the web app show it. A name over 200 characters raises `AristotleAPIError`. By default Aristotle may ask clarifying questions; see [`AgentQuestionsSetting`](#agentquestionssetting).

```python wrap theme={null}
project = await Project.create(
    prompt="Prove that every function in ring_buffer.c is memory safe",
    tar_file_path="ring-buffer.tar.gz",
)
```

### `Project.create_from_directory(prompt, project_dir, agent_questions_setting=AgentQuestionsSetting.TIMEOUT_15_MIN, name=None, *, include_ignored=False)`

Submits a new project from a local directory, as one archive of at most 100 MB. It leaves out `.git`, build output and editor files, files an ignore rule such as a `.gitignore` entry matches, files named like credentials, result archives an earlier run saved, and files whose names aren't UTF-8. Pass `include_ignored=True` to upload the files the ignore rules match too, such as sources a build generates.

```python wrap theme={null}
project = await Project.create_from_directory(
    prompt="Hunt for real bugs with provable resolution",
    project_dir="./my-project",
)
```

### `Project.from_id(object_id)`

Loads a project by ID. Raises `AristotleNotFoundError` when no project you can see has that ID.

### `Project.list_projects(pagination_key=None, limit=30, status=None, latest_run_status=None, archived=False)`

Returns `(projects, next_pagination_key)`, newest first. `limit` ranges from 1 to 100. `status` accepts a single `ProjectStatus` or a list, and filters returned projects to those statuses. `latest_run_status` takes a list of `TaskStatus` values, and keeps the projects whose latest task has one of them. `archived=True` lists only the archived projects, which the list otherwise leaves out.

```python wrap theme={null}
projects, next_key = await Project.list_projects(limit=10)
running, _ = await Project.list_projects(status=ProjectStatus.RUNNING)
```

### `project.ask(prompt, files=None, agent_questions_setting=AgentQuestionsSetting.TIMEOUT_15_MIN)`

Continues a project. If a task is running, the prompt changes its direction, and the task keeps its own questions setting. If the project is idle, the prompt starts a new task, which uses credits. To understand a result, read the task's `output_summary` first. `files` can be used only on an idle project.

### `project.get_tasks(pagination_key=None, limit=10, newest_first=True)`

Returns `(tasks, next_pagination_key)`.

### `project.get_files(destination=None)`

Refreshes the project, then downloads the result tarball if available or the original input otherwise. If `destination` is omitted, the file is downloaded in the current directory; a directory, or a path ending in a separator, gets it under its default name. Raises `ProjectHasNoFilesError` when the project has neither.

```python wrap theme={null}
path = await project.get_files(destination="output.tar.gz")
```

### `project.refresh()`

Refreshes the project's state in place.

### `project.archive()`

Archives an idle project and updates it in place. `Project.list_projects` then leaves it out unless you pass `archived=True`, and its shared link still works. Raises `AristotleAPIError` with status 409 while a run of the project is in progress.

### `project.unarchive()`

Brings an archived project back to `Project.list_projects` and updates it in place. A prompt sent to an archived project brings it back too.

### Fields

`project_id`, `description` (the project's name), `status` ([`ProjectStatus`](#projectstatus)), `latest_run_status` (the [`TaskStatus`](#taskstatus) of its latest task, or `None` before the first), `created_at`, `last_updated`, `has_input`, `has_files`, `archived_at` (when the project was archived, or `None`).

## `AgentTask`

### `AgentTask.from_id(object_id)`

Loads a task by ID.

### `task.wait_for_completion(num_events=3, *, interactive=False, stop_on_questions=False)`

Waits until the task reaches a terminal state. By default it writes nothing to stdout and reads nothing from stdin: it logs the questions waiting for an answer, and how the task ended, to the `aristotle` logger. `interactive=True` shows live progress on stdout, as the CLI does: the most recent events and the project's property counts. Pass `num_events=0` to hide recent events. At an interactive terminal it also asks you Aristotle's questions as they arrive; elsewhere it logs them.

With `stop_on_questions=True` it returns early with the open questions, as a list of [`Question`](#question): as soon as one is waiting by default or away from a terminal, and with `interactive=True` at a terminal once it has asked them, if some are still open. A read-only task never returns early. A wait that doesn't return early returns an empty list. A wait also ends if the connection to Aristotle keeps failing, while the task goes on, so inspect `task.status` after it returns.

You don't need to keep a process waiting to find out when a task ends. Aristotle emails you when a task completes or fails, with a link to the project. Turn these emails off under **Email notifications** in [Settings](https://aristotle.harmonic.fun/settings).

### `task.get_events(pagination_key=None, limit=50, newest_first=True)`

Returns `(events, next_pagination_key)`. Each event represents one meaningful step Aristotle took during the task.

### `task.show(num_events=0, pagination_key=None)`

Logs a snapshot of the task, and its `num_events` most recent events, to the `aristotle` logger. Returns the next pagination key if more remain.

### `task.cancel()`

Cancels the task if queued or in progress, and updates it in place. Canceling an already canceled task succeeds; canceling a task that ended with another status raises `AristotleAPIError`.

### `task.refresh()`

Refreshes the task's state in place.

### Fields

`agent_task_id`, `project_id`, `status` ([`TaskStatus`](#taskstatus)), `created_at`, `last_updated_at`, `percent_complete` (deprecated, always `None`), `description`, `file_name`, `output_summary`, `read_only` (`True` on someone else's shared project, where only the owner can answer questions).

## `Event`

An `Event` represents one step Aristotle took during a task: a build, a command, a file edit, a search, a read, a question, a summary, a message, or a change to a property or a definition. Build, command, file edit, search, and read events record only that the step happened: their `content` is empty and their `file_path` is `None`. Events are shown by `task.wait_for_completion(interactive=True)` and `task.show`, and listed by `task.get_events`.

### `event.answer(answer)`

Answers the question that an `AGENT_QUESTION` event announced, or, on an older server, the event itself while its status is `SENT`, the form questions took before [`Question`](#question). Aristotle now asks each question as a `Question`; answer it with `question.answer()`.

### Fields

`event_id`, `agent_task_id`, `event_type` ([`EventType`](#eventtype)), `created_at`, `content`, `file_path`, `explanation`, `suggestions`, `status` ([`EventStatus`](#eventstatus)), `duration_seconds`, `declaration_id` (the property or definition of a property or definition event, or `None`), `declaration_status` (the status that a `PROPERTY_STATUS_CHANGED` event moved its property to, or `None`).

## `Question`

A question Aristotle asked during a task. Aristotle keeps working after it asks; when it needs the answer to go on, it waits up to 15 minutes, then carries on without it. A question takes an answer until the task ends.

### `Question.list_for_task(agent_task_id)`

Returns every question asked during the task, in any state, oldest first.

### `question.answer(answer)`

Sends the answer and updates the question from Aristotle's reply. Raises `QuestionClosed` when the question no longer takes an answer.

### Fields

`question_id`, `project_id`, `agent_task_id`, `content`, `suggestions`, `response` (the answer, or `None`), `created_at`, `updated_at`. `answered` is `True` once it has an answer, and `ignored` when it closed without one; `pending` is `True` otherwise, including after the task ends, when the question no longer takes an answer.

## `ProjectStatus`

```python wrap theme={null}
class ProjectStatus(IntEnum):
    UNKNOWN = 0
    RUNNING = 1
    IDLE = 2
```

`RUNNING` indicates at least one active task. `IDLE` indicates no task is currently running. `UNKNOWN` indicates a server response this SDK version does not recognize; upgrade `aristotlelib`.

## `AgentQuestionsSetting`

```python wrap theme={null}
class AgentQuestionsSetting(IntEnum):
    DISABLED = 1
    TIMEOUT_15_MIN = 2
```

`TIMEOUT_15_MIN`, the default, lets Aristotle ask clarifying questions while a task runs, whether or not you wait for it, and wait up to 15 minutes for each answer. Use `DISABLED` for a batch run nobody will answer: Aristotle then verifies what doesn't need a decision only you can make, leaves the rest unverified, and names the open question in its summary, as it does when a question gets no answer.

## `TaskStatus`

```python wrap theme={null}
class TaskStatus(Enum):
    UNKNOWN = "UNKNOWN"
    QUEUED = "QUEUED"
    IN_PROGRESS = "IN_PROGRESS"
    COMPLETE = "COMPLETE"
    COMPLETE_WITH_ERRORS = "COMPLETE_WITH_ERRORS"
    OUT_OF_BUDGET = "OUT_OF_BUDGET"
    FAILED = "FAILED"
    CANCELED = "CANCELED"
```

`COMPLETE_WITH_ERRORS` signals partial progress that did not fully satisfy the prompt. `OUT_OF_BUDGET` signals compute exhaustion; partial results are typically available. Both are good candidates for a follow-up with `project.ask()`, which starts a new task that uses credits.

## `EventType`

```python wrap theme={null}
class EventType(IntEnum):
    UNKNOWN = 0
    MESSAGE = 1
    BUILDING = 2
    THINKING = 3
    EDITING_FILE = 4
    SEARCHING_LOCAL = 5
    RUNNING_COMMAND = 6
    PROVING = 7
    READING_FILES = 8
    REVIEWING = 9
    FINISHED = 10
    ERROR = 11
    READING_LEAN = 12
    SEARCHING_EXTERNAL = 13
    RUNNING_LEAN = 14
    QUESTION = 15
    SUMMARY = 16
    AGENT_QUESTION = 17
    AGENT_FOLLOW_UP = 18
    PROPERTY_ADDED = 19
    PROPERTY_MODIFIED = 20
    PROPERTY_STATUS_CHANGED = 21
    PROPERTY_REMOVED = 22
    DEFINITION_ADDED = 23
    DEFINITION_MODIFIED = 24
    DEFINITION_REMOVED = 25
```

`QUESTION` records a user question about a task. `SUMMARY` records a task summary. `AGENT_QUESTION` records a clarifying question from Aristotle. `AGENT_FOLLOW_UP` records a message from Aristotle after the summary, such as how to pick up a task that ran out of time. `PROPERTY_ADDED` through `DEFINITION_REMOVED` record a change that Aristotle made to a property or a definition: their `content` names it and says what changed, and `declaration_id` says which one it is. Versions of `aristotlelib` before 3.4.0 report them as `UNKNOWN`.

## `EventStatus`

```python wrap theme={null}
class EventStatus(IntEnum):
    UNKNOWN = 0
    COMPLETE = 1
    SENT = 2
```

`SENT` marks an event still on its way: a `MESSAGE` that `project.ask()` sent to a running task, until the task picks it up, or an `AGENT_QUESTION` event from before [`Question`](#question), until it's answered. Every other event is `COMPLETE`, a question's event included: the question's own state is on the `Question`.

## Errors

Network and API failures raise `AristotleAPIError`. When the failure originates from an HTTP response, the exception's `status_code` attribute is set. Its subclasses say more:

* `AristotleNotFoundError`: no project or task you can see has the ID.
* `AristotleProjectLimitError`: too many of your runs are in progress or queued.
* `AristotleNotProcessedError`: the request failed before Aristotle acted on it, so it is safe to send again.
* `AristotleOutcomeUnknownError`: the request failed after Aristotle may have acted on it, so check before sending it again.
* `ProjectHasNoFilesError`: `project.get_files()` found nothing to download.

`question.answer()` raises `QuestionClosed`, which you import from `aristotlelib`, when the question no longer takes an answer. It is a `ValueError`, not an `AristotleAPIError`.

```python wrap theme={null}
from aristotlelib import AristotleAPIError

try:
    project = await Project.create(prompt="My prompt", tar_file_path="my-project.tar.gz")
except AristotleAPIError as e:
    print(f"API error (status {e.status_code}): {e}")
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.