Debian Codegraph @

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

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