FoundryStateStore Class
Note
This is an experimental class, and may change at any time.
Developer-facing client for one explicit Foundry state store.
The instance is bound to a single caller-chosen store name. Session or
conversation scoping is expressed by encoding that identity into the store
name itself (for example checkpoints/<conversation-id>), matching spec
PR 247's removal of built-in session isolation.
Prefer get_or_create over the constructor: it resolves (or creates) the store's server-side resource in one call, so you never need a separate lifecycle step before reading or writing items:
store = await FoundryStateStore.get_or_create("checkpoints/thread-abc")
await store.set_item("step-1", {"done": False})
Store-level operations (get, update, delete) act on
the bound store itself. The explicit *_item methods
(create_item, get_item, set_item,
delete_item, list_keys) act on individual items within it.
Create a store-bound durable state-store client.
Prefer get_or_create, which also resolves the server-side store resource; use the constructor directly only when you already know the store exists and want to skip that round trip.
Constructor
FoundryStateStore(name: str, credential: AsyncTokenCredential | None = None, endpoint: FoundryStorageEndpoint | str | None = None, *, user_isolation: bool = False, item_ttl_seconds: int = 2592000, description: str | None = None, tags: Mapping[str, str] | None = None, user_id: str | None = None, api_version: str = 'v1', **kwargs: Any)
Parameters
| Name | Description |
|---|---|
|
name
Required
|
The logical state-store name. Encode conversation/thread identity into this name when you need that scope. |
|
credential
|
<xref:AsyncTokenCredential> | None
Async token credential. Defaults to
Default value: None
|
|
endpoint
|
Foundry storage endpoint or project endpoint URL. Default value: None
|
Keyword-Only Parameters
| Name | Description |
|---|---|
|
user_isolation
|
Whether item operations should be partitioned per resolved user. Fixed at store creation; ignored if the store already exists. Default value: False
|
|
item_ttl_seconds
|
Store-level default TTL inherited by every item. Fixed at store creation; ignored if the store already exists. Default value: 2592000
|
|
description
|
Optional mutable store description, set at creation. Change it later with update. Default value: None
|
|
tags
|
Optional mutable store metadata tags, set at creation. Change them later with update. Default value: None
|
|
user_id
|
Delegated end-user identity for trusted callers. Default value: None
|
|
api_version
|
Storage API version. Default value: v1
|
Methods
| aclose |
Close the pipeline client and any owned default credential. |
| create_item |
Create a new item and fail on duplicate keys. |
| delete |
Delete the bound store, cascading to every item under it. |
| delete_item |
Delete one item by key. |
| get |
Fetch the bound store's own descriptor. |
| get_item |
Fetch one item by key. |
| get_or_create |
Return a client bound to name, creating the store if needed. This is the recommended entry point: it resolves the server-side store resource in one call (fetch, or create on first use) so callers never need a separate lifecycle step before reading or writing items. |
| list_keys |
List keys within the bound store. |
| set_item |
Create or replace one item by key. |
| update |
Update the bound store's mutable metadata ( |
aclose
Close the pipeline client and any owned default credential.
async aclose() -> None
create_item
Create a new item and fail on duplicate keys.
async create_item(key: str, value: JSONObject, *, tags: Mapping[str, str] | None = None, call_id: str | None = None) -> StateStoreItemRef
Parameters
| Name | Description |
|---|---|
|
key
Required
|
The item key to create. |
|
value
Required
|
The item payload as a JSON object. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
tags
|
Optional string labels stored with the item and used to filter list_keys. Default value: None
|
|
call_id
|
Explicit Foundry call ID to forward. The default
Default value: None
|
Returns
| Type | Description |
|---|---|
|
A reference to the created item. |
delete
Delete the bound store, cascading to every item under it.
async delete() -> DeletedStateStore
Returns
| Type | Description |
|---|---|
|
The deleted-store marker. |
delete_item
Delete one item by key.
async delete_item(key: str, *, if_match: str | None = None, call_id: str | None = None) -> DeletedStateStoreItem
Parameters
| Name | Description |
|---|---|
|
key
Required
|
The item key to delete. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
if_match
|
Optional concurrency token. Default value: None
|
|
call_id
|
Explicit Foundry call ID to forward. The default
Default value: None
|
Returns
| Type | Description |
|---|---|
|
The deleted-item marker. |
get
Fetch the bound store's own descriptor.
async get() -> StateStore
Returns
| Type | Description |
|---|---|
|
The store descriptor. |
Exceptions
| Type | Description |
|---|---|
|
If the store does not exist. |
get_item
Fetch one item by key.
async get_item(key: str, *, call_id: str | None = None) -> StateStoreItem | None
Parameters
| Name | Description |
|---|---|
|
key
Required
|
The item key to fetch. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
call_id
|
Explicit Foundry call ID to forward. The default
Default value: None
|
Returns
| Type | Description |
|---|---|
|
The item, or |
get_or_create
Return a client bound to name, creating the store if needed.
This is the recommended entry point: it resolves the server-side store resource in one call (fetch, or create on first use) so callers never need a separate lifecycle step before reading or writing items.
async classmethod get_or_create(name: str, credential: AsyncTokenCredential | None = None, endpoint: FoundryStorageEndpoint | str | None = None, *, user_isolation: bool = False, item_ttl_seconds: int = 2592000, description: str | None = None, tags: Mapping[str, str] | None = None, user_id: str | None = None, api_version: str = 'v1', **kwargs: Any) -> FoundryStateStore
Parameters
| Name | Description |
|---|---|
|
name
Required
|
The logical state-store name. See the constructor. |
|
credential
|
<xref:AsyncTokenCredential> | None
Async token credential. See the constructor. Default value: None
|
|
endpoint
|
Foundry storage endpoint or project endpoint URL. Default value: None
|
Keyword-Only Parameters
| Name | Description |
|---|---|
|
user_isolation
|
See the constructor. Only applied if the store does not already exist. Default value: False
|
|
item_ttl_seconds
|
See the constructor. Only applied if the store does not already exist. Default value: 2592000
|
|
description
|
See the constructor. Only applied if the store does not already exist. Default value: None
|
|
tags
|
See the constructor. Only applied if the store does not already exist. Default value: None
|
|
user_id
|
Delegated end-user identity for trusted callers. Default value: None
|
|
api_version
|
Storage API version. Default value: v1
|
Returns
| Type | Description |
|---|---|
|
The bound, ready-to-use store client. |
list_keys
List keys within the bound store.
async list_keys(*, tags: Mapping[str, str] | None = None, limit: int | None = None, after: str | None = None, before: str | None = None, order: Literal['asc', 'desc'] = 'desc', call_id: str | None = None) -> StateStoreItemKeyPage
Keyword-Only Parameters
| Name | Description |
|---|---|
|
tags
|
Optional tag filter; only keys whose tags match every provided pair are returned. Default value: None
|
|
limit
|
Optional maximum number of keys to return in the page. Default value: None
|
|
after
|
Return keys ordered after this cursor. Mutually exclusive
with Default value: None
|
|
before
|
Return keys ordered before this cursor. Mutually
exclusive with Default value: None
|
|
order
|
Sort order, Default value: desc
|
|
call_id
|
Explicit Foundry call ID to forward. The default
Default value: None
|
Returns
| Type | Description |
|---|---|
|
A page of item keys. |
set_item
Create or replace one item by key.
async set_item(key: str, value: JSONObject, *, tags: Mapping[str, str] | None = None, if_match: str | None = None, require_exists: bool = False, call_id: str | None = None) -> StateStoreItemRef
Parameters
| Name | Description |
|---|---|
|
key
Required
|
The item key to create or replace. |
|
value
Required
|
The item payload as a JSON object. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
tags
|
Optional string labels stored with the item and used to filter list_keys. Default value: None
|
|
if_match
|
Optional concurrency token; the write only succeeds
when the current item ETag matches. Mutually exclusive with
Default value: None
|
|
require_exists
|
When Default value: False
|
|
call_id
|
Explicit Foundry call ID to forward. The default
Default value: None
|
Returns
| Type | Description |
|---|---|
|
A reference to the created or replaced item. |
update
Update the bound store's mutable metadata (description / tags).
async update(*, description: str | None | object = <object object>, tags: ~collections.abc.Mapping[str, str] | None | object = <object object>) -> StateStore
Keyword-Only Parameters
| Name | Description |
|---|---|
|
description
|
The new description, or Default value: <object object at 0x000002984AB03650>
|
|
tags
|
The new tags (replaces the existing set wholesale), or
Default value: <object object at 0x000002984AB03650>
|
Returns
| Type | Description |
|---|---|
|
The updated store descriptor. |
Attributes
name
Return the logical store name bound to this client.