letta-client 0.1.42__py3-none-any.whl → 0.1.43__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of letta-client might be problematic. Click here for more details.

@@ -0,0 +1,753 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+ from ...core.client_wrapper import SyncClientWrapper
5
+ from ...core.request_options import RequestOptions
6
+ from ...types.block import Block
7
+ from ...core.jsonable_encoder import jsonable_encoder
8
+ from ...core.unchecked_base_model import construct_type
9
+ from ...errors.unprocessable_entity_error import UnprocessableEntityError
10
+ from ...types.http_validation_error import HttpValidationError
11
+ from json.decoder import JSONDecodeError
12
+ from ...core.api_error import ApiError
13
+ from ...types.agent_state import AgentState
14
+ from ...core.client_wrapper import AsyncClientWrapper
15
+
16
+ # this is used as the default value for optional parameters
17
+ OMIT = typing.cast(typing.Any, ...)
18
+
19
+
20
+ class BlocksClient:
21
+ def __init__(self, *, client_wrapper: SyncClientWrapper):
22
+ self._client_wrapper = client_wrapper
23
+
24
+ def retrieve(
25
+ self, agent_id: str, block_label: str, *, request_options: typing.Optional[RequestOptions] = None
26
+ ) -> Block:
27
+ """
28
+ Retrieve a memory block from an agent.
29
+
30
+ Parameters
31
+ ----------
32
+ agent_id : str
33
+
34
+ block_label : str
35
+
36
+ request_options : typing.Optional[RequestOptions]
37
+ Request-specific configuration.
38
+
39
+ Returns
40
+ -------
41
+ Block
42
+ Successful Response
43
+
44
+ Examples
45
+ --------
46
+ from letta_client import Letta
47
+
48
+ client = Letta(
49
+ token="YOUR_TOKEN",
50
+ )
51
+ client.agents.blocks.retrieve(
52
+ agent_id="agent_id",
53
+ block_label="block_label",
54
+ )
55
+ """
56
+ _response = self._client_wrapper.httpx_client.request(
57
+ f"v1/agents/{jsonable_encoder(agent_id)}/core-memory/blocks/{jsonable_encoder(block_label)}",
58
+ method="GET",
59
+ request_options=request_options,
60
+ )
61
+ try:
62
+ if 200 <= _response.status_code < 300:
63
+ return typing.cast(
64
+ Block,
65
+ construct_type(
66
+ type_=Block, # type: ignore
67
+ object_=_response.json(),
68
+ ),
69
+ )
70
+ if _response.status_code == 422:
71
+ raise UnprocessableEntityError(
72
+ typing.cast(
73
+ HttpValidationError,
74
+ construct_type(
75
+ type_=HttpValidationError, # type: ignore
76
+ object_=_response.json(),
77
+ ),
78
+ )
79
+ )
80
+ _response_json = _response.json()
81
+ except JSONDecodeError:
82
+ raise ApiError(status_code=_response.status_code, body=_response.text)
83
+ raise ApiError(status_code=_response.status_code, body=_response_json)
84
+
85
+ def modify(
86
+ self,
87
+ agent_id: str,
88
+ block_label: str,
89
+ *,
90
+ value: typing.Optional[str] = OMIT,
91
+ limit: typing.Optional[int] = OMIT,
92
+ name: typing.Optional[str] = OMIT,
93
+ is_template: typing.Optional[bool] = OMIT,
94
+ label: typing.Optional[str] = OMIT,
95
+ description: typing.Optional[str] = OMIT,
96
+ metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
97
+ request_options: typing.Optional[RequestOptions] = None,
98
+ ) -> Block:
99
+ """
100
+ Updates a memory block of an agent.
101
+
102
+ Parameters
103
+ ----------
104
+ agent_id : str
105
+
106
+ block_label : str
107
+
108
+ value : typing.Optional[str]
109
+ Value of the block.
110
+
111
+ limit : typing.Optional[int]
112
+ Character limit of the block.
113
+
114
+ name : typing.Optional[str]
115
+ Name of the block if it is a template.
116
+
117
+ is_template : typing.Optional[bool]
118
+ Whether the block is a template (e.g. saved human/persona options).
119
+
120
+ label : typing.Optional[str]
121
+ Label of the block (e.g. 'human', 'persona') in the context window.
122
+
123
+ description : typing.Optional[str]
124
+ Description of the block.
125
+
126
+ metadata : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
127
+ Metadata of the block.
128
+
129
+ request_options : typing.Optional[RequestOptions]
130
+ Request-specific configuration.
131
+
132
+ Returns
133
+ -------
134
+ Block
135
+ Successful Response
136
+
137
+ Examples
138
+ --------
139
+ from letta_client import Letta
140
+
141
+ client = Letta(
142
+ token="YOUR_TOKEN",
143
+ )
144
+ client.agents.blocks.modify(
145
+ agent_id="agent_id",
146
+ block_label="block_label",
147
+ )
148
+ """
149
+ _response = self._client_wrapper.httpx_client.request(
150
+ f"v1/agents/{jsonable_encoder(agent_id)}/core-memory/blocks/{jsonable_encoder(block_label)}",
151
+ method="PATCH",
152
+ json={
153
+ "value": value,
154
+ "limit": limit,
155
+ "name": name,
156
+ "is_template": is_template,
157
+ "label": label,
158
+ "description": description,
159
+ "metadata": metadata,
160
+ },
161
+ request_options=request_options,
162
+ omit=OMIT,
163
+ )
164
+ try:
165
+ if 200 <= _response.status_code < 300:
166
+ return typing.cast(
167
+ Block,
168
+ construct_type(
169
+ type_=Block, # type: ignore
170
+ object_=_response.json(),
171
+ ),
172
+ )
173
+ if _response.status_code == 422:
174
+ raise UnprocessableEntityError(
175
+ typing.cast(
176
+ HttpValidationError,
177
+ construct_type(
178
+ type_=HttpValidationError, # type: ignore
179
+ object_=_response.json(),
180
+ ),
181
+ )
182
+ )
183
+ _response_json = _response.json()
184
+ except JSONDecodeError:
185
+ raise ApiError(status_code=_response.status_code, body=_response.text)
186
+ raise ApiError(status_code=_response.status_code, body=_response_json)
187
+
188
+ def list(self, agent_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> typing.List[Block]:
189
+ """
190
+ Retrieve the memory blocks of a specific agent.
191
+
192
+ Parameters
193
+ ----------
194
+ agent_id : str
195
+
196
+ request_options : typing.Optional[RequestOptions]
197
+ Request-specific configuration.
198
+
199
+ Returns
200
+ -------
201
+ typing.List[Block]
202
+ Successful Response
203
+
204
+ Examples
205
+ --------
206
+ from letta_client import Letta
207
+
208
+ client = Letta(
209
+ token="YOUR_TOKEN",
210
+ )
211
+ client.agents.blocks.list(
212
+ agent_id="agent_id",
213
+ )
214
+ """
215
+ _response = self._client_wrapper.httpx_client.request(
216
+ f"v1/agents/{jsonable_encoder(agent_id)}/core-memory/blocks",
217
+ method="GET",
218
+ request_options=request_options,
219
+ )
220
+ try:
221
+ if 200 <= _response.status_code < 300:
222
+ return typing.cast(
223
+ typing.List[Block],
224
+ construct_type(
225
+ type_=typing.List[Block], # type: ignore
226
+ object_=_response.json(),
227
+ ),
228
+ )
229
+ if _response.status_code == 422:
230
+ raise UnprocessableEntityError(
231
+ typing.cast(
232
+ HttpValidationError,
233
+ construct_type(
234
+ type_=HttpValidationError, # type: ignore
235
+ object_=_response.json(),
236
+ ),
237
+ )
238
+ )
239
+ _response_json = _response.json()
240
+ except JSONDecodeError:
241
+ raise ApiError(status_code=_response.status_code, body=_response.text)
242
+ raise ApiError(status_code=_response.status_code, body=_response_json)
243
+
244
+ def attach(
245
+ self, agent_id: str, block_id: str, *, request_options: typing.Optional[RequestOptions] = None
246
+ ) -> AgentState:
247
+ """
248
+ Attach a block to an agent.
249
+
250
+ Parameters
251
+ ----------
252
+ agent_id : str
253
+
254
+ block_id : str
255
+
256
+ request_options : typing.Optional[RequestOptions]
257
+ Request-specific configuration.
258
+
259
+ Returns
260
+ -------
261
+ AgentState
262
+ Successful Response
263
+
264
+ Examples
265
+ --------
266
+ from letta_client import Letta
267
+
268
+ client = Letta(
269
+ token="YOUR_TOKEN",
270
+ )
271
+ client.agents.blocks.attach(
272
+ agent_id="agent_id",
273
+ block_id="block_id",
274
+ )
275
+ """
276
+ _response = self._client_wrapper.httpx_client.request(
277
+ f"v1/agents/{jsonable_encoder(agent_id)}/core-memory/blocks/attach/{jsonable_encoder(block_id)}",
278
+ method="PATCH",
279
+ request_options=request_options,
280
+ )
281
+ try:
282
+ if 200 <= _response.status_code < 300:
283
+ return typing.cast(
284
+ AgentState,
285
+ construct_type(
286
+ type_=AgentState, # type: ignore
287
+ object_=_response.json(),
288
+ ),
289
+ )
290
+ if _response.status_code == 422:
291
+ raise UnprocessableEntityError(
292
+ typing.cast(
293
+ HttpValidationError,
294
+ construct_type(
295
+ type_=HttpValidationError, # type: ignore
296
+ object_=_response.json(),
297
+ ),
298
+ )
299
+ )
300
+ _response_json = _response.json()
301
+ except JSONDecodeError:
302
+ raise ApiError(status_code=_response.status_code, body=_response.text)
303
+ raise ApiError(status_code=_response.status_code, body=_response_json)
304
+
305
+ def detach(
306
+ self, agent_id: str, block_id: str, *, request_options: typing.Optional[RequestOptions] = None
307
+ ) -> AgentState:
308
+ """
309
+ Detach a block from an agent.
310
+
311
+ Parameters
312
+ ----------
313
+ agent_id : str
314
+
315
+ block_id : str
316
+
317
+ request_options : typing.Optional[RequestOptions]
318
+ Request-specific configuration.
319
+
320
+ Returns
321
+ -------
322
+ AgentState
323
+ Successful Response
324
+
325
+ Examples
326
+ --------
327
+ from letta_client import Letta
328
+
329
+ client = Letta(
330
+ token="YOUR_TOKEN",
331
+ )
332
+ client.agents.blocks.detach(
333
+ agent_id="agent_id",
334
+ block_id="block_id",
335
+ )
336
+ """
337
+ _response = self._client_wrapper.httpx_client.request(
338
+ f"v1/agents/{jsonable_encoder(agent_id)}/core-memory/blocks/detach/{jsonable_encoder(block_id)}",
339
+ method="PATCH",
340
+ request_options=request_options,
341
+ )
342
+ try:
343
+ if 200 <= _response.status_code < 300:
344
+ return typing.cast(
345
+ AgentState,
346
+ construct_type(
347
+ type_=AgentState, # type: ignore
348
+ object_=_response.json(),
349
+ ),
350
+ )
351
+ if _response.status_code == 422:
352
+ raise UnprocessableEntityError(
353
+ typing.cast(
354
+ HttpValidationError,
355
+ construct_type(
356
+ type_=HttpValidationError, # type: ignore
357
+ object_=_response.json(),
358
+ ),
359
+ )
360
+ )
361
+ _response_json = _response.json()
362
+ except JSONDecodeError:
363
+ raise ApiError(status_code=_response.status_code, body=_response.text)
364
+ raise ApiError(status_code=_response.status_code, body=_response_json)
365
+
366
+
367
+ class AsyncBlocksClient:
368
+ def __init__(self, *, client_wrapper: AsyncClientWrapper):
369
+ self._client_wrapper = client_wrapper
370
+
371
+ async def retrieve(
372
+ self, agent_id: str, block_label: str, *, request_options: typing.Optional[RequestOptions] = None
373
+ ) -> Block:
374
+ """
375
+ Retrieve a memory block from an agent.
376
+
377
+ Parameters
378
+ ----------
379
+ agent_id : str
380
+
381
+ block_label : str
382
+
383
+ request_options : typing.Optional[RequestOptions]
384
+ Request-specific configuration.
385
+
386
+ Returns
387
+ -------
388
+ Block
389
+ Successful Response
390
+
391
+ Examples
392
+ --------
393
+ import asyncio
394
+
395
+ from letta_client import AsyncLetta
396
+
397
+ client = AsyncLetta(
398
+ token="YOUR_TOKEN",
399
+ )
400
+
401
+
402
+ async def main() -> None:
403
+ await client.agents.blocks.retrieve(
404
+ agent_id="agent_id",
405
+ block_label="block_label",
406
+ )
407
+
408
+
409
+ asyncio.run(main())
410
+ """
411
+ _response = await self._client_wrapper.httpx_client.request(
412
+ f"v1/agents/{jsonable_encoder(agent_id)}/core-memory/blocks/{jsonable_encoder(block_label)}",
413
+ method="GET",
414
+ request_options=request_options,
415
+ )
416
+ try:
417
+ if 200 <= _response.status_code < 300:
418
+ return typing.cast(
419
+ Block,
420
+ construct_type(
421
+ type_=Block, # type: ignore
422
+ object_=_response.json(),
423
+ ),
424
+ )
425
+ if _response.status_code == 422:
426
+ raise UnprocessableEntityError(
427
+ typing.cast(
428
+ HttpValidationError,
429
+ construct_type(
430
+ type_=HttpValidationError, # type: ignore
431
+ object_=_response.json(),
432
+ ),
433
+ )
434
+ )
435
+ _response_json = _response.json()
436
+ except JSONDecodeError:
437
+ raise ApiError(status_code=_response.status_code, body=_response.text)
438
+ raise ApiError(status_code=_response.status_code, body=_response_json)
439
+
440
+ async def modify(
441
+ self,
442
+ agent_id: str,
443
+ block_label: str,
444
+ *,
445
+ value: typing.Optional[str] = OMIT,
446
+ limit: typing.Optional[int] = OMIT,
447
+ name: typing.Optional[str] = OMIT,
448
+ is_template: typing.Optional[bool] = OMIT,
449
+ label: typing.Optional[str] = OMIT,
450
+ description: typing.Optional[str] = OMIT,
451
+ metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
452
+ request_options: typing.Optional[RequestOptions] = None,
453
+ ) -> Block:
454
+ """
455
+ Updates a memory block of an agent.
456
+
457
+ Parameters
458
+ ----------
459
+ agent_id : str
460
+
461
+ block_label : str
462
+
463
+ value : typing.Optional[str]
464
+ Value of the block.
465
+
466
+ limit : typing.Optional[int]
467
+ Character limit of the block.
468
+
469
+ name : typing.Optional[str]
470
+ Name of the block if it is a template.
471
+
472
+ is_template : typing.Optional[bool]
473
+ Whether the block is a template (e.g. saved human/persona options).
474
+
475
+ label : typing.Optional[str]
476
+ Label of the block (e.g. 'human', 'persona') in the context window.
477
+
478
+ description : typing.Optional[str]
479
+ Description of the block.
480
+
481
+ metadata : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
482
+ Metadata of the block.
483
+
484
+ request_options : typing.Optional[RequestOptions]
485
+ Request-specific configuration.
486
+
487
+ Returns
488
+ -------
489
+ Block
490
+ Successful Response
491
+
492
+ Examples
493
+ --------
494
+ import asyncio
495
+
496
+ from letta_client import AsyncLetta
497
+
498
+ client = AsyncLetta(
499
+ token="YOUR_TOKEN",
500
+ )
501
+
502
+
503
+ async def main() -> None:
504
+ await client.agents.blocks.modify(
505
+ agent_id="agent_id",
506
+ block_label="block_label",
507
+ )
508
+
509
+
510
+ asyncio.run(main())
511
+ """
512
+ _response = await self._client_wrapper.httpx_client.request(
513
+ f"v1/agents/{jsonable_encoder(agent_id)}/core-memory/blocks/{jsonable_encoder(block_label)}",
514
+ method="PATCH",
515
+ json={
516
+ "value": value,
517
+ "limit": limit,
518
+ "name": name,
519
+ "is_template": is_template,
520
+ "label": label,
521
+ "description": description,
522
+ "metadata": metadata,
523
+ },
524
+ request_options=request_options,
525
+ omit=OMIT,
526
+ )
527
+ try:
528
+ if 200 <= _response.status_code < 300:
529
+ return typing.cast(
530
+ Block,
531
+ construct_type(
532
+ type_=Block, # type: ignore
533
+ object_=_response.json(),
534
+ ),
535
+ )
536
+ if _response.status_code == 422:
537
+ raise UnprocessableEntityError(
538
+ typing.cast(
539
+ HttpValidationError,
540
+ construct_type(
541
+ type_=HttpValidationError, # type: ignore
542
+ object_=_response.json(),
543
+ ),
544
+ )
545
+ )
546
+ _response_json = _response.json()
547
+ except JSONDecodeError:
548
+ raise ApiError(status_code=_response.status_code, body=_response.text)
549
+ raise ApiError(status_code=_response.status_code, body=_response_json)
550
+
551
+ async def list(
552
+ self, agent_id: str, *, request_options: typing.Optional[RequestOptions] = None
553
+ ) -> typing.List[Block]:
554
+ """
555
+ Retrieve the memory blocks of a specific agent.
556
+
557
+ Parameters
558
+ ----------
559
+ agent_id : str
560
+
561
+ request_options : typing.Optional[RequestOptions]
562
+ Request-specific configuration.
563
+
564
+ Returns
565
+ -------
566
+ typing.List[Block]
567
+ Successful Response
568
+
569
+ Examples
570
+ --------
571
+ import asyncio
572
+
573
+ from letta_client import AsyncLetta
574
+
575
+ client = AsyncLetta(
576
+ token="YOUR_TOKEN",
577
+ )
578
+
579
+
580
+ async def main() -> None:
581
+ await client.agents.blocks.list(
582
+ agent_id="agent_id",
583
+ )
584
+
585
+
586
+ asyncio.run(main())
587
+ """
588
+ _response = await self._client_wrapper.httpx_client.request(
589
+ f"v1/agents/{jsonable_encoder(agent_id)}/core-memory/blocks",
590
+ method="GET",
591
+ request_options=request_options,
592
+ )
593
+ try:
594
+ if 200 <= _response.status_code < 300:
595
+ return typing.cast(
596
+ typing.List[Block],
597
+ construct_type(
598
+ type_=typing.List[Block], # type: ignore
599
+ object_=_response.json(),
600
+ ),
601
+ )
602
+ if _response.status_code == 422:
603
+ raise UnprocessableEntityError(
604
+ typing.cast(
605
+ HttpValidationError,
606
+ construct_type(
607
+ type_=HttpValidationError, # type: ignore
608
+ object_=_response.json(),
609
+ ),
610
+ )
611
+ )
612
+ _response_json = _response.json()
613
+ except JSONDecodeError:
614
+ raise ApiError(status_code=_response.status_code, body=_response.text)
615
+ raise ApiError(status_code=_response.status_code, body=_response_json)
616
+
617
+ async def attach(
618
+ self, agent_id: str, block_id: str, *, request_options: typing.Optional[RequestOptions] = None
619
+ ) -> AgentState:
620
+ """
621
+ Attach a block to an agent.
622
+
623
+ Parameters
624
+ ----------
625
+ agent_id : str
626
+
627
+ block_id : str
628
+
629
+ request_options : typing.Optional[RequestOptions]
630
+ Request-specific configuration.
631
+
632
+ Returns
633
+ -------
634
+ AgentState
635
+ Successful Response
636
+
637
+ Examples
638
+ --------
639
+ import asyncio
640
+
641
+ from letta_client import AsyncLetta
642
+
643
+ client = AsyncLetta(
644
+ token="YOUR_TOKEN",
645
+ )
646
+
647
+
648
+ async def main() -> None:
649
+ await client.agents.blocks.attach(
650
+ agent_id="agent_id",
651
+ block_id="block_id",
652
+ )
653
+
654
+
655
+ asyncio.run(main())
656
+ """
657
+ _response = await self._client_wrapper.httpx_client.request(
658
+ f"v1/agents/{jsonable_encoder(agent_id)}/core-memory/blocks/attach/{jsonable_encoder(block_id)}",
659
+ method="PATCH",
660
+ request_options=request_options,
661
+ )
662
+ try:
663
+ if 200 <= _response.status_code < 300:
664
+ return typing.cast(
665
+ AgentState,
666
+ construct_type(
667
+ type_=AgentState, # type: ignore
668
+ object_=_response.json(),
669
+ ),
670
+ )
671
+ if _response.status_code == 422:
672
+ raise UnprocessableEntityError(
673
+ typing.cast(
674
+ HttpValidationError,
675
+ construct_type(
676
+ type_=HttpValidationError, # type: ignore
677
+ object_=_response.json(),
678
+ ),
679
+ )
680
+ )
681
+ _response_json = _response.json()
682
+ except JSONDecodeError:
683
+ raise ApiError(status_code=_response.status_code, body=_response.text)
684
+ raise ApiError(status_code=_response.status_code, body=_response_json)
685
+
686
+ async def detach(
687
+ self, agent_id: str, block_id: str, *, request_options: typing.Optional[RequestOptions] = None
688
+ ) -> AgentState:
689
+ """
690
+ Detach a block from an agent.
691
+
692
+ Parameters
693
+ ----------
694
+ agent_id : str
695
+
696
+ block_id : str
697
+
698
+ request_options : typing.Optional[RequestOptions]
699
+ Request-specific configuration.
700
+
701
+ Returns
702
+ -------
703
+ AgentState
704
+ Successful Response
705
+
706
+ Examples
707
+ --------
708
+ import asyncio
709
+
710
+ from letta_client import AsyncLetta
711
+
712
+ client = AsyncLetta(
713
+ token="YOUR_TOKEN",
714
+ )
715
+
716
+
717
+ async def main() -> None:
718
+ await client.agents.blocks.detach(
719
+ agent_id="agent_id",
720
+ block_id="block_id",
721
+ )
722
+
723
+
724
+ asyncio.run(main())
725
+ """
726
+ _response = await self._client_wrapper.httpx_client.request(
727
+ f"v1/agents/{jsonable_encoder(agent_id)}/core-memory/blocks/detach/{jsonable_encoder(block_id)}",
728
+ method="PATCH",
729
+ request_options=request_options,
730
+ )
731
+ try:
732
+ if 200 <= _response.status_code < 300:
733
+ return typing.cast(
734
+ AgentState,
735
+ construct_type(
736
+ type_=AgentState, # type: ignore
737
+ object_=_response.json(),
738
+ ),
739
+ )
740
+ if _response.status_code == 422:
741
+ raise UnprocessableEntityError(
742
+ typing.cast(
743
+ HttpValidationError,
744
+ construct_type(
745
+ type_=HttpValidationError, # type: ignore
746
+ object_=_response.json(),
747
+ ),
748
+ )
749
+ )
750
+ _response_json = _response.json()
751
+ except JSONDecodeError:
752
+ raise ApiError(status_code=_response.status_code, body=_response.text)
753
+ raise ApiError(status_code=_response.status_code, body=_response_json)