# States

## Create Task State

`states.create(StateCreateParams**kwargs)  -> State`

**post** `/states`

Create Task State

### Parameters

- `agent_id: str`

- `state: Dict[str, object]`

- `task_id: str`

### Returns

- `class 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: str`

    The task state's unique id

  - `agent_id: str`

  - `created_at: datetime`

    The timestamp when the state was created

  - `state: Dict[str, object]`

  - `task_id: str`

  - `updated_at: Optional[datetime]`

    The timestamp when the state was last updated

### Example

```python
import os
from agentex import Agentex

client = Agentex(
    api_key=os.environ.get("AGENTEX_SDK_API_KEY"),  # This is the default and can be omitted
)
state = client.states.create(
    agent_id="agent_id",
    state={
        "foo": "bar"
    },
    task_id="task_id",
)
print(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

`states.list(StateListParams**kwargs)  -> StateListResponse`

**get** `/states`

List all states, optionally filtered by query parameters.

### Parameters

- `agent_id: Optional[str]`

  Agent ID

- `limit: Optional[int]`

  Limit

- `order_by: Optional[str]`

  Field to order by

- `order_direction: Optional[str]`

  Order direction (asc or desc)

- `page_number: Optional[int]`

  Page number

- `task_id: Optional[str]`

  Task ID

### Returns

- `List[State]`

  - `id: str`

    The task state's unique id

  - `agent_id: str`

  - `created_at: datetime`

    The timestamp when the state was created

  - `state: Dict[str, object]`

  - `task_id: str`

  - `updated_at: Optional[datetime]`

    The timestamp when the state was last updated

### Example

```python
import os
from agentex import Agentex

client = Agentex(
    api_key=os.environ.get("AGENTEX_SDK_API_KEY"),  # This is the default and can be omitted
)
states = client.states.list()
print(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

`states.retrieve(strstate_id)  -> State`

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

Get a state by its unique state ID.

### Parameters

- `state_id: str`

### Returns

- `class 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: str`

    The task state's unique id

  - `agent_id: str`

  - `created_at: datetime`

    The timestamp when the state was created

  - `state: Dict[str, object]`

  - `task_id: str`

  - `updated_at: Optional[datetime]`

    The timestamp when the state was last updated

### Example

```python
import os
from agentex import Agentex

client = Agentex(
    api_key=os.environ.get("AGENTEX_SDK_API_KEY"),  # This is the default and can be omitted
)
state = client.states.retrieve(
    "state_id",
)
print(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

`states.update(strstate_id, StateUpdateParams**kwargs)  -> State`

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

Update Task State

### Parameters

- `state_id: str`

- `state: Dict[str, object]`

### Returns

- `class 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: str`

    The task state's unique id

  - `agent_id: str`

  - `created_at: datetime`

    The timestamp when the state was created

  - `state: Dict[str, object]`

  - `task_id: str`

  - `updated_at: Optional[datetime]`

    The timestamp when the state was last updated

### Example

```python
import os
from agentex import Agentex

client = Agentex(
    api_key=os.environ.get("AGENTEX_SDK_API_KEY"),  # This is the default and can be omitted
)
state = client.states.update(
    state_id="state_id",
    state={
        "foo": "bar"
    },
)
print(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

`states.delete(strstate_id)  -> State`

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

Delete Task State

### Parameters

- `state_id: str`

### Returns

- `class 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: str`

    The task state's unique id

  - `agent_id: str`

  - `created_at: datetime`

    The timestamp when the state was created

  - `state: Dict[str, object]`

  - `task_id: str`

  - `updated_at: Optional[datetime]`

    The timestamp when the state was last updated

### Example

```python
import os
from agentex import Agentex

client = Agentex(
    api_key=os.environ.get("AGENTEX_SDK_API_KEY"),  # This is the default and can be omitted
)
state = client.states.delete(
    "state_id",
)
print(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

- `class 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: str`

    The task state's unique id

  - `agent_id: str`

  - `created_at: datetime`

    The timestamp when the state was created

  - `state: Dict[str, object]`

  - `task_id: str`

  - `updated_at: Optional[datetime]`

    The timestamp when the state was last updated

### State List Response

- `List[State]`

  - `id: str`

    The task state's unique id

  - `agent_id: str`

  - `created_at: datetime`

    The timestamp when the state was created

  - `state: Dict[str, object]`

  - `task_id: str`

  - `updated_at: Optional[datetime]`

    The timestamp when the state was last updated
