# States

## Create Task State

**post** `/states`

Create Task State

### Body Parameters

- `agent_id: string`

- `state: map[unknown]`

- `task_id: string`

### Returns

- `State object { id, agent_id, created_at, 3 more }`

  Represents a state in the agent system. A state is associated uniquely with a task and an agent.

  This entity is used to store states in MongoDB, with each state
  associated with a specific task and agent. The combination of task_id and agent_id is globally unique.

  The state is a dictionary of arbitrary data.

  - `id: string`

    The task state's unique id

  - `agent_id: string`

  - `created_at: string`

    The timestamp when the state was created

  - `state: map[unknown]`

  - `task_id: string`

  - `updated_at: optional string`

    The timestamp when the state was last updated

### Example

```http
curl http://localhost:5003/states \
    -H 'Content-Type: application/json' \
    -H "Authorization: Bearer $AGENTEX_SDK_API_KEY" \
    -d '{
          "agent_id": "agent_id",
          "state": {
            "foo": "bar"
          },
          "task_id": "task_id"
        }'
```

#### Response

```json
{
  "id": "id",
  "agent_id": "agent_id",
  "created_at": "2019-12-27T18:11:19.117Z",
  "state": {
    "foo": "bar"
  },
  "task_id": "task_id",
  "updated_at": "2019-12-27T18:11:19.117Z"
}
```

## List States

**get** `/states`

List all states, optionally filtered by query parameters.

### Query Parameters

- `agent_id: optional string`

  Agent ID

- `limit: optional number`

  Limit

- `order_by: optional string`

  Field to order by

- `order_direction: optional string`

  Order direction (asc or desc)

- `page_number: optional number`

  Page number

- `task_id: optional string`

  Task ID

### Returns

- `id: string`

  The task state's unique id

- `agent_id: string`

- `created_at: string`

  The timestamp when the state was created

- `state: map[unknown]`

- `task_id: string`

- `updated_at: optional string`

  The timestamp when the state was last updated

### Example

```http
curl http://localhost:5003/states \
    -H "Authorization: Bearer $AGENTEX_SDK_API_KEY"
```

#### Response

```json
[
  {
    "id": "id",
    "agent_id": "agent_id",
    "created_at": "2019-12-27T18:11:19.117Z",
    "state": {
      "foo": "bar"
    },
    "task_id": "task_id",
    "updated_at": "2019-12-27T18:11:19.117Z"
  }
]
```

## Get State by State ID

**get** `/states/{state_id}`

Get a state by its unique state ID.

### Path Parameters

- `state_id: string`

### Returns

- `State object { id, agent_id, created_at, 3 more }`

  Represents a state in the agent system. A state is associated uniquely with a task and an agent.

  This entity is used to store states in MongoDB, with each state
  associated with a specific task and agent. The combination of task_id and agent_id is globally unique.

  The state is a dictionary of arbitrary data.

  - `id: string`

    The task state's unique id

  - `agent_id: string`

  - `created_at: string`

    The timestamp when the state was created

  - `state: map[unknown]`

  - `task_id: string`

  - `updated_at: optional string`

    The timestamp when the state was last updated

### Example

```http
curl http://localhost:5003/states/$STATE_ID \
    -H "Authorization: Bearer $AGENTEX_SDK_API_KEY"
```

#### Response

```json
{
  "id": "id",
  "agent_id": "agent_id",
  "created_at": "2019-12-27T18:11:19.117Z",
  "state": {
    "foo": "bar"
  },
  "task_id": "task_id",
  "updated_at": "2019-12-27T18:11:19.117Z"
}
```

## Update Task State

**put** `/states/{state_id}`

Update Task State

### Path Parameters

- `state_id: string`

### Body Parameters

- `state: map[unknown]`

### Returns

- `State object { id, agent_id, created_at, 3 more }`

  Represents a state in the agent system. A state is associated uniquely with a task and an agent.

  This entity is used to store states in MongoDB, with each state
  associated with a specific task and agent. The combination of task_id and agent_id is globally unique.

  The state is a dictionary of arbitrary data.

  - `id: string`

    The task state's unique id

  - `agent_id: string`

  - `created_at: string`

    The timestamp when the state was created

  - `state: map[unknown]`

  - `task_id: string`

  - `updated_at: optional string`

    The timestamp when the state was last updated

### Example

```http
curl http://localhost:5003/states/$STATE_ID \
    -X PUT \
    -H 'Content-Type: application/json' \
    -H "Authorization: Bearer $AGENTEX_SDK_API_KEY" \
    -d '{
          "state": {
            "foo": "bar"
          }
        }'
```

#### Response

```json
{
  "id": "id",
  "agent_id": "agent_id",
  "created_at": "2019-12-27T18:11:19.117Z",
  "state": {
    "foo": "bar"
  },
  "task_id": "task_id",
  "updated_at": "2019-12-27T18:11:19.117Z"
}
```

## Delete Task State

**delete** `/states/{state_id}`

Delete Task State

### Path Parameters

- `state_id: string`

### Returns

- `State object { id, agent_id, created_at, 3 more }`

  Represents a state in the agent system. A state is associated uniquely with a task and an agent.

  This entity is used to store states in MongoDB, with each state
  associated with a specific task and agent. The combination of task_id and agent_id is globally unique.

  The state is a dictionary of arbitrary data.

  - `id: string`

    The task state's unique id

  - `agent_id: string`

  - `created_at: string`

    The timestamp when the state was created

  - `state: map[unknown]`

  - `task_id: string`

  - `updated_at: optional string`

    The timestamp when the state was last updated

### Example

```http
curl http://localhost:5003/states/$STATE_ID \
    -X DELETE \
    -H "Authorization: Bearer $AGENTEX_SDK_API_KEY"
```

#### Response

```json
{
  "id": "id",
  "agent_id": "agent_id",
  "created_at": "2019-12-27T18:11:19.117Z",
  "state": {
    "foo": "bar"
  },
  "task_id": "task_id",
  "updated_at": "2019-12-27T18:11:19.117Z"
}
```

## Domain Types

### State

- `State object { id, agent_id, created_at, 3 more }`

  Represents a state in the agent system. A state is associated uniquely with a task and an agent.

  This entity is used to store states in MongoDB, with each state
  associated with a specific task and agent. The combination of task_id and agent_id is globally unique.

  The state is a dictionary of arbitrary data.

  - `id: string`

    The task state's unique id

  - `agent_id: string`

  - `created_at: string`

    The timestamp when the state was created

  - `state: map[unknown]`

  - `task_id: string`

  - `updated_at: optional string`

    The timestamp when the state was last updated

### State List Response

- `StateListResponse = array of State`

  - `id: string`

    The task state's unique id

  - `agent_id: string`

  - `created_at: string`

    The timestamp when the state was created

  - `state: map[unknown]`

  - `task_id: string`

  - `updated_at: optional string`

    The timestamp when the state was last updated
