# Agent check state

## Overview

Starting with the release of **Agent 2.18**, the Agent Check API exposes two new interfaces to allow stateful behavior in Agent Checks. More specific details of the Agent interfaces can be found in the [Agent check API](https://archivedocs.stackstate.com/5.1/develop/developer-guides/agent_check/agent-check-api)

## When to use Agent State

Agent State is intended for Agent Checks that need to persist state in between check runs. The type of persistence model to use depends on the use case. `Stateful Agent Checks` are able to persist state to disk after each check run, **regardless of whether the check completely successfully or data was successfully sent to StackState**. `Transactional Agent Checks` have two states; Persistent state which behaves the same as state in a `Stateful Agent Check` and transactional state. Transactional state is persisted when the check **completes successfully and the data was delivered to StackState.**

State(s) are parameters to the `stateful_check` and `transactional_check` methods and the values in the return type are eventually persisted.

⚠️ **PLEASE NOTE -** State files are persisted as plain text in JSON format, therefore no passwords / secrets should ever be stored as state.

## Agent State location

{% tabs %}
{% tab title="Linux" %}
The state files are located in the `/opt/stackstate-agent/run/{check_name}` folder for each stateful / transactional check.

The root path `/opt/stackstate-agent/run` can be updated by setting:

* `check_state_root_path` in the Agent configuration file located at: `/etc/stackstate-agent/stackstate.yaml`.
* Setting `STS_CHECK_STATE_ROOT_PATH={path}` as a environment variable.
  {% endtab %}

{% tab title="Docker" %}
The state files are located in the `/opt/stackstate-agent/run/{check_name}` folder for each stateful / transactional check.

The root path `/opt/stackstate-agent/run` can be updated by setting:

* `check_state_root_path` in the Agent configuration file located at: `/etc/stackstate-agent/stackstate.yaml`.
* Setting `STS_CHECK_STATE_ROOT_PATH={path}` as a environment variable.
* Alternatively mount a volume on the check state root path. For more information on mounting volumes for Docker, take a look here: <https://docs.docker.com/storage/volumes/>.
  {% endtab %}

{% tab title="Windows" %}
The state files are located in the `c:\programdata\stackstate-agent\run\{check_name}` folder for each stateful / transactional check.

The root path `c:\programdata\stackstate-agent\run` can be updated by setting:

* `check_state_root_path` in the Agent configuration file located at: `C:\ProgramData\StackState\stackstate.yaml`.
* Setting `STS_CHECK_STATE_ROOT_PATH={path}` as a environment variable.
  {% endtab %}
  {% endtabs %}

⚠️ **PLEASE NOTE -** Running stateful checks in Kubernetes is currently not supported by the StackState Agent Helm Chart.

## See also

* [How to develop Agent checks](https://archivedocs.stackstate.com/5.1/develop/developer-guides/agent_check/how_to_develop_agent_checks)
* [Agent check API](https://archivedocs.stackstate.com/5.1/develop/developer-guides/agent_check/agent-check-api)
* [Connect an Agent check with StackState using the Custom Synchronization StackPack](https://archivedocs.stackstate.com/5.1/develop/developer-guides/agent_check/connect_agent_check_with_stackstate)
* [Developer guide - Custom Synchronization StackPack](https://archivedocs.stackstate.com/5.1/develop/developer-guides/custom_synchronization_stackpack)
