# Tasks

## Overview <a href="#overview" id="overview"></a>

Edison client implements a RestClient (called `EdisonClient`) with the following functionalities:

* [Simple task running](https://edisonscientific.gitbook.io/edison-cookbook/edison-client#simple-task-running): `run_tasks_until_done(TaskRequest)` or `await arun_tasks_until_done(TaskRequest)`
* [Asynchronous tasks](https://edisonscientific.gitbook.io/edison-cookbook/edison-client#asynchronous-tasks): `get_task(task_id)` or `aget_task(task_id)` and `create_task(TaskRequest)` or `acreate_task(TaskRequest)`

To create a `EdisonClient`, you need to pass an Edison Scientific platform api key (see [Authentication](/edison-client/quickstart.md#authentication)):

## Task types <a href="#task-types" id="task-types"></a>

In the Edison platform, we define the deployed combination of an agent and an environment as a `job`.

To invoke a job, we need to submit a `task` (also called a `query`) to it. `EdisonClient` can be used to submit tasks/queries to available jobs in the Edison platform.

Using an `EdisonClient` instance, you can submit tasks to the platform by calling the `create_task` method, which receives a `TaskRequest` (or a dictionary with `kwargs`) and returns the task ID.

Aiming to make the submission of tasks as simple as possible, we have created a `JobNames` `enum` that contains the available task types.

Please note that Kosmos is not available via API.

| Alias                      | Task type         | Description                                                                                                                                              |
| -------------------------- | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `JobNames.LITERATURE`      | Literature search | Ask a question of scientific data sources, and receive a high-accuracy, cited response. Built with [PaperQA3](https://github.com/Future-House/paper-qa). |
| `JobNames.LITERATURE_HIGH` | Literature search | Ask a question of scientific data sources, and receive a high-accuracy, cited response. High reasoning mode enabled for SOTA performance.                |
| `JobNames.ANALYSIS`        | Data analysis     | Turn biological datasets into detailed analyses answering your research questions.                                                                       |
| `JobNames.PRECEDENT`       | Precedent search  | Formerly known as HasAnyone, query if anyone has ever done something in science.                                                                         |
| `JobNames.MOLECULES`       | Chemistry tasks   | A new iteration of ChemCrow, Phoenix uses cheminformatics tools to do chemistry. Good for planning synthesis and designing new molecules.                |

## Kosmos <a href="#submitting-tasks" id="submitting-tasks"></a>

Kosmos is a specialized agent for autonomous discovery. It can digest over 1,500 research papers and execute more than 42,000 lines of analysis code in a single run. It operates through multiple AI agents working in parallel, sharing information through structured "world models."

Every conclusion is fully auditable, so you can trace any finding back to its original code or scientific source. Kosmos also generates publication-ready figures and data visualizations alongside its written analysis.

Please note that Kosmos is not currently available via API.

## Submitting tasks <a href="#submitting-tasks" id="submitting-tasks"></a>

Using `JobNames`, the task submission looks like this:

```python
from edison_client import EdisonClient, JobNames

client = EdisonClient(
    api_key="<your_api_key>",
)

task_data = {
    "name": JobNames.PRECEDENT,
    "query": "Has anyone tested therapeutic exerkines in humans or NHPs?",
}

task_response = client.run_tasks_until_done(task_data)

print(task_response)
```

## Asynchronous tasks <a href="#asynchronous-tasks" id="asynchronous-tasks"></a>

Sometimes you may want to submit many jobs, while querying results at a later time. The platform API supports this, as shown below.

```python
import asyncio
from edison_client import EdisonClient, JobNames


async def main():
    client = EdisonClient(
        api_key="<your_api_key>",
    )

    task_data = {
        "name": JobNames.PRECEDENT,
        "query": "Has anyone tested therapeutic exerkines in humans or NHPs?",
    }

    task_response = await client.arun_tasks_until_done(task_data)
    return task_response


# For Python 3.7+
if __name__ == "__main__":
    task_response = asyncio.run(main())
```

## Batch task submission <a href="#batch-task-submission" id="batch-task-submission"></a>

In either the sync or the async code, collections of tasks can be given to the client to run them in a batch:

```python
import asyncio
from edison_client import EdisonClient, JobNames


async def main():
    client = EdisonClient(
        api_key="<your_api_key>",
    )

    task_data = [{
        "name": JobNames.PRECEDENT,
        "query": "Has anyone tested therapeutic exerkines in humans or NHPs?",
    },
    {
        "name": JobNames.LITERATURE,
        "query": "Are there any clinically validated therapeutic exerkines for humans?",
    }
    ]

    task_responses = await client.arun_tasks_until_done(task_data)
    return task_responses


# For Python 3.7+
if __name__ == "__main__":
    task_responses = asyncio.run(main())
```

## Task continuation <a href="#task-continuation" id="task-continuation"></a>

Once a task is submitted and the answer is returned, Edison platform allow you to ask follow-up questions to the previous task. It is also possible through the platform API. To accomplish that, we can use the `runtime_config` we discussed in the [Simple task running](https://edisonscientific.gitbook.io/edison-cookbook/edison-client#simple-task-running) section.

```python
from edison_client import EdisonClient, JobNames

client = EdisonClient(
    api_key="<your_api_key>",
)

task_data = {"name": JobNames.LITERATURE, "query": "How many species of birds are there?"}

task_id = client.create_task(task_data)

continued_task_data = {
    "name": JobNames.LITERATURE,
    "query": "From the previous answer, specifically, how many species of crows are there?",
    "runtime_config": {"continued_job_id": task_id},
}

task_result = client.run_tasks_until_done(continued_task_data)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.edisonscientific.com/edison-client/tasks.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
