Debian Codegraph @

src/anthropic/resources/beta/memory_stores/memory_stores.py

raw
1 from __future__ import annotations
2
3 from typing import Dict, List, Union, Optional
4 from datetime import datetime
5 from itertools import chain
6
7 import httpx2
8
9 from .memories import (
10 Memories,
11 AsyncMemories,
12 MemoriesWithRawResponse,
13 AsyncMemoriesWithRawResponse,
14 MemoriesWithStreamingResponse,
15 AsyncMemoriesWithStreamingResponse,
16 )
17 from ...._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
18 from ...._utils import is_given, path_template, strip_not_given
19 from ...._compat import cached_property
20 from ...._resource import SyncAPIResource, AsyncAPIResource
21 from ...._response import (
22 to_raw_response_wrapper,
23 to_streamed_response_wrapper,
24 async_to_raw_response_wrapper,
25 async_to_streamed_response_wrapper,
26 )
27 from ....pagination import SyncPageCursor, AsyncPageCursor
28 from ...._base_client import AsyncPaginator, make_request_options
29 from .memory_versions import (
30 MemoryVersions,
31 AsyncMemoryVersions,
32 MemoryVersionsWithRawResponse,
33 AsyncMemoryVersionsWithRawResponse,
34 MemoryVersionsWithStreamingResponse,
35 AsyncMemoryVersionsWithStreamingResponse,
36 )
37 from ....types.anthropic_beta_param import AnthropicBetaParam
38 from ....types.beta.beta_managed_agents_memory_store import BetaManagedAgentsMemoryStore
39 from ....types.beta.beta_managed_agents_deleted_memory_store import BetaManagedAgentsDeletedMemoryStore
40
41 __all__ = ["MemoryStores", "AsyncMemoryStores"]
42
43
44 class MemoryStores(SyncAPIResource):
45 @cached_property
46 def memories(self) -> Memories:
47 return Memories(self._client)
48
49 @cached_property
50 def memory_versions(self) -> MemoryVersions:
51 return MemoryVersions(self._client)
52
53 @cached_property
54 def with_raw_response(self) -> MemoryStoresWithRawResponse:
55 """
56 This property can be used as a prefix for any HTTP method call to return
57 the raw response object instead of the parsed content.
58
59 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
60 """
61 return MemoryStoresWithRawResponse(self)
62
63 @cached_property
64 def with_streaming_response(self) -> MemoryStoresWithStreamingResponse:
65 """
66 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
67
68 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
69 """
70 return MemoryStoresWithStreamingResponse(self)
71
72 def create(
73 self,
74 *,
75 name: str,
76 description: str | Omit = omit,
77 metadata: Dict[str, str] | Omit = omit,
78 betas: List[AnthropicBetaParam] | Omit = omit,
79 workspace_id: str | Omit = omit,
80 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
81 # The extra values given here take precedence over values defined on the client or passed to this method.
82 extra_headers: Headers | None = None,
83 extra_query: Query | None = None,
84 extra_body: Body | None = None,
85 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
86 ) -> BetaManagedAgentsMemoryStore:
87 """Create a memory store
88
89 Args:
90 name: Human-readable name for the store.
91
92 Required; 1–255 characters; no control
93 characters. The mount-path slug under `/mnt/memory/` is derived from this name
94 (lowercased, non-alphanumeric runs collapsed to a hyphen). Names need not be
95 unique within a workspace.
96
97 description: Free-text description of what the store contains, up to 1024 characters.
98 Included in the agent's system prompt when the store is attached, so word it to
99 be useful to the agent.
100
101 metadata: Arbitrary key-value tags for your own bookkeeping (such as the end user a store
102 belongs to). Up to 16 pairs; keys 1–64 characters; values up to 512 characters.
103 Not visible to the agent.
104
105 betas: Optional header to specify the beta version(s) you want to use.
106
107 workspace_id: Optional header to select the Workspace for this request. The value is a
108 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
109
110 Only needed for credentials that can act on more than one Workspace. A
111 credential that belongs to a specific Workspace may omit it; if sent, it must
112 match that Workspace.
113
114 extra_headers: Send extra headers
115
116 extra_query: Add additional query parameters to the request
117
118 extra_body: Add additional JSON properties to the request
119
120 timeout: Override the client-level default timeout for this request, in seconds
121 """
122 extra_headers = {
123 **strip_not_given(
124 {
125 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["agent-memory-2026-07-22"]))
126 if is_given(betas)
127 else not_given,
128 "anthropic-workspace-id": workspace_id,
129 }
130 ),
131 **(extra_headers or {}),
132 }
133 extra_headers = {"anthropic-beta": "agent-memory-2026-07-22", **(extra_headers or {})}
134 return self._post(
135 "/v1/memory_stores?beta=true",
136 body={
137 "name": name,
138 "description": description,
139 "metadata": metadata,
140 },
141 options=make_request_options(
142 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
143 ),
144 cast_to=BetaManagedAgentsMemoryStore,
145 )
146
147 def retrieve(
148 self,
149 memory_store_id: str,
150 *,
151 betas: List[AnthropicBetaParam] | Omit = omit,
152 workspace_id: str | Omit = omit,
153 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
154 # The extra values given here take precedence over values defined on the client or passed to this method.
155 extra_headers: Headers | None = None,
156 extra_query: Query | None = None,
157 extra_body: Body | None = None,
158 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
159 ) -> BetaManagedAgentsMemoryStore:
160 """
161 Retrieve a memory store
162
163 Args:
164 memory_store_id: ID of the memory store to retrieve (a `memstore_...` identifier). Required.
165 Enumerate IDs via `GET /v1/memory_stores`.
166
167 betas: Optional header to specify the beta version(s) you want to use.
168
169 workspace_id: Optional header to select the Workspace for this request. The value is a
170 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
171
172 Only needed for credentials that can act on more than one Workspace. A
173 credential that belongs to a specific Workspace may omit it; if sent, it must
174 match that Workspace.
175
176 extra_headers: Send extra headers
177
178 extra_query: Add additional query parameters to the request
179
180 extra_body: Add additional JSON properties to the request
181
182 timeout: Override the client-level default timeout for this request, in seconds
183 """
184 if not memory_store_id:
185 raise ValueError(f"Expected a non-empty value for `memory_store_id` but received {memory_store_id!r}")
186 extra_headers = {
187 **strip_not_given(
188 {
189 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["agent-memory-2026-07-22"]))
190 if is_given(betas)
191 else not_given,
192 "anthropic-workspace-id": workspace_id,
193 }
194 ),
195 **(extra_headers or {}),
196 }
197 extra_headers = {"anthropic-beta": "agent-memory-2026-07-22", **(extra_headers or {})}
198 return self._get(
199 path_template("/v1/memory_stores/{memory_store_id}?beta=true", memory_store_id=memory_store_id),
200 options=make_request_options(
201 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
202 ),
203 cast_to=BetaManagedAgentsMemoryStore,
204 )
205
206 def update(
207 self,
208 memory_store_id: str,
209 *,
210 description: Optional[str] | Omit = omit,
211 metadata: Optional[Dict[str, Optional[str]]] | Omit = omit,
212 name: Optional[str] | Omit = omit,
213 betas: List[AnthropicBetaParam] | Omit = omit,
214 workspace_id: str | Omit = omit,
215 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
216 # The extra values given here take precedence over values defined on the client or passed to this method.
217 extra_headers: Headers | None = None,
218 extra_query: Query | None = None,
219 extra_body: Body | None = None,
220 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
221 ) -> BetaManagedAgentsMemoryStore:
222 """
223 Update a memory store
224
225 Args:
226 memory_store_id: ID of the memory store to update (a `memstore_...` identifier). Required.
227 Enumerate IDs via `GET /v1/memory_stores`. Updating an archived store
228 returns 400.
229
230 description: New description for the store, up to 1024 characters. Pass an empty string to
231 clear it.
232
233 metadata: Metadata patch. Set a key to a string to upsert it, or to null to delete it.
234 Omit the field to preserve. The stored bag is limited to 16 keys (up to 64 chars
235 each) with values up to 512 chars.
236
237 name: New human-readable name for the store. 1–255 characters; no control characters.
238 Renaming changes the slug used for the store's `mount_path` in sessions created
239 after the update.
240
241 betas: Optional header to specify the beta version(s) you want to use.
242
243 workspace_id: Optional header to select the Workspace for this request. The value is a
244 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
245
246 Only needed for credentials that can act on more than one Workspace. A
247 credential that belongs to a specific Workspace may omit it; if sent, it must
248 match that Workspace.
249
250 extra_headers: Send extra headers
251
252 extra_query: Add additional query parameters to the request
253
254 extra_body: Add additional JSON properties to the request
255
256 timeout: Override the client-level default timeout for this request, in seconds
257 """
258 if not memory_store_id:
259 raise ValueError(f"Expected a non-empty value for `memory_store_id` but received {memory_store_id!r}")
260 extra_headers = {
261 **strip_not_given(
262 {
263 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["agent-memory-2026-07-22"]))
264 if is_given(betas)
265 else not_given,
266 "anthropic-workspace-id": workspace_id,
267 }
268 ),
269 **(extra_headers or {}),
270 }
271 extra_headers = {"anthropic-beta": "agent-memory-2026-07-22", **(extra_headers or {})}
272 return self._post(
273 path_template("/v1/memory_stores/{memory_store_id}?beta=true", memory_store_id=memory_store_id),
274 body={
275 "description": description,
276 "metadata": metadata,
277 "name": name,
278 },
279 options=make_request_options(
280 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
281 ),
282 cast_to=BetaManagedAgentsMemoryStore,
283 )
284
285 def list(
286 self,
287 *,
288 created_at_gte: Union[str, datetime] | Omit = omit,
289 created_at_lte: Union[str, datetime] | Omit = omit,
290 include_archived: bool | Omit = omit,
291 limit: int | Omit = omit,
292 page: str | Omit = omit,
293 betas: List[AnthropicBetaParam] | Omit = omit,
294 workspace_id: str | Omit = omit,
295 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
296 # The extra values given here take precedence over values defined on the client or passed to this method.
297 extra_headers: Headers | None = None,
298 extra_query: Query | None = None,
299 extra_body: Body | None = None,
300 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
301 ) -> SyncPageCursor[BetaManagedAgentsMemoryStore]:
302 """
303 List memory stores
304
305 Args:
306 created_at_gte: Return only stores whose `created_at` is at or after this time (inclusive). Sent
307 on the wire as `created_at[gte]`.
308
309 created_at_lte: Return only stores whose `created_at` is at or before this time (inclusive).
310 Sent on the wire as `created_at[lte]`.
311
312 include_archived: When `true`, archived stores are included in the results. Defaults to `false`
313 (archived stores are excluded).
314
315 limit: Maximum number of stores to return per page. Must be between 1 and 100. Defaults
316 to 20 when omitted.
317
318 page: Opaque pagination cursor (a `page_...` value). Pass the `next_page` value from a
319 previous response to fetch the next page; omit for the first page.
320
321 betas: Optional header to specify the beta version(s) you want to use.
322
323 workspace_id: Optional header to select the Workspace for this request. The value is a
324 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
325
326 Only needed for credentials that can act on more than one Workspace. A
327 credential that belongs to a specific Workspace may omit it; if sent, it must
328 match that Workspace.
329
330 extra_headers: Send extra headers
331
332 extra_query: Add additional query parameters to the request
333
334 extra_body: Add additional JSON properties to the request
335
336 timeout: Override the client-level default timeout for this request, in seconds
337 """
338 extra_headers = {
339 **strip_not_given(
340 {
341 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["agent-memory-2026-07-22"]))
342 if is_given(betas)
343 else not_given,
344 "anthropic-workspace-id": workspace_id,
345 }
346 ),
347 **(extra_headers or {}),
348 }
349 extra_headers = {"anthropic-beta": "agent-memory-2026-07-22", **(extra_headers or {})}
350 return self._get_api_list(
351 "/v1/memory_stores?beta=true",
352 page=SyncPageCursor[BetaManagedAgentsMemoryStore],
353 options=make_request_options(
354 extra_headers=extra_headers,
355 extra_query=extra_query,
356 extra_body=extra_body,
357 timeout=timeout,
358 query={
359 "created_at[gte]": created_at_gte,
360 "created_at[lte]": created_at_lte,
361 "include_archived": include_archived,
362 "limit": limit,
363 "page": page,
364 },
365 ),
366 model=BetaManagedAgentsMemoryStore,
367 )
368
369 def delete(
370 self,
371 memory_store_id: str,
372 *,
373 betas: List[AnthropicBetaParam] | Omit = omit,
374 workspace_id: str | Omit = omit,
375 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
376 # The extra values given here take precedence over values defined on the client or passed to this method.
377 extra_headers: Headers | None = None,
378 extra_query: Query | None = None,
379 extra_body: Body | None = None,
380 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
381 ) -> BetaManagedAgentsDeletedMemoryStore:
382 """
383 Delete a memory store
384
385 Args:
386 memory_store_id: ID of the memory store to permanently delete (a `memstore_...` identifier).
387 Required. Deletion cascades to all memories and memory versions in the store and
388 cannot be undone.
389
390 betas: Optional header to specify the beta version(s) you want to use.
391
392 workspace_id: Optional header to select the Workspace for this request. The value is a
393 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
394
395 Only needed for credentials that can act on more than one Workspace. A
396 credential that belongs to a specific Workspace may omit it; if sent, it must
397 match that Workspace.
398
399 extra_headers: Send extra headers
400
401 extra_query: Add additional query parameters to the request
402
403 extra_body: Add additional JSON properties to the request
404
405 timeout: Override the client-level default timeout for this request, in seconds
406 """
407 if not memory_store_id:
408 raise ValueError(f"Expected a non-empty value for `memory_store_id` but received {memory_store_id!r}")
409 extra_headers = {
410 **strip_not_given(
411 {
412 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["agent-memory-2026-07-22"]))
413 if is_given(betas)
414 else not_given,
415 "anthropic-workspace-id": workspace_id,
416 }
417 ),
418 **(extra_headers or {}),
419 }
420 extra_headers = {"anthropic-beta": "agent-memory-2026-07-22", **(extra_headers or {})}
421 return self._delete(
422 path_template("/v1/memory_stores/{memory_store_id}?beta=true", memory_store_id=memory_store_id),
423 options=make_request_options(
424 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
425 ),
426 cast_to=BetaManagedAgentsDeletedMemoryStore,
427 )
428
429 def archive(
430 self,
431 memory_store_id: str,
432 *,
433 betas: List[AnthropicBetaParam] | Omit = omit,
434 workspace_id: str | Omit = omit,
435 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
436 # The extra values given here take precedence over values defined on the client or passed to this method.
437 extra_headers: Headers | None = None,
438 extra_query: Query | None = None,
439 extra_body: Body | None = None,
440 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
441 ) -> BetaManagedAgentsMemoryStore:
442 """
443 Archive a memory store
444
445 Args:
446 memory_store_id: ID of the memory store to archive (a `memstore_...` identifier). Required.
447 Archiving is one-way and idempotent; archived stores cannot be unarchived.
448 Enumerate IDs via `GET /v1/memory_stores`.
449
450 betas: Optional header to specify the beta version(s) you want to use.
451
452 workspace_id: Optional header to select the Workspace for this request. The value is a
453 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
454
455 Only needed for credentials that can act on more than one Workspace. A
456 credential that belongs to a specific Workspace may omit it; if sent, it must
457 match that Workspace.
458
459 extra_headers: Send extra headers
460
461 extra_query: Add additional query parameters to the request
462
463 extra_body: Add additional JSON properties to the request
464
465 timeout: Override the client-level default timeout for this request, in seconds
466 """
467 if not memory_store_id:
468 raise ValueError(f"Expected a non-empty value for `memory_store_id` but received {memory_store_id!r}")
469 extra_headers = {
470 **strip_not_given(
471 {
472 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["agent-memory-2026-07-22"]))
473 if is_given(betas)
474 else not_given,
475 "anthropic-workspace-id": workspace_id,
476 }
477 ),
478 **(extra_headers or {}),
479 }
480 extra_headers = {"anthropic-beta": "agent-memory-2026-07-22", **(extra_headers or {})}
481 return self._post(
482 path_template("/v1/memory_stores/{memory_store_id}/archive?beta=true", memory_store_id=memory_store_id),
483 options=make_request_options(
484 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
485 ),
486 cast_to=BetaManagedAgentsMemoryStore,
487 )
488
489
490 class AsyncMemoryStores(AsyncAPIResource):
491 @cached_property
492 def memories(self) -> AsyncMemories:
493 return AsyncMemories(self._client)
494
495 @cached_property
496 def memory_versions(self) -> AsyncMemoryVersions:
497 return AsyncMemoryVersions(self._client)
498
499 @cached_property
500 def with_raw_response(self) -> AsyncMemoryStoresWithRawResponse:
501 """
502 This property can be used as a prefix for any HTTP method call to return
503 the raw response object instead of the parsed content.
504
505 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
506 """
507 return AsyncMemoryStoresWithRawResponse(self)
508
509 @cached_property
510 def with_streaming_response(self) -> AsyncMemoryStoresWithStreamingResponse:
511 """
512 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
513
514 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
515 """
516 return AsyncMemoryStoresWithStreamingResponse(self)
517
518 async def create(
519 self,
520 *,
521 name: str,
522 description: str | Omit = omit,
523 metadata: Dict[str, str] | Omit = omit,
524 betas: List[AnthropicBetaParam] | Omit = omit,
525 workspace_id: str | Omit = omit,
526 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
527 # The extra values given here take precedence over values defined on the client or passed to this method.
528 extra_headers: Headers | None = None,
529 extra_query: Query | None = None,
530 extra_body: Body | None = None,
531 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
532 ) -> BetaManagedAgentsMemoryStore:
533 """Create a memory store
534
535 Args:
536 name: Human-readable name for the store.
537
538 Required; 1–255 characters; no control
539 characters. The mount-path slug under `/mnt/memory/` is derived from this name
540 (lowercased, non-alphanumeric runs collapsed to a hyphen). Names need not be
541 unique within a workspace.
542
543 description: Free-text description of what the store contains, up to 1024 characters.
544 Included in the agent's system prompt when the store is attached, so word it to
545 be useful to the agent.
546
547 metadata: Arbitrary key-value tags for your own bookkeeping (such as the end user a store
548 belongs to). Up to 16 pairs; keys 1–64 characters; values up to 512 characters.
549 Not visible to the agent.
550
551 betas: Optional header to specify the beta version(s) you want to use.
552
553 workspace_id: Optional header to select the Workspace for this request. The value is a
554 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
555
556 Only needed for credentials that can act on more than one Workspace. A
557 credential that belongs to a specific Workspace may omit it; if sent, it must
558 match that Workspace.
559
560 extra_headers: Send extra headers
561
562 extra_query: Add additional query parameters to the request
563
564 extra_body: Add additional JSON properties to the request
565
566 timeout: Override the client-level default timeout for this request, in seconds
567 """
568 extra_headers = {
569 **strip_not_given(
570 {
571 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["agent-memory-2026-07-22"]))
572 if is_given(betas)
573 else not_given,
574 "anthropic-workspace-id": workspace_id,
575 }
576 ),
577 **(extra_headers or {}),
578 }
579 extra_headers = {"anthropic-beta": "agent-memory-2026-07-22", **(extra_headers or {})}
580 return await self._post(
581 "/v1/memory_stores?beta=true",
582 body={
583 "name": name,
584 "description": description,
585 "metadata": metadata,
586 },
587 options=make_request_options(
588 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
589 ),
590 cast_to=BetaManagedAgentsMemoryStore,
591 )
592
593 async def retrieve(
594 self,
595 memory_store_id: str,
596 *,
597 betas: List[AnthropicBetaParam] | Omit = omit,
598 workspace_id: str | Omit = omit,
599 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
600 # The extra values given here take precedence over values defined on the client or passed to this method.
601 extra_headers: Headers | None = None,
602 extra_query: Query | None = None,
603 extra_body: Body | None = None,
604 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
605 ) -> BetaManagedAgentsMemoryStore:
606 """
607 Retrieve a memory store
608
609 Args:
610 memory_store_id: ID of the memory store to retrieve (a `memstore_...` identifier). Required.
611 Enumerate IDs via `GET /v1/memory_stores`.
612
613 betas: Optional header to specify the beta version(s) you want to use.
614
615 workspace_id: Optional header to select the Workspace for this request. The value is a
616 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
617
618 Only needed for credentials that can act on more than one Workspace. A
619 credential that belongs to a specific Workspace may omit it; if sent, it must
620 match that Workspace.
621
622 extra_headers: Send extra headers
623
624 extra_query: Add additional query parameters to the request
625
626 extra_body: Add additional JSON properties to the request
627
628 timeout: Override the client-level default timeout for this request, in seconds
629 """
630 if not memory_store_id:
631 raise ValueError(f"Expected a non-empty value for `memory_store_id` but received {memory_store_id!r}")
632 extra_headers = {
633 **strip_not_given(
634 {
635 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["agent-memory-2026-07-22"]))
636 if is_given(betas)
637 else not_given,
638 "anthropic-workspace-id": workspace_id,
639 }
640 ),
641 **(extra_headers or {}),
642 }
643 extra_headers = {"anthropic-beta": "agent-memory-2026-07-22", **(extra_headers or {})}
644 return await self._get(
645 path_template("/v1/memory_stores/{memory_store_id}?beta=true", memory_store_id=memory_store_id),
646 options=make_request_options(
647 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
648 ),
649 cast_to=BetaManagedAgentsMemoryStore,
650 )
651
652 async def update(
653 self,
654 memory_store_id: str,
655 *,
656 description: Optional[str] | Omit = omit,
657 metadata: Optional[Dict[str, Optional[str]]] | Omit = omit,
658 name: Optional[str] | Omit = omit,
659 betas: List[AnthropicBetaParam] | Omit = omit,
660 workspace_id: str | Omit = omit,
661 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
662 # The extra values given here take precedence over values defined on the client or passed to this method.
663 extra_headers: Headers | None = None,
664 extra_query: Query | None = None,
665 extra_body: Body | None = None,
666 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
667 ) -> BetaManagedAgentsMemoryStore:
668 """
669 Update a memory store
670
671 Args:
672 memory_store_id: ID of the memory store to update (a `memstore_...` identifier). Required.
673 Enumerate IDs via `GET /v1/memory_stores`. Updating an archived store
674 returns 400.
675
676 description: New description for the store, up to 1024 characters. Pass an empty string to
677 clear it.
678
679 metadata: Metadata patch. Set a key to a string to upsert it, or to null to delete it.
680 Omit the field to preserve. The stored bag is limited to 16 keys (up to 64 chars
681 each) with values up to 512 chars.
682
683 name: New human-readable name for the store. 1–255 characters; no control characters.
684 Renaming changes the slug used for the store's `mount_path` in sessions created
685 after the update.
686
687 betas: Optional header to specify the beta version(s) you want to use.
688
689 workspace_id: Optional header to select the Workspace for this request. The value is a
690 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
691
692 Only needed for credentials that can act on more than one Workspace. A
693 credential that belongs to a specific Workspace may omit it; if sent, it must
694 match that Workspace.
695
696 extra_headers: Send extra headers
697
698 extra_query: Add additional query parameters to the request
699
700 extra_body: Add additional JSON properties to the request
701
702 timeout: Override the client-level default timeout for this request, in seconds
703 """
704 if not memory_store_id:
705 raise ValueError(f"Expected a non-empty value for `memory_store_id` but received {memory_store_id!r}")
706 extra_headers = {
707 **strip_not_given(
708 {
709 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["agent-memory-2026-07-22"]))
710 if is_given(betas)
711 else not_given,
712 "anthropic-workspace-id": workspace_id,
713 }
714 ),
715 **(extra_headers or {}),
716 }
717 extra_headers = {"anthropic-beta": "agent-memory-2026-07-22", **(extra_headers or {})}
718 return await self._post(
719 path_template("/v1/memory_stores/{memory_store_id}?beta=true", memory_store_id=memory_store_id),
720 body={
721 "description": description,
722 "metadata": metadata,
723 "name": name,
724 },
725 options=make_request_options(
726 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
727 ),
728 cast_to=BetaManagedAgentsMemoryStore,
729 )
730
731 def list(
732 self,
733 *,
734 created_at_gte: Union[str, datetime] | Omit = omit,
735 created_at_lte: Union[str, datetime] | Omit = omit,
736 include_archived: bool | Omit = omit,
737 limit: int | Omit = omit,
738 page: str | Omit = omit,
739 betas: List[AnthropicBetaParam] | Omit = omit,
740 workspace_id: str | Omit = omit,
741 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
742 # The extra values given here take precedence over values defined on the client or passed to this method.
743 extra_headers: Headers | None = None,
744 extra_query: Query | None = None,
745 extra_body: Body | None = None,
746 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
747 ) -> AsyncPaginator[BetaManagedAgentsMemoryStore, AsyncPageCursor[BetaManagedAgentsMemoryStore]]:
748 """
749 List memory stores
750
751 Args:
752 created_at_gte: Return only stores whose `created_at` is at or after this time (inclusive). Sent
753 on the wire as `created_at[gte]`.
754
755 created_at_lte: Return only stores whose `created_at` is at or before this time (inclusive).
756 Sent on the wire as `created_at[lte]`.
757
758 include_archived: When `true`, archived stores are included in the results. Defaults to `false`
759 (archived stores are excluded).
760
761 limit: Maximum number of stores to return per page. Must be between 1 and 100. Defaults
762 to 20 when omitted.
763
764 page: Opaque pagination cursor (a `page_...` value). Pass the `next_page` value from a
765 previous response to fetch the next page; omit for the first page.
766
767 betas: Optional header to specify the beta version(s) you want to use.
768
769 workspace_id: Optional header to select the Workspace for this request. The value is a
770 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
771
772 Only needed for credentials that can act on more than one Workspace. A
773 credential that belongs to a specific Workspace may omit it; if sent, it must
774 match that Workspace.
775
776 extra_headers: Send extra headers
777
778 extra_query: Add additional query parameters to the request
779
780 extra_body: Add additional JSON properties to the request
781
782 timeout: Override the client-level default timeout for this request, in seconds
783 """
784 extra_headers = {
785 **strip_not_given(
786 {
787 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["agent-memory-2026-07-22"]))
788 if is_given(betas)
789 else not_given,
790 "anthropic-workspace-id": workspace_id,
791 }
792 ),
793 **(extra_headers or {}),
794 }
795 extra_headers = {"anthropic-beta": "agent-memory-2026-07-22", **(extra_headers or {})}
796 return self._get_api_list(
797 "/v1/memory_stores?beta=true",
798 page=AsyncPageCursor[BetaManagedAgentsMemoryStore],
799 options=make_request_options(
800 extra_headers=extra_headers,
801 extra_query=extra_query,
802 extra_body=extra_body,
803 timeout=timeout,
804 query={
805 "created_at[gte]": created_at_gte,
806 "created_at[lte]": created_at_lte,
807 "include_archived": include_archived,
808 "limit": limit,
809 "page": page,
810 },
811 ),
812 model=BetaManagedAgentsMemoryStore,
813 )
814
815 async def delete(
816 self,
817 memory_store_id: str,
818 *,
819 betas: List[AnthropicBetaParam] | Omit = omit,
820 workspace_id: str | Omit = omit,
821 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
822 # The extra values given here take precedence over values defined on the client or passed to this method.
823 extra_headers: Headers | None = None,
824 extra_query: Query | None = None,
825 extra_body: Body | None = None,
826 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
827 ) -> BetaManagedAgentsDeletedMemoryStore:
828 """
829 Delete a memory store
830
831 Args:
832 memory_store_id: ID of the memory store to permanently delete (a `memstore_...` identifier).
833 Required. Deletion cascades to all memories and memory versions in the store and
834 cannot be undone.
835
836 betas: Optional header to specify the beta version(s) you want to use.
837
838 workspace_id: Optional header to select the Workspace for this request. The value is a
839 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
840
841 Only needed for credentials that can act on more than one Workspace. A
842 credential that belongs to a specific Workspace may omit it; if sent, it must
843 match that Workspace.
844
845 extra_headers: Send extra headers
846
847 extra_query: Add additional query parameters to the request
848
849 extra_body: Add additional JSON properties to the request
850
851 timeout: Override the client-level default timeout for this request, in seconds
852 """
853 if not memory_store_id:
854 raise ValueError(f"Expected a non-empty value for `memory_store_id` but received {memory_store_id!r}")
855 extra_headers = {
856 **strip_not_given(
857 {
858 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["agent-memory-2026-07-22"]))
859 if is_given(betas)
860 else not_given,
861 "anthropic-workspace-id": workspace_id,
862 }
863 ),
864 **(extra_headers or {}),
865 }
866 extra_headers = {"anthropic-beta": "agent-memory-2026-07-22", **(extra_headers or {})}
867 return await self._delete(
868 path_template("/v1/memory_stores/{memory_store_id}?beta=true", memory_store_id=memory_store_id),
869 options=make_request_options(
870 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
871 ),
872 cast_to=BetaManagedAgentsDeletedMemoryStore,
873 )
874
875 async def archive(
876 self,
877 memory_store_id: str,
878 *,
879 betas: List[AnthropicBetaParam] | Omit = omit,
880 workspace_id: str | Omit = omit,
881 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
882 # The extra values given here take precedence over values defined on the client or passed to this method.
883 extra_headers: Headers | None = None,
884 extra_query: Query | None = None,
885 extra_body: Body | None = None,
886 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
887 ) -> BetaManagedAgentsMemoryStore:
888 """
889 Archive a memory store
890
891 Args:
892 memory_store_id: ID of the memory store to archive (a `memstore_...` identifier). Required.
893 Archiving is one-way and idempotent; archived stores cannot be unarchived.
894 Enumerate IDs via `GET /v1/memory_stores`.
895
896 betas: Optional header to specify the beta version(s) you want to use.
897
898 workspace_id: Optional header to select the Workspace for this request. The value is a
899 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
900
901 Only needed for credentials that can act on more than one Workspace. A
902 credential that belongs to a specific Workspace may omit it; if sent, it must
903 match that Workspace.
904
905 extra_headers: Send extra headers
906
907 extra_query: Add additional query parameters to the request
908
909 extra_body: Add additional JSON properties to the request
910
911 timeout: Override the client-level default timeout for this request, in seconds
912 """
913 if not memory_store_id:
914 raise ValueError(f"Expected a non-empty value for `memory_store_id` but received {memory_store_id!r}")
915 extra_headers = {
916 **strip_not_given(
917 {
918 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["agent-memory-2026-07-22"]))
919 if is_given(betas)
920 else not_given,
921 "anthropic-workspace-id": workspace_id,
922 }
923 ),
924 **(extra_headers or {}),
925 }
926 extra_headers = {"anthropic-beta": "agent-memory-2026-07-22", **(extra_headers or {})}
927 return await self._post(
928 path_template("/v1/memory_stores/{memory_store_id}/archive?beta=true", memory_store_id=memory_store_id),
929 options=make_request_options(
930 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
931 ),
932 cast_to=BetaManagedAgentsMemoryStore,
933 )
934
935
936 class MemoryStoresWithRawResponse:
937 def __init__(self, memory_stores: MemoryStores) -> None:
938 self._memory_stores = memory_stores
939
940 self.create = to_raw_response_wrapper(
941 memory_stores.create,
942 )
943 self.retrieve = to_raw_response_wrapper(
944 memory_stores.retrieve,
945 )
946 self.update = to_raw_response_wrapper(
947 memory_stores.update,
948 )
949 self.list = to_raw_response_wrapper(
950 memory_stores.list,
951 )
952 self.delete = to_raw_response_wrapper(
953 memory_stores.delete,
954 )
955 self.archive = to_raw_response_wrapper(
956 memory_stores.archive,
957 )
958
959 @cached_property
960 def memories(self) -> MemoriesWithRawResponse:
961 return MemoriesWithRawResponse(self._memory_stores.memories)
962
963 @cached_property
964 def memory_versions(self) -> MemoryVersionsWithRawResponse:
965 return MemoryVersionsWithRawResponse(self._memory_stores.memory_versions)
966
967
968 class AsyncMemoryStoresWithRawResponse:
969 def __init__(self, memory_stores: AsyncMemoryStores) -> None:
970 self._memory_stores = memory_stores
971
972 self.create = async_to_raw_response_wrapper(
973 memory_stores.create,
974 )
975 self.retrieve = async_to_raw_response_wrapper(
976 memory_stores.retrieve,
977 )
978 self.update = async_to_raw_response_wrapper(
979 memory_stores.update,
980 )
981 self.list = async_to_raw_response_wrapper(
982 memory_stores.list,
983 )
984 self.delete = async_to_raw_response_wrapper(
985 memory_stores.delete,
986 )
987 self.archive = async_to_raw_response_wrapper(
988 memory_stores.archive,
989 )
990
991 @cached_property
992 def memories(self) -> AsyncMemoriesWithRawResponse:
993 return AsyncMemoriesWithRawResponse(self._memory_stores.memories)
994
995 @cached_property
996 def memory_versions(self) -> AsyncMemoryVersionsWithRawResponse:
997 return AsyncMemoryVersionsWithRawResponse(self._memory_stores.memory_versions)
998
999
1000 class MemoryStoresWithStreamingResponse:
1001 def __init__(self, memory_stores: MemoryStores) -> None:
1002 self._memory_stores = memory_stores
1003
1004 self.create = to_streamed_response_wrapper(
1005 memory_stores.create,
1006 )
1007 self.retrieve = to_streamed_response_wrapper(
1008 memory_stores.retrieve,
1009 )
1010 self.update = to_streamed_response_wrapper(
1011 memory_stores.update,
1012 )
1013 self.list = to_streamed_response_wrapper(
1014 memory_stores.list,
1015 )
1016 self.delete = to_streamed_response_wrapper(
1017 memory_stores.delete,
1018 )
1019 self.archive = to_streamed_response_wrapper(
1020 memory_stores.archive,
1021 )
1022
1023 @cached_property
1024 def memories(self) -> MemoriesWithStreamingResponse:
1025 return MemoriesWithStreamingResponse(self._memory_stores.memories)
1026
1027 @cached_property
1028 def memory_versions(self) -> MemoryVersionsWithStreamingResponse:
1029 return MemoryVersionsWithStreamingResponse(self._memory_stores.memory_versions)
1030
1031
1032 class AsyncMemoryStoresWithStreamingResponse:
1033 def __init__(self, memory_stores: AsyncMemoryStores) -> None:
1034 self._memory_stores = memory_stores
1035
1036 self.create = async_to_streamed_response_wrapper(
1037 memory_stores.create,
1038 )
1039 self.retrieve = async_to_streamed_response_wrapper(
1040 memory_stores.retrieve,
1041 )
1042 self.update = async_to_streamed_response_wrapper(
1043 memory_stores.update,
1044 )
1045 self.list = async_to_streamed_response_wrapper(
1046 memory_stores.list,
1047 )
1048 self.delete = async_to_streamed_response_wrapper(
1049 memory_stores.delete,
1050 )
1051 self.archive = async_to_streamed_response_wrapper(
1052 memory_stores.archive,
1053 )
1054
1055 @cached_property
1056 def memories(self) -> AsyncMemoriesWithStreamingResponse:
1057 return AsyncMemoriesWithStreamingResponse(self._memory_stores.memories)
1058
1059 @cached_property
1060 def memory_versions(self) -> AsyncMemoryVersionsWithStreamingResponse:
1061 return AsyncMemoryVersionsWithStreamingResponse(self._memory_stores.memory_versions)