[agentserver-core] Add FoundryStateStore durable KV storage layer#47763
[agentserver-core] Add FoundryStateStore durable KV storage layer#47763shanmukha1200 wants to merge 10 commits into
Conversation
|
Thank you for your contribution @shanmukha1200! We will review the pull request and get back to you soon. |
There was a problem hiding this comment.
Pull request overview
This PR adds a new protocol-neutral storage layer (azure.ai.agentserver.core.storage) to azure-ai-agentserver-core. It introduces FoundryStorageClient (a base owning the AsyncPipelineClient, policy chain, and error handling) and FoundryStateStore, a generic durable key-value store over POST /storage/state:read|:write|:listKeys with namespace/key/value/tags, optional if_match optimistic concurrency, and ordered, paged list_keys. This generalizes the existing responses-package FoundryStorageProvider into the shared core so protocol packages can build resource-specific clients on top.
Changes:
- New
storagesubpackage: client/transport, endpoint resolution, error hierarchy, pipeline policies, JSON helpers, and theFoundryStateStoreKV store with its serializer. - Added
azure-core>=1.30.0dependency and a CHANGELOG2.0.0b6 (Unreleased)entry. - Added unit tests for request construction and response handling.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
storage/__init__.py |
Public exports for the new storage package. |
storage/_client.py |
FoundryStorageClient base: pipeline, policies, _send_storage_request. |
storage/_endpoint.py |
FoundryStorageEndpoint resolution and versioned URL building. |
storage/_errors.py |
Storage exception hierarchy incl. new FoundryStoragePreconditionError (412). |
storage/_policies.py |
UA + per-retry logging policies with URL masking. |
storage/_state.py |
FoundryStateStore read/write/list_keys/get/set/delete. |
storage/_state_serializer.py |
Wire (de)serialization + StateItem/StateKey/KeyPage types. |
storage/_json.py |
Small JSON parsing helper. |
tests/test_foundry_state_store.py |
Unit tests for request/response behavior. |
pyproject.toml |
Adds azure-core>=1.30.0 dependency. |
CHANGELOG.md |
Adds 2.0.0b6 (Unreleased) feature entry (version not synced — see comment). |
|
@shanmukha1200 please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
a6d75fa to
13e374f
Compare
Adds azure.ai.agentserver.core.storage: a protocol-neutral Foundry storage
layer (FoundryStorageClient transport, endpoint, pipeline policies, error
hierarchy) and FoundryStateStore, a durable namespace-scoped key-value store
over POST /storage/state:read|:write|:listKeys with if_match optimistic
concurrency, per-item TTL, tags, and ordered, paged list_keys.
The public contract is strongly typed: writes use the Upsert/Delete change
objects (WriteChange), stored values are typed as JSONValue, and list order is
a Literal ("asc"/"desc"). Internal helpers and pipeline policies are kept out
of the public surface.
Includes unit tests for the state store, error mapping, endpoint resolution,
and pipeline policies; a developer guide (docs/state-store-guide.md); a
runnable sample; and README/CHANGELOG updates.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
13e374f to
1d7b980
Compare
Refactor FoundryStateStore to follow the explicit /storage/statestores/* protocol while keeping it as the public developer-facing entry point. This removes the old namespace-scoped batch/session-isolation model in favor of explicit store lifecycle APIs plus single-item operations, store-level TTL, delegated x-ms-user-id support on item paths, and updated docs/samples/tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add get_or_create and create_or_get helpers for explicit store setup while keeping FoundryStateStore construction side-effect free. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
| item_ttl_seconds=3600, | ||
| description="Checkpoint store for thread abc", | ||
| ) as store: | ||
| await store.get_or_create() |
There was a problem hiding this comment.
Can you simplify?
store = FoundryStateStore.get_or_create(...)
await store.set(...)
| Stores are **explicit resources**. Create or resolve them before writing items. | ||
|
|
||
| ```python | ||
| info = await store.create() |
There was a problem hiding this comment.
This whole surface needs some polish
store = await FoundryStateStore.create(...);
store = await FoundryStateStore.get(name);
store = await FoundryStateStore.get_or_create(...);
store = await store.update(...);
store = await store.delete(...);
…e-storage spec (foundrysdk_specs#247)
Per the latest commit on coreai-microsoft/foundrysdk_specs#247
("rename route to /storage/state_stores, add store PATCH update, align
object descriptors"), the state-store REST path is /storage/state_stores/*
(snake_case with underscore), not /storage/statestores/*.
- _state.py: store path + create() now target state_stores.
- _policies.py: masked-logging allowlist updated to the new segment name.
- Updated docs/state-store-guide.md, README, and test URL assertions.
- Fixed the core CHANGELOG/README, which still described the earlier
namespace-based design (pre-dating the PR Azure#47763 pull) instead of the
current store-bound statestores-protocol API; also dropped an unused
aiohttp dependency left over from that earlier design.
No functional change beyond the route rename -- the object-type descriptor
changes in the spec commit (state_store / state_store.item) are response-only
fields the SDK does not parse or assert on.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…te/get/update/delete Per review feedback on PR Azure#47763 (constructor-then-create felt awkward) and the guide-first workflow: reshape the store-admin surface to four verbs instead of six, and stop threading the per-request delegated-user header through the constructor. - FoundryStateStore.get_or_create(name, ...) is now the sole entry point (an async classmethod): resolves the store in one call (fetch, or create on first use, refetching on a create/create race), replacing the previous constructor + separate create()/create_or_get()/get_or_create() dance. - get(key=None) and delete(key=None, ...) are overloaded on whether a key is supplied: no key acts on the bound store itself (was get_properties / delete_store); a key acts on one item (unchanged item-level behavior). update(...) replaces update_metadata(...) (no collision, simple rename). - Removed the constructor's user_id parameter. x-ms-user-id is a per-request delegation header, not a store-level setting -- it is now resolved dynamically, per call, from azure.ai.agentserver.core's existing request-scoped platform context (get_request_context().user_id), the same mechanism protocol hosts already populate from the inbound x-agent-user-id header. A single (possibly long-lived, reused) FoundryStateStore instance can now safely serve requests for different users. - azure-ai-agentserver-activity's FoundryStorage updated to call the new classmethod for writes while keeping the plain constructor for reads/ deletes (both already tolerate a not-yet-created store gracefully), so the "only create on first write" behavior is unchanged. - Rewrote the core state-store tests, the sample, and the developer guide for the new shape; added a "Limits" section to the guide mirroring the spec's field-constraints tables (no equivalent guide exists yet for the resilient-task primitive to model this section after). Verified: black, mypy, and pytest all clean for both packages (148 + 99 passed). Two mypy findings in _state.py (tags Union narrowing in update(), **query kwargs in list_keys) are pre-existing, inherited verbatim from PR Azure#47763's pulled code -- unrelated to this rename and left as-is. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…te/get/update/delete Addresses PR review feedback (constructor-then-create felt awkward) and aligns the SDK with the latest state-storage spec commit (route renamed to /storage/state_stores/*). - Route rename: /storage/statestores/* -> /storage/state_stores/* in _state.py's request paths and _policies.py's masked-logging allowlist. - FoundryStateStore.get_or_create(name, ...) is now the sole entry point (an async classmethod): resolves the store in one call (fetch, or create on first use, refetching on a create/create race), replacing the previous constructor + separate create()/create_or_get()/get_or_create() dance. - get(key=None) and delete(key=None, ...) are overloaded on whether a key is supplied: no key acts on the bound store itself (was get_properties / delete_store); a key acts on one item (unchanged item-level behavior). update(...) replaces update_metadata(...) (no collision, simple rename). - The user_id constructor parameter (delegated x-ms-user-id) is unchanged on this branch: this base predates azure.ai.agentserver.core's request-scoped platform context (added later, in 2.0.0b7), so the "resolve user_id per-request instead of at construction" fix from the sibling PR (Azure#47978) does not apply here yet without also backporting that module. Flagging for a follow-up once this PR is based on (or merges after) that work. - Rewrote the state-store tests, the sample, the developer guide, and the README snippet for the new shape; added a "Limits" section to the guide mirroring the spec's field-constraints tables. Verified: black and pytest clean for the storage surface (41 storage tests pass). Three pre-existing mypy findings in _state.py / _state_serializer.py (tags Union narrowing in update(), **query kwargs in list_keys) predate this change and are left as-is. Three unrelated pre-existing test_tracing.py failures in this branch's older tracing code (opentelemetry-sdk version mismatch) are also unrelated to this change. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…s from a TypeSpec contract Same change as PR Azure#47978, ported onto this branch's base (which predates _request_context.py, so the constructor-based user_id parameter is unchanged here -- see FoundryStateStore.__init__/_request()). Replace hand-rolled dataclasses + ad hoc JSON (de)serialization in FoundryStateStore with real Python model classes generated from a formal TypeSpec contract (type_spec/main.tsp), the same @azure-tools/typespec-python emitter azure-ai-agentserver-responses uses. The contract does not live under Azure/azure-rest-api-specs yet, so models are compiled locally for now (see type_spec/README.md) instead of tsp-client sync. - Added type_spec/main.tsp, package.json/README, and a Makefile generate-models target. - Added azure/ai/agentserver/core/storage/_generated/: generated model classes (StateStore, StateStoreItem, StateStoreItemMetadata, DeletedStateStore, DeletedStateStoreItem, StateStoreKey, CreateStateStoreRequest, UpdateStateStoreRequest, CreateItemRequest, PutItemRequest, ListResponseStateStore(Key)) plus the model_base.py runtime it depends on. Added mypy.ini excluding _generated and the isodate dependency model_base.py requires. - Renamed public types to match the generated/spec names exactly: StateStoreInfo -> StateStore, StateItem -> StateStoreItem, StateItemMetadata -> StateStoreItemMetadata, DeletedStateItem -> DeletedStateStoreItem, StateKey -> StateStoreKey. KeyPage stays a hand-written convenience wrapper. - Rewrote _state_serializer.py's serialize_*/deserialize_* helpers to build/parse the generated models instead of raw dicts, preserving update()'s description/tags tri-state semantics via the generated model's mapping constructor. - Added @overload pairs to get()/delete() so callers get a narrow return type based on whether key is supplied, instead of one wide union. - Updated tests, CHANGELOG, and README for the above. 27/27 storage-specific tests pass (3 pre-existing, unrelated test_tracing.py failures confirmed environment/version-related); mypy clean aside from the same pre-existing finding already called out in the prior commit on this branch. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…tate-store guide The guide's code samples returned typed objects (StateStore, StateStoreItem, etc.) but never imported or named the types, so every example read as if get()/set()/list_keys() returned raw dicts. Added a Typed Models section mapping each method to its return model, and added explicit imports/type annotations to the Getting Started, Store Lifecycle, Fetch-one-item, and Listing Keys examples. StateStoreItem.value stays intentionally untyped (opaque application JSON) -- called that out explicitly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…tate-store guide Same fix as the sibling PR Azure#47763: the guide's code samples returned typed objects (StateStore, StateStoreItem, etc.) but never imported or named the types, so every example read as if get()/set()/list_keys() returned raw dicts. Added a Typed Models section mapping each method to its return model, and added explicit imports/type annotations to the Getting Started, Store Lifecycle, Fetch-one-item, and Listing Keys examples. StateStoreItem.value stays intentionally untyped (opaque application JSON) -- called that out explicitly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…yword Same change as the sibling PR Azure#47978, ported onto this branch's base (constructor-based user_id parameter unchanged here). The constructor, get_or_create(), update(), create_item(), and set() still took only scattered kwargs (user_isolation, item_ttl_seconds, description, tags) even after the underlying request bodies became typed generated models -- there was no way to build/reuse a CreateStateStoreRequest etc. and pass it straight through. Each of those methods now also accepts an 'options' keyword: a typed request model bundling its scattered keywords into one object, mutually exclusive with them per call. - Constructor / get_or_create(): options: CreateStateStoreRequest | None. options.name is ignored -- the store's name always comes from the required `name` parameter. Absent fields on options fall back to the same defaults the scattered kwargs use. - update(): options: UpdateStateStoreRequest | None. Building options via its mapping constructor (e.g. UpdateStateStoreRequest({"tags": None})) preserves the omit-vs-null distinction the description/tags keywords make via the _UNSET sentinel -- a field's absence from options means "leave unchanged", presence with None means "clear it". - create_item() / set(): options: CreateItemRequest | PutItemRequest | None. Only options.tags is read; key/value always come from the method's own required parameters. - Added _resolve_create_options()/_resolve_tags_option() helpers in _state.py implementing the reconciliation + mutual-exclusion checks. - Re-exported CreateStateStoreRequest, UpdateStateStoreRequest, CreateItemRequest, and PutItemRequest from azure.ai.agentserver.core.storage (previously internal-only, used only by _state_serializer.py). - Documented the new options keyword in the state-store guide (with the update() unset-vs-null gotcha called out) and added CHANGELOG coverage. - Added 10 new tests covering the options path, its defaulting behavior, and the mutual-exclusion ValueError for all five methods. 141/146 core tests pass (3 pre-existing, unrelated test_tracing.py failures confirmed environment/version-related, 5 skipped); mypy clean aside from the same pre-existing finding already called out in prior commits on this branch. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Rewrite the durable state store guide prose to be customer-first: remove internal architecture references (FoundryStorageClient pipeline, /storage/state_stores/* protocol, type_spec/main.tsp, "protocol's single-item PUT", on-the-wire base64url encoding) and defensive "not a raw dict / does not and cannot" framing. Content, examples, tables, and limits are unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Make FoundryStateStore opinionated toward simple key-value semantics: remove the typed request-object `options=` keyword from the constructor, get_or_create(), update(), create_item(), and set(). Callers now pass plain scalar keywords only (user_isolation, item_ttl_seconds, description, tags), matching every sibling store (MAF CheckpointStorage, ADK BaseMemoryService, in-SDK InMemoryResponseProvider, azure-ai-projects BetaMemoryStoresOperations) -- none exposes generated request-body models as a caller-facing options= param. Responses stay typed. - Delete _resolve_create_options() and _resolve_tags_option() helpers. - Stop re-exporting CreateStateStoreRequest / UpdateStateStoreRequest / CreateItemRequest / PutItemRequest from storage/__init__ and the serializer __all__ (still used internally to build wire bodies). - Keep item_ttl_seconds naming (matches our own state-store wire contract; the memory-store default_ttl_seconds precedent is a different, nested resource). - Update guide (remove "Accepted request options" section, flat-kwargs examples), CHANGELOG, and tests (remove 10 options= tests). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
| - Any item write renews the TTL window for that item | ||
| - Reads do **not** renew the TTL window | ||
|
|
||
| ## Single-Item Operations |
There was a problem hiding this comment.
Follow the same naming convention for all item operations <create/set/deleteget>_item()
| |---|---| | ||
| | `get_or_create()`, `get()` (no `key`), `update()` | `StateStore` | | ||
| | `delete()` (no `key`) | `DeletedStateStore` | | ||
| | `create_item()`, `set()` | `StateStoreItemMetadata` | |
There was a problem hiding this comment.
Why StateStoreItemMetadata and not StateStoreItem?
There was a problem hiding this comment.
StateStoreItem has a value by definition maybe metadata sounds vague but we would need another typed response object
There was a problem hiding this comment.
maybe
stateStoreItem
----> StateStoreItemKey
--->Name
---->etag
-----> createdAt
----> updatedAt
-----> Value
follow this heirarchy and return StateStoreItemKey for create and StateStoreItem for get
| | `create_item()`, `set()` | `StateStoreItemMetadata` | | ||
| | `get(key)` | `StateStoreItem` | | ||
| | `delete(key)` | `DeletedStateStoreItem` | | ||
| | `list_keys()` | `KeyPage` (of `StateStoreKey`) | |
There was a problem hiding this comment.
this needs typespec change will take it up once all other comments are resolved
| print(store.name) | ||
| ``` | ||
|
|
||
| `get()` and `delete()` are overloaded on whether you pass a `key`: with no |
There was a problem hiding this comment.
This kind of overload is bad. Lets avoid this and make item methods separate and explicit *_item methods.
Address review feedback (PR Azure#47763): remove the key-vs-no-key @Overloads on FoundryStateStore.get/delete and give every item operation an explicit, consistently named method. - set -> set_item - get(key) -> get_item(key); bare get() stays store-scoped - delete(key) -> delete_item(key); bare delete() stays store-scoped - create_item / list_keys unchanged Store-level get()/update()/delete() now unambiguously act on the bound store. Updates README, state-store guide, samples, tests, and CHANGELOG to match. No TypeSpec/generated-model changes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add azure.ai.agentserver.core.storage: protocol-neutral FoundryStorageClient (transport, endpoint, pipeline policies, error hierarchy) plus FoundryStateStore, a generic durable key-value store over /storage/state:read|:write|:listKeys with namespace/key/value/tags, optional if_match optimistic concurrency, and ordered paged list_keys. Adds azure-core dependency and tests.
Responses has its own storage providers idea is to make responses re-use this storage clients in a follow-up PR
Description
Please add an informative description that covers that changes made by the pull request and link all relevant issues.
If an SDK is being regenerated based on a new API spec, a link to the pull request containing these API spec changes should be included above.
All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines