# States

## Create Task State

`client.states.create(StateCreateParamsbody, RequestOptionsoptions?): State`

**post** `/states`

Create Task State

### Parameters

- `body: StateCreateParams`

  - `agent_id: string`

  - `state: Record<string, unknown>`

  - `task_id: string`

### Returns

- `State`

  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: Record<string, unknown>`

  - `task_id: string`

  - `updated_at?: string | null`

    The timestamp when the state was last updated

### Example

```typescript
import Agentex from 'agentex';

const client = new Agentex({
  apiKey: process.env['AGENTEX_SDK_API_KEY'], // This is the default and can be omitted
});

const state = await client.states.create({
  agent_id: 'agent_id',
  state: { foo: 'bar' },
  task_id: 'task_id',
});

console.log(state.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

`client.states.list(StateListParamsquery?, RequestOptionsoptions?): StateListResponse`

**get** `/states`

List all states, optionally filtered by query parameters.

### Parameters

- `query: StateListParams`

  - `agent_id?: string | null`

    Agent ID

  - `limit?: number`

    Limit

  - `order_by?: string | null`

    Field to order by

  - `order_direction?: string`

    Order direction (asc or desc)

  - `page_number?: number`

    Page number

  - `task_id?: string | null`

    Task ID

### Returns

- `StateListResponse = Array<State>`

  - `id: string`

    The task state's unique id

  - `agent_id: string`

  - `created_at: string`

    The timestamp when the state was created

  - `state: Record<string, unknown>`

  - `task_id: string`

  - `updated_at?: string | null`

    The timestamp when the state was last updated

### Example

```typescript
import Agentex from 'agentex';

const client = new Agentex({
  apiKey: process.env['AGENTEX_SDK_API_KEY'], // This is the default and can be omitted
});

const states = await client.states.list();

console.log(states);
```

#### 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

`client.states.retrieve(stringstateID, RequestOptionsoptions?): State`

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

Get a state by its unique state ID.

### Parameters

- `stateID: string`

### Returns

- `State`

  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: Record<string, unknown>`

  - `task_id: string`

  - `updated_at?: string | null`

    The timestamp when the state was last updated

### Example

```typescript
import Agentex from 'agentex';

const client = new Agentex({
  apiKey: process.env['AGENTEX_SDK_API_KEY'], // This is the default and can be omitted
});

const state = await client.states.retrieve('state_id');

console.log(state.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"
}
```

## Update Task State

`client.states.update(stringstateID, StateUpdateParamsbody, RequestOptionsoptions?): State`

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

Update Task State

### Parameters

- `stateID: string`

- `body: StateUpdateParams`

  - `state: Record<string, unknown>`

### Returns

- `State`

  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: Record<string, unknown>`

  - `task_id: string`

  - `updated_at?: string | null`

    The timestamp when the state was last updated

### Example

```typescript
import Agentex from 'agentex';

const client = new Agentex({
  apiKey: process.env['AGENTEX_SDK_API_KEY'], // This is the default and can be omitted
});

const state = await client.states.update('state_id', { state: { foo: 'bar' } });

console.log(state.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"
}
```

## Delete Task State

`client.states.delete(stringstateID, RequestOptionsoptions?): State`

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

Delete Task State

### Parameters

- `stateID: string`

### Returns

- `State`

  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: Record<string, unknown>`

  - `task_id: string`

  - `updated_at?: string | null`

    The timestamp when the state was last updated

### Example

```typescript
import Agentex from 'agentex';

const client = new Agentex({
  apiKey: process.env['AGENTEX_SDK_API_KEY'], // This is the default and can be omitted
});

const state = await client.states.delete('state_id');

console.log(state.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"
}
```

## Domain Types

### State

- `State`

  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: Record<string, unknown>`

  - `task_id: string`

  - `updated_at?: string | null`

    The timestamp when the state was last updated

### State List Response

- `StateListResponse = Array<State>`

  - `id: string`

    The task state's unique id

  - `agent_id: string`

  - `created_at: string`

    The timestamp when the state was created

  - `state: Record<string, unknown>`

  - `task_id: string`

  - `updated_at?: string | null`

    The timestamp when the state was last updated
