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: Optimistic-concurrency precondition: the update applies only if the memory's
258 stored `content_sha256` equals the supplied value. On mismatch, the request
259 returns `memory_precondition_failed_error` (HTTP 409); re-read the memory and
260 retry against the fresh state. If the precondition fails but the stored state
261 already exactly matches the requested `content` and `path`, the server returns
262 200 instead of 409.
263
264 betas: Optional header to specify the beta version(s) you want to use.
265
266 workspace_id: Optional header to select the Workspace for this request. The value is a
267 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
268
269 Only needed for credentials that can act on more than one Workspace. A
270 credential that belongs to a specific Workspace may omit it; if sent, it must
271 match that Workspace.
272
273 extra_headers: Send extra headers
274
275 extra_query: Add additional query parameters to the request
276
277 extra_body: Add additional JSON properties to the request
278
279 timeout: Override the client-level default timeout for this request, in seconds
280 """
281 if not memory_store_id:
282 raise ValueError(f"Expected a non-empty value for `memory_store_id` but received {memory_store_id!r}")
283 if not memory_id:
284 raise ValueError(f"Expected a non-empty value for `memory_id` but received {memory_id!r}")
285 extra_headers = {
286 **strip_not_given(
287 {
288 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["agent-memory-2026-07-22"]))
289 if is_given(betas)
290 else not_given,
291 "anthropic-workspace-id": workspace_id,
292 }
293 ),
294 **(extra_headers or {}),
295 }
296 extra_headers = {"anthropic-beta": "agent-memory-2026-07-22", **(extra_headers or {})}
297 return self._post(
298 path_template(
299 "/v1/memory_stores/{memory_store_id}/memories/{memory_id}?beta=true",
300 memory_store_id=memory_store_id,
301 memory_id=memory_id,
302 ),
303 body={
304 "content": content,
305 "path": path,
306 "precondition": precondition,
307 },
308 options=make_request_options(
309 extra_headers=extra_headers,
310 extra_query=extra_query,
311 extra_body=extra_body,
312 timeout=timeout,
313 query={"view": view},
314 ),
315 cast_to=BetaManagedAgentsMemory,
316 )
317
318 def list(
319 self,
320 memory_store_id: str,
321 *,
322 depth: int | Omit = omit,
323 limit: int | Omit = omit,
324 page: str | Omit = omit,
325 path_prefix: str | Omit = omit,
326 view: BetaManagedAgentsMemoryView | Omit = omit,
327 betas: List[AnthropicBetaParam] | Omit = omit,
328 workspace_id: str | Omit = omit,
329 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
330 # The extra values given here take precedence over values defined on the client or passed to this method.
331 extra_headers: Headers | None = None,
332 extra_query: Query | None = None,
333 extra_body: Body | None = None,
334 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
335 ) -> SyncPageCursor[BetaManagedAgentsMemoryListItem]:
336 """
337 List memories
338
339 Args:
340 memory_store_id: The ID of the memory store to list memories from (`memstore_...`).
341
342 depth: `0` (or omitted) returns all descendants below `path_prefix` (recursive). `1`
343 returns immediate children only; deeper entries roll up as `memory_prefix`
344 items. `depth=1` behaves like `ls`; omitting `depth` behaves like `find`.
345
346 limit: Maximum number of items to return per page. Must be between 1 and 100. Defaults
347 to 20 when omitted. Capped at 20 when `view=full`. Both `memory` and
348 `memory_prefix` items count toward the limit.
349
350 page: Opaque pagination cursor (a `page_...` value). Pass the `next_page` value from a
351 previous response to fetch the next page; omit for the first page.
352
353 path_prefix: Optional path prefix filter. Must end with `/` (segment-aligned), e.g.,
354 `/notes/`. This value appears in request URLs. Do not include secrets or
355 personally identifiable information.
356
357 view: Which projection of each `memory` to return. Defaults to `basic` (content
358 omitted). `full` populates `content` on each item and caps `limit` at 20; use
359 this as the bulk-read path for export and sync.
360
361 betas: Optional header to specify the beta version(s) you want to use.
362
363 workspace_id: Optional header to select the Workspace for this request. The value is a
364 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
365
366 Only needed for credentials that can act on more than one Workspace. A
367 credential that belongs to a specific Workspace may omit it; if sent, it must
368 match that Workspace.
369
370 extra_headers: Send extra headers
371
372 extra_query: Add additional query parameters to the request
373
374 extra_body: Add additional JSON properties to the request
375
376 timeout: Override the client-level default timeout for this request, in seconds
377 """
378 if not memory_store_id:
379 raise ValueError(f"Expected a non-empty value for `memory_store_id` but received {memory_store_id!r}")
380 extra_headers = {
381 **strip_not_given(
382 {
383 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["agent-memory-2026-07-22"]))
384 if is_given(betas)
385 else not_given,
386 "anthropic-workspace-id": workspace_id,
387 }
388 ),
389 **(extra_headers or {}),
390 }
391 extra_headers = {"anthropic-beta": "agent-memory-2026-07-22", **(extra_headers or {})}
392 return self._get_api_list(
393 path_template("/v1/memory_stores/{memory_store_id}/memories?beta=true", memory_store_id=memory_store_id),
394 page=SyncPageCursor[BetaManagedAgentsMemoryListItem],
395 options=make_request_options(
396 extra_headers=extra_headers,
397 extra_query=extra_query,
398 extra_body=extra_body,
399 timeout=timeout,
400 query={
401 "depth": depth,
402 "limit": limit,
403 "page": page,
404 "path_prefix": path_prefix,
405 "view": view,
406 },
407 ),
408 model=cast(
409 Any, BetaManagedAgentsMemoryListItem
410 ), # Union types cannot be passed in as arguments in the type system
411 )
412
413 def delete(
414 self,
415 memory_id: str,
416 *,
417 memory_store_id: str,
418 expected_content_sha256: str | Omit = omit,
419 betas: List[AnthropicBetaParam] | Omit = omit,
420 workspace_id: str | Omit = omit,
421 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
422 # The extra values given here take precedence over values defined on the client or passed to this method.
423 extra_headers: Headers | None = None,
424 extra_query: Query | None = None,
425 extra_body: Body | None = None,
426 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
427 ) -> BetaManagedAgentsDeletedMemory:
428 """
429 Delete a memory
430
431 Args:
432 memory_store_id: The ID of the memory store that holds the memory (`memstore_...`).
433
434 memory_id: The ID of the memory to delete (`mem_...`).
435
436 expected_content_sha256: Delete the memory only if its current `content_sha256` equals this value, given
437 as 64 lowercase hexadecimal characters. Omit it to delete unconditionally.
438
439 If the hashes differ, the request fails with HTTP status 409 and nothing is
440 deleted.
441
442 betas: Optional header to specify the beta version(s) you want to use.
443
444 workspace_id: Optional header to select the Workspace for this request. The value is a
445 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
446
447 Only needed for credentials that can act on more than one Workspace. A
448 credential that belongs to a specific Workspace may omit it; if sent, it must
449 match that Workspace.
450
451 extra_headers: Send extra headers
452
453 extra_query: Add additional query parameters to the request
454
455 extra_body: Add additional JSON properties to the request
456
457 timeout: Override the client-level default timeout for this request, in seconds
458 """
459 if not memory_store_id:
460 raise ValueError(f"Expected a non-empty value for `memory_store_id` but received {memory_store_id!r}")
461 if not memory_id:
462 raise ValueError(f"Expected a non-empty value for `memory_id` but received {memory_id!r}")
463 extra_headers = {
464 **strip_not_given(
465 {
466 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["agent-memory-2026-07-22"]))
467 if is_given(betas)
468 else not_given,
469 "anthropic-workspace-id": workspace_id,
470 }
471 ),
472 **(extra_headers or {}),
473 }
474 extra_headers = {"anthropic-beta": "agent-memory-2026-07-22", **(extra_headers or {})}
475 return self._delete(
476 path_template(
477 "/v1/memory_stores/{memory_store_id}/memories/{memory_id}?beta=true",
478 memory_store_id=memory_store_id,
479 memory_id=memory_id,
480 ),
481 options=make_request_options(
482 extra_headers=extra_headers,
483 extra_query=extra_query,
484 extra_body=extra_body,
485 timeout=timeout,
486 query={"expected_content_sha256": expected_content_sha256},
487 ),
488 cast_to=BetaManagedAgentsDeletedMemory,
489 )
490
491
492 class AsyncMemories(AsyncAPIResource):
493 @cached_property
494 def with_raw_response(self) -> AsyncMemoriesWithRawResponse:
495 """
496 This property can be used as a prefix for any HTTP method call to return
497 the raw response object instead of the parsed content.
498
499 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
500 """
501 return AsyncMemoriesWithRawResponse(self)
502
503 @cached_property
504 def with_streaming_response(self) -> AsyncMemoriesWithStreamingResponse:
505 """
506 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
507
508 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
509 """
510 return AsyncMemoriesWithStreamingResponse(self)
511
512 async def create(
513 self,
514 memory_store_id: str,
515 *,
516 content: Optional[str],
517 path: str,
518 view: BetaManagedAgentsMemoryView | Omit = omit,
519 betas: List[AnthropicBetaParam] | Omit = omit,
520 workspace_id: str | Omit = omit,
521 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
522 # The extra values given here take precedence over values defined on the client or passed to this method.
523 extra_headers: Headers | None = None,
524 extra_query: Query | None = None,
525 extra_body: Body | None = None,
526 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
527 ) -> BetaManagedAgentsMemory:
528 """
529 Create a memory
530
531 Args:
532 memory_store_id: The ID of the memory store to create the memory in (`memstore_...`).
533
534 content: UTF-8 text content for the new memory. Maximum 100 kB (102,400 bytes). Required;
535 pass `""` explicitly to create an empty memory.
536
537 path: Hierarchical path for the new memory, e.g. `/projects/foo/notes.md`. Must start
538 with `/`, contain at least one non-empty segment, and be at most 1,024 bytes.
539 Must not contain empty segments, `.` or `..` segments, control or format
540 characters, or the Unicode line and paragraph separators (U+2028, U+2029), and
541 must be NFC-normalized. Paths are case-sensitive.
542
543 view: Selects which projection of a `memory` or `memory_version` the server returns.
544 `basic` returns the object with `content` set to `null`; `full` populates
545 `content`. When omitted, the default is endpoint-specific: retrieve operations
546 default to `full`; list, create, and update operations default to `basic`.
547 Listing with `view=full` caps `limit` at 20.
548
549 betas: Optional header to specify the beta version(s) you want to use.
550
551 workspace_id: Optional header to select the Workspace for this request. The value is a
552 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
553
554 Only needed for credentials that can act on more than one Workspace. A
555 credential that belongs to a specific Workspace may omit it; if sent, it must
556 match that Workspace.
557
558 extra_headers: Send extra headers
559
560 extra_query: Add additional query parameters to the request
561
562 extra_body: Add additional JSON properties to the request
563
564 timeout: Override the client-level default timeout for this request, in seconds
565 """
566 if not memory_store_id:
567 raise ValueError(f"Expected a non-empty value for `memory_store_id` but received {memory_store_id!r}")
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 path_template("/v1/memory_stores/{memory_store_id}/memories?beta=true", memory_store_id=memory_store_id),
582 body={
583 "content": content,
584 "path": path,
585 },
586 options=make_request_options(
587 extra_headers=extra_headers,
588 extra_query=extra_query,
589 extra_body=extra_body,
590 timeout=timeout,
591 query={"view": view},
592 ),
593 cast_to=BetaManagedAgentsMemory,
594 )
595
596 async def retrieve(
597 self,
598 memory_id: str,
599 *,
600 memory_store_id: str,
601 view: BetaManagedAgentsMemoryView | Omit = omit,
602 betas: List[AnthropicBetaParam] | Omit = omit,
603 workspace_id: str | Omit = omit,
604 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
605 # The extra values given here take precedence over values defined on the client or passed to this method.
606 extra_headers: Headers | None = None,
607 extra_query: Query | None = None,
608 extra_body: Body | None = None,
609 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
610 ) -> BetaManagedAgentsMemory:
611 """
612 Retrieve a memory
613
614 Args:
615 memory_store_id: The ID of the memory store that holds the memory (`memstore_...`).
616
617 memory_id: The ID of the memory to retrieve (`mem_...`).
618
619 view: Selects which projection of a `memory` or `memory_version` the server returns.
620 `basic` returns the object with `content` set to `null`; `full` populates
621 `content`. When omitted, the default is endpoint-specific: retrieve operations
622 default to `full`; list, create, and update operations default to `basic`.
623 Listing with `view=full` caps `limit` at 20.
624
625 betas: Optional header to specify the beta version(s) you want to use.
626
627 workspace_id: Optional header to select the Workspace for this request. The value is a
628 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
629
630 Only needed for credentials that can act on more than one Workspace. A
631 credential that belongs to a specific Workspace may omit it; if sent, it must
632 match that Workspace.
633
634 extra_headers: Send extra headers
635
636 extra_query: Add additional query parameters to the request
637
638 extra_body: Add additional JSON properties to the request
639
640 timeout: Override the client-level default timeout for this request, in seconds
641 """
642 if not memory_store_id:
643 raise ValueError(f"Expected a non-empty value for `memory_store_id` but received {memory_store_id!r}")
644 if not memory_id:
645 raise ValueError(f"Expected a non-empty value for `memory_id` but received {memory_id!r}")
646 extra_headers = {
647 **strip_not_given(
648 {
649 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["agent-memory-2026-07-22"]))
650 if is_given(betas)
651 else not_given,
652 "anthropic-workspace-id": workspace_id,
653 }
654 ),
655 **(extra_headers or {}),
656 }
657 extra_headers = {"anthropic-beta": "agent-memory-2026-07-22", **(extra_headers or {})}
658 return await self._get(
659 path_template(
660 "/v1/memory_stores/{memory_store_id}/memories/{memory_id}?beta=true",
661 memory_store_id=memory_store_id,
662 memory_id=memory_id,
663 ),
664 options=make_request_options(
665 extra_headers=extra_headers,
666 extra_query=extra_query,
667 extra_body=extra_body,
668 timeout=timeout,
669 query={"view": view},
670 ),
671 cast_to=BetaManagedAgentsMemory,
672 )
673
674 async def update(
675 self,
676 memory_id: str,
677 *,
678 memory_store_id: str,
679 view: BetaManagedAgentsMemoryView | Omit = omit,
680 content: Optional[str] | Omit = omit,
681 path: Optional[str] | Omit = omit,
682 precondition: BetaManagedAgentsPreconditionParam | Omit = omit,
683 betas: List[AnthropicBetaParam] | Omit = omit,
684 workspace_id: str | Omit = omit,
685 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
686 # The extra values given here take precedence over values defined on the client or passed to this method.
687 extra_headers: Headers | None = None,
688 extra_query: Query | None = None,
689 extra_body: Body | None = None,
690 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
691 ) -> BetaManagedAgentsMemory:
692 """
693 Update a memory
694
695 Args:
696 memory_store_id: The ID of the memory store that holds the memory (`memstore_...`).
697
698 memory_id: The ID of the memory to update (`mem_...`).
699
700 view: Selects which projection of a `memory` or `memory_version` the server returns.
701 `basic` returns the object with `content` set to `null`; `full` populates
702 `content`. When omitted, the default is endpoint-specific: retrieve operations
703 default to `full`; list, create, and update operations default to `basic`.
704 Listing with `view=full` caps `limit` at 20.
705
706 content: New UTF-8 text content for the memory. Maximum 100 kB (102,400 bytes). Omit to
707 leave the content unchanged (e.g., for a rename-only update).
708
709 path: New path for the memory (a rename). Must start with `/`, contain at least one
710 non-empty segment, and be at most 1,024 bytes. Must not contain empty segments,
711 `.` or `..` segments, control or format characters, or the Unicode line and
712 paragraph separators (U+2028, U+2029), and must be NFC-normalized. Paths are
713 case-sensitive. The memory's `id` is preserved across renames. Omit to leave the
714 path unchanged.
715
716 precondition: Optimistic-concurrency precondition: the update applies only if the memory's
717 stored `content_sha256` equals the supplied value. On mismatch, the request
718 returns `memory_precondition_failed_error` (HTTP 409); re-read the memory and
719 retry against the fresh state. If the precondition fails but the stored state
720 already exactly matches the requested `content` and `path`, the server returns
721 200 instead of 409.
722
723 betas: Optional header to specify the beta version(s) you want to use.
724
725 workspace_id: Optional header to select the Workspace for this request. The value is a
726 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
727
728 Only needed for credentials that can act on more than one Workspace. A
729 credential that belongs to a specific Workspace may omit it; if sent, it must
730 match that Workspace.
731
732 extra_headers: Send extra headers
733
734 extra_query: Add additional query parameters to the request
735
736 extra_body: Add additional JSON properties to the request
737
738 timeout: Override the client-level default timeout for this request, in seconds
739 """
740 if not memory_store_id:
741 raise ValueError(f"Expected a non-empty value for `memory_store_id` but received {memory_store_id!r}")
742 if not memory_id:
743 raise ValueError(f"Expected a non-empty value for `memory_id` but received {memory_id!r}")
744 extra_headers = {
745 **strip_not_given(
746 {
747 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["agent-memory-2026-07-22"]))
748 if is_given(betas)
749 else not_given,
750 "anthropic-workspace-id": workspace_id,
751 }
752 ),
753 **(extra_headers or {}),
754 }
755 extra_headers = {"anthropic-beta": "agent-memory-2026-07-22", **(extra_headers or {})}
756 return await self._post(
757 path_template(
758 "/v1/memory_stores/{memory_store_id}/memories/{memory_id}?beta=true",
759 memory_store_id=memory_store_id,
760 memory_id=memory_id,
761 ),
762 body={
763 "content": content,
764 "path": path,
765 "precondition": precondition,
766 },
767 options=make_request_options(
768 extra_headers=extra_headers,
769 extra_query=extra_query,
770 extra_body=extra_body,
771 timeout=timeout,
772 query={"view": view},
773 ),
774 cast_to=BetaManagedAgentsMemory,
775 )
776
777 def list(
778 self,
779 memory_store_id: str,
780 *,
781 depth: int | Omit = omit,
782 limit: int | Omit = omit,
783 page: str | Omit = omit,
784 path_prefix: str | Omit = omit,
785 view: BetaManagedAgentsMemoryView | Omit = omit,
786 betas: List[AnthropicBetaParam] | Omit = omit,
787 workspace_id: str | Omit = omit,
788 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
789 # The extra values given here take precedence over values defined on the client or passed to this method.
790 extra_headers: Headers | None = None,
791 extra_query: Query | None = None,
792 extra_body: Body | None = None,
793 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
794 ) -> AsyncPaginator[BetaManagedAgentsMemoryListItem, AsyncPageCursor[BetaManagedAgentsMemoryListItem]]:
795 """
796 List memories
797
798 Args:
799 memory_store_id: The ID of the memory store to list memories from (`memstore_...`).
800
801 depth: `0` (or omitted) returns all descendants below `path_prefix` (recursive). `1`
802 returns immediate children only; deeper entries roll up as `memory_prefix`
803 items. `depth=1` behaves like `ls`; omitting `depth` behaves like `find`.
804
805 limit: Maximum number of items to return per page. Must be between 1 and 100. Defaults
806 to 20 when omitted. Capped at 20 when `view=full`. Both `memory` and
807 `memory_prefix` items count toward the limit.
808
809 page: Opaque pagination cursor (a `page_...` value). Pass the `next_page` value from a
810 previous response to fetch the next page; omit for the first page.
811
812 path_prefix: Optional path prefix filter. Must end with `/` (segment-aligned), e.g.,
813 `/notes/`. This value appears in request URLs. Do not include secrets or
814 personally identifiable information.
815
816 view: Which projection of each `memory` to return. Defaults to `basic` (content
817 omitted). `full` populates `content` on each item and caps `limit` at 20; use
818 this as the bulk-read path for export and sync.
819
820 betas: Optional header to specify the beta version(s) you want to use.
821
822 workspace_id: Optional header to select the Workspace for this request. The value is a
823 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
824
825 Only needed for credentials that can act on more than one Workspace. A
826 credential that belongs to a specific Workspace may omit it; if sent, it must
827 match that Workspace.
828
829 extra_headers: Send extra headers
830
831 extra_query: Add additional query parameters to the request
832
833 extra_body: Add additional JSON properties to the request
834
835 timeout: Override the client-level default timeout for this request, in seconds
836 """
837 if not memory_store_id:
838 raise ValueError(f"Expected a non-empty value for `memory_store_id` but received {memory_store_id!r}")
839 extra_headers = {
840 **strip_not_given(
841 {
842 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["agent-memory-2026-07-22"]))
843 if is_given(betas)
844 else not_given,
845 "anthropic-workspace-id": workspace_id,
846 }
847 ),
848 **(extra_headers or {}),
849 }
850 extra_headers = {"anthropic-beta": "agent-memory-2026-07-22", **(extra_headers or {})}
851 return self._get_api_list(
852 path_template("/v1/memory_stores/{memory_store_id}/memories?beta=true", memory_store_id=memory_store_id),
853 page=AsyncPageCursor[BetaManagedAgentsMemoryListItem],
854 options=make_request_options(
855 extra_headers=extra_headers,
856 extra_query=extra_query,
857 extra_body=extra_body,
858 timeout=timeout,
859 query={
860 "depth": depth,
861 "limit": limit,
862 "page": page,
863 "path_prefix": path_prefix,
864 "view": view,
865 },
866 ),
867 model=cast(
868 Any, BetaManagedAgentsMemoryListItem
869 ), # Union types cannot be passed in as arguments in the type system
870 )
871
872 async def delete(
873 self,
874 memory_id: str,
875 *,
876 memory_store_id: str,
877 expected_content_sha256: str | Omit = omit,
878 betas: List[AnthropicBetaParam] | Omit = omit,
879 workspace_id: str | Omit = omit,
880 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
881 # The extra values given here take precedence over values defined on the client or passed to this method.
882 extra_headers: Headers | None = None,
883 extra_query: Query | None = None,
884 extra_body: Body | None = None,
885 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
886 ) -> BetaManagedAgentsDeletedMemory:
887 """
888 Delete a memory
889
890 Args:
891 memory_store_id: The ID of the memory store that holds the memory (`memstore_...`).
892
893 memory_id: The ID of the memory to delete (`mem_...`).
894
895 expected_content_sha256: Delete the memory only if its current `content_sha256` equals this value, given
896 as 64 lowercase hexadecimal characters. Omit it to delete unconditionally.
897
898 If the hashes differ, the request fails with HTTP status 409 and nothing is
899 deleted.
900
901 betas: Optional header to specify the beta version(s) you want to use.
902
903 workspace_id: Optional header to select the Workspace for this request. The value is a
904 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
905
906 Only needed for credentials that can act on more than one Workspace. A
907 credential that belongs to a specific Workspace may omit it; if sent, it must
908 match that Workspace.
909
910 extra_headers: Send extra headers
911
912 extra_query: Add additional query parameters to the request
913
914 extra_body: Add additional JSON properties to the request
915
916 timeout: Override the client-level default timeout for this request, in seconds
917 """
918 if not memory_store_id:
919 raise ValueError(f"Expected a non-empty value for `memory_store_id` but received {memory_store_id!r}")
920 if not memory_id:
921 raise ValueError(f"Expected a non-empty value for `memory_id` but received {memory_id!r}")
922 extra_headers = {
923 **strip_not_given(
924 {
925 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["agent-memory-2026-07-22"]))
926 if is_given(betas)
927 else not_given,
928 "anthropic-workspace-id": workspace_id,
929 }
930 ),
931 **(extra_headers or {}),
932 }
933 extra_headers = {"anthropic-beta": "agent-memory-2026-07-22", **(extra_headers or {})}
934 return await self._delete(
935 path_template(
936 "/v1/memory_stores/{memory_store_id}/memories/{memory_id}?beta=true",
937 memory_store_id=memory_store_id,
938 memory_id=memory_id,
939 ),
940 options=make_request_options(
941 extra_headers=extra_headers,
942 extra_query=extra_query,
943 extra_body=extra_body,
944 timeout=timeout,
945 query={"expected_content_sha256": expected_content_sha256},
946 ),
947 cast_to=BetaManagedAgentsDeletedMemory,
948 )
949
950
951 class MemoriesWithRawResponse:
952 def __init__(self, memories: Memories) -> None:
953 self._memories = memories
954
955 self.create = to_raw_response_wrapper(
956 memories.create,
957 )
958 self.retrieve = to_raw_response_wrapper(
959 memories.retrieve,
960 )
961 self.update = to_raw_response_wrapper(
962 memories.update,
963 )
964 self.list = to_raw_response_wrapper(
965 memories.list,
966 )
967 self.delete = to_raw_response_wrapper(
968 memories.delete,
969 )
970
971
972 class AsyncMemoriesWithRawResponse:
973 def __init__(self, memories: AsyncMemories) -> None:
974 self._memories = memories
975
976 self.create = async_to_raw_response_wrapper(
977 memories.create,
978 )
979 self.retrieve = async_to_raw_response_wrapper(
980 memories.retrieve,
981 )
982 self.update = async_to_raw_response_wrapper(
983 memories.update,
984 )
985 self.list = async_to_raw_response_wrapper(
986 memories.list,
987 )
988 self.delete = async_to_raw_response_wrapper(
989 memories.delete,
990 )
991
992
993 class MemoriesWithStreamingResponse:
994 def __init__(self, memories: Memories) -> None:
995 self._memories = memories
996
997 self.create = to_streamed_response_wrapper(
998 memories.create,
999 )
1000 self.retrieve = to_streamed_response_wrapper(
1001 memories.retrieve,
1002 )
1003 self.update = to_streamed_response_wrapper(
1004 memories.update,
1005 )
1006 self.list = to_streamed_response_wrapper(
1007 memories.list,
1008 )
1009 self.delete = to_streamed_response_wrapper(
1010 memories.delete,
1011 )
1012
1013
1014 class AsyncMemoriesWithStreamingResponse:
1015 def __init__(self, memories: AsyncMemories) -> None:
1016 self._memories = memories
1017
1018 self.create = async_to_streamed_response_wrapper(
1019 memories.create,
1020 )
1021 self.retrieve = async_to_streamed_response_wrapper(
1022 memories.retrieve,
1023 )
1024 self.update = async_to_streamed_response_wrapper(
1025 memories.update,
1026 )
1027 self.list = async_to_streamed_response_wrapper(
1028 memories.list,
1029 )
1030 self.delete = async_to_streamed_response_wrapper(
1031 memories.delete,
1032 )