letta-client 0.1.4__py3-none-any.whl → 0.1.9__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.
Files changed (157) hide show
  1. letta/__init__.py +44 -21
  2. letta/agents/__init__.py +71 -24
  3. letta/agents/archival_memory/client.py +17 -17
  4. letta/agents/client.py +424 -1700
  5. letta/agents/context/client.py +5 -5
  6. letta/agents/core_memory/client.py +1080 -0
  7. letta/agents/memory_variables/__init__.py +5 -0
  8. letta/agents/{memory → memory_variables}/client.py +41 -40
  9. letta/agents/memory_variables/types/__init__.py +5 -0
  10. letta/agents/{types/agents_get_agent_variables_response.py → memory_variables/types/memory_variables_get_response.py} +3 -3
  11. letta/agents/messages/__init__.py +36 -2
  12. letta/agents/messages/client.py +278 -17
  13. letta/agents/messages/types/__init__.py +37 -3
  14. letta/agents/messages/types/letta_streaming_response.py +139 -16
  15. letta/agents/messages/types/messages_list_response_item.py +121 -9
  16. letta/agents/recall_memory/client.py +5 -5
  17. letta/agents/sources/client.py +5 -5
  18. letta/agents/templates/__init__.py +5 -0
  19. letta/agents/templates/client.py +578 -0
  20. letta/agents/templates/types/__init__.py +5 -0
  21. letta/agents/templates/types/templates_migrate_response.py +19 -0
  22. letta/agents/tools/client.py +13 -13
  23. letta/agents/types/__init__.py +23 -29
  24. letta/agents/types/agents_search_request_combinator.py +5 -0
  25. letta/agents/types/agents_search_request_search_item.py +64 -0
  26. letta/agents/types/{agents_search_deployed_agents_request_search_item_zero.py → agents_search_request_search_item_name.py} +5 -4
  27. letta/agents/types/agents_search_request_search_item_name_operator.py +5 -0
  28. letta/agents/types/agents_search_request_search_item_order_by.py +22 -0
  29. letta/agents/types/agents_search_request_search_item_order_by_direction.py +5 -0
  30. letta/agents/types/agents_search_request_search_item_order_by_value.py +5 -0
  31. letta/agents/types/{agents_migrate_response.py → agents_search_request_search_item_version.py} +3 -3
  32. letta/blocks/client.py +25 -25
  33. letta/client.py +8 -4
  34. letta/core/__init__.py +4 -0
  35. letta/core/client_wrapper.py +7 -18
  36. letta/core/unchecked_base_model.py +305 -0
  37. letta/health/client.py +3 -3
  38. letta/jobs/client.py +17 -17
  39. letta/models/client.py +5 -5
  40. letta/providers/client.py +597 -0
  41. letta/sources/client.py +33 -33
  42. letta/sources/files/client.py +11 -11
  43. letta/sources/passages/client.py +5 -5
  44. letta/tools/client.py +77 -57
  45. letta/types/__init__.py +22 -0
  46. letta/types/action_model.py +2 -2
  47. letta/types/action_parameters_model.py +2 -2
  48. letta/types/action_response_model.py +2 -2
  49. letta/types/agent_environment_variable.py +63 -0
  50. letta/types/agent_state.py +19 -16
  51. letta/types/agent_type.py +1 -2
  52. letta/types/app_auth_scheme.py +2 -2
  53. letta/types/app_model.py +2 -2
  54. letta/types/archival_memory_summary.py +2 -2
  55. letta/types/assistant_file.py +2 -2
  56. letta/types/assistant_message_input.py +2 -2
  57. letta/types/assistant_message_output.py +3 -4
  58. letta/types/auth_request.py +2 -2
  59. letta/types/auth_response.py +2 -2
  60. letta/types/auth_scheme_field.py +2 -2
  61. letta/types/block.py +11 -16
  62. letta/types/block_update.py +2 -2
  63. letta/types/chat_completion_request.py +2 -2
  64. letta/types/chat_completion_response.py +2 -2
  65. letta/types/child_tool_rule.py +2 -2
  66. letta/types/choice.py +2 -2
  67. letta/types/conditional_tool_rule.py +2 -2
  68. letta/types/conflict_error_body.py +2 -2
  69. letta/types/context_window_overview.py +7 -2
  70. letta/types/create_assistant_file_request.py +2 -2
  71. letta/types/create_assistant_request.py +2 -2
  72. letta/types/create_block.py +2 -2
  73. letta/types/delete_assistant_file_response.py +2 -2
  74. letta/types/delete_assistant_response.py +2 -2
  75. letta/types/e_2_b_sandbox_config.py +2 -2
  76. letta/types/embedding_config.py +10 -10
  77. letta/types/file_metadata.py +2 -7
  78. letta/types/function_call_input.py +2 -2
  79. letta/types/function_call_output.py +2 -2
  80. letta/types/function_schema.py +2 -2
  81. letta/types/health.py +2 -2
  82. letta/types/http_validation_error.py +2 -2
  83. letta/types/init_tool_rule.py +2 -2
  84. letta/types/internal_server_error_body.py +2 -2
  85. letta/types/job.py +7 -12
  86. letta/types/letta_request.py +7 -2
  87. letta/types/letta_response.py +6 -5
  88. letta/types/letta_response_messages_item.py +125 -0
  89. letta/types/letta_schemas_letta_message_tool_call.py +2 -2
  90. letta/types/letta_schemas_message_message.py +12 -17
  91. letta/types/letta_schemas_openai_chat_completion_request_tool.py +2 -2
  92. letta/types/letta_schemas_openai_chat_completion_request_tool_call.py +2 -2
  93. letta/types/letta_schemas_openai_chat_completion_request_tool_call_function.py +2 -2
  94. letta/types/letta_schemas_openai_chat_completion_response_message.py +2 -2
  95. letta/types/letta_schemas_openai_chat_completion_response_tool_call.py +2 -2
  96. letta/types/letta_schemas_openai_chat_completions_tool_call_function.py +2 -2
  97. letta/types/letta_schemas_openai_chat_completions_tool_call_input.py +2 -2
  98. letta/types/letta_schemas_openai_chat_completions_tool_call_output.py +2 -2
  99. letta/types/letta_schemas_tool_tool.py +14 -13
  100. letta/types/letta_usage_statistics.py +6 -7
  101. letta/types/llm_config.py +9 -9
  102. letta/types/local_sandbox_config.py +2 -2
  103. letta/types/log_prob_token.py +2 -2
  104. letta/types/memory.py +2 -2
  105. letta/types/message_content_log_prob.py +2 -2
  106. letta/types/message_create.py +2 -2
  107. letta/types/not_found_error_body.py +2 -2
  108. letta/types/open_ai_assistant.py +2 -2
  109. letta/types/organization.py +2 -2
  110. letta/types/organization_create.py +2 -2
  111. letta/types/passage.py +10 -15
  112. letta/types/provider.py +38 -0
  113. letta/types/reasoning_message.py +6 -7
  114. letta/types/recall_memory_summary.py +2 -2
  115. letta/types/response_format.py +2 -2
  116. letta/types/sandbox_config.py +2 -7
  117. letta/types/sandbox_config_create.py +2 -2
  118. letta/types/sandbox_config_update.py +2 -2
  119. letta/types/sandbox_environment_variable.py +2 -7
  120. letta/types/sandbox_environment_variable_create.py +2 -2
  121. letta/types/sandbox_environment_variable_update.py +2 -6
  122. letta/types/source.py +8 -13
  123. letta/types/system_message_input.py +2 -2
  124. letta/types/system_message_output.py +6 -7
  125. letta/types/terminal_tool_rule.py +2 -2
  126. letta/types/tool_call_delta.py +2 -2
  127. letta/types/tool_call_function_output.py +2 -2
  128. letta/types/tool_call_message.py +6 -7
  129. letta/types/tool_create.py +2 -2
  130. letta/types/tool_function_choice.py +2 -2
  131. letta/types/tool_input.py +2 -2
  132. letta/types/tool_message.py +2 -2
  133. letta/types/tool_return_message.py +10 -11
  134. letta/types/tool_type.py +5 -0
  135. letta/types/usage_statistics.py +2 -2
  136. letta/types/user.py +5 -10
  137. letta/types/user_create.py +2 -7
  138. letta/types/user_message_input.py +2 -2
  139. letta/types/user_message_output.py +6 -7
  140. letta/types/user_update.py +2 -7
  141. letta/types/validation_error.py +2 -2
  142. {letta_client-0.1.4.dist-info → letta_client-0.1.9.dist-info}/METADATA +1 -1
  143. letta_client-0.1.9.dist-info/RECORD +200 -0
  144. letta/agents/memory/__init__.py +0 -5
  145. letta/agents/memory/messages/client.py +0 -147
  146. letta/agents/memory_blocks/client.py +0 -364
  147. letta/agents/types/agents_search_deployed_agents_request_combinator.py +0 -5
  148. letta/agents/types/agents_search_deployed_agents_request_search_item.py +0 -16
  149. letta/agents/types/agents_search_deployed_agents_request_search_item_direction.py +0 -27
  150. letta/agents/types/agents_search_deployed_agents_request_search_item_direction_direction.py +0 -5
  151. letta/agents/types/agents_search_deployed_agents_request_search_item_direction_value.py +0 -7
  152. letta/agents/types/agents_search_deployed_agents_request_search_item_operator.py +0 -24
  153. letta/agents/types/agents_search_deployed_agents_request_search_item_operator_operator.py +0 -7
  154. letta_client-0.1.4.dist-info/RECORD +0 -191
  155. /letta/agents/{memory/messages → core_memory}/__init__.py +0 -0
  156. /letta/{agents/memory_blocks → providers}/__init__.py +0 -0
  157. {letta_client-0.1.4.dist-info → letta_client-0.1.9.dist-info}/WHEEL +0 -0
@@ -5,7 +5,7 @@ from ...core.client_wrapper import SyncClientWrapper
5
5
  from ...core.request_options import RequestOptions
6
6
  from .types.messages_list_response import MessagesListResponse
7
7
  from ...core.jsonable_encoder import jsonable_encoder
8
- from ...core.pydantic_utilities import parse_obj_as
8
+ from ...core.unchecked_base_model import construct_type
9
9
  from ...errors.unprocessable_entity_error import UnprocessableEntityError
10
10
  from ...types.http_validation_error import HttpValidationError
11
11
  from json.decoder import JSONDecodeError
@@ -21,6 +21,7 @@ from ...types.letta_schemas_message_message import LettaSchemasMessageMessage
21
21
  from .types.letta_streaming_response import LettaStreamingResponse
22
22
  import httpx_sse
23
23
  import json
24
+ from ...types.job import Job
24
25
  from ...core.client_wrapper import AsyncClientWrapper
25
26
 
26
27
  # this is used as the default value for optional parameters
@@ -99,7 +100,7 @@ class MessagesClient:
99
100
  if 200 <= _response.status_code < 300:
100
101
  return typing.cast(
101
102
  MessagesListResponse,
102
- parse_obj_as(
103
+ construct_type(
103
104
  type_=MessagesListResponse, # type: ignore
104
105
  object_=_response.json(),
105
106
  ),
@@ -108,7 +109,7 @@ class MessagesClient:
108
109
  raise UnprocessableEntityError(
109
110
  typing.cast(
110
111
  HttpValidationError,
111
- parse_obj_as(
112
+ construct_type(
112
113
  type_=HttpValidationError, # type: ignore
113
114
  object_=_response.json(),
114
115
  ),
@@ -124,6 +125,7 @@ class MessagesClient:
124
125
  agent_id: str,
125
126
  *,
126
127
  messages: typing.Sequence[MessageCreate],
128
+ use_assistant_message: typing.Optional[bool] = OMIT,
127
129
  assistant_message_tool_name: typing.Optional[str] = OMIT,
128
130
  assistant_message_tool_kwarg: typing.Optional[str] = OMIT,
129
131
  request_options: typing.Optional[RequestOptions] = None,
@@ -139,6 +141,9 @@ class MessagesClient:
139
141
  messages : typing.Sequence[MessageCreate]
140
142
  The messages to be sent to the agent.
141
143
 
144
+ use_assistant_message : typing.Optional[bool]
145
+ Whether the server should parse specific tool call arguments (default `send_message`) as `AssistantMessage` objects.
146
+
142
147
  assistant_message_tool_name : typing.Optional[str]
143
148
  The name of the designated message tool.
144
149
 
@@ -177,6 +182,7 @@ class MessagesClient:
177
182
  "messages": convert_and_respect_annotation_metadata(
178
183
  object_=messages, annotation=typing.Sequence[MessageCreate], direction="write"
179
184
  ),
185
+ "use_assistant_message": use_assistant_message,
180
186
  "assistant_message_tool_name": assistant_message_tool_name,
181
187
  "assistant_message_tool_kwarg": assistant_message_tool_kwarg,
182
188
  },
@@ -187,7 +193,7 @@ class MessagesClient:
187
193
  if 200 <= _response.status_code < 300:
188
194
  return typing.cast(
189
195
  LettaResponse,
190
- parse_obj_as(
196
+ construct_type(
191
197
  type_=LettaResponse, # type: ignore
192
198
  object_=_response.json(),
193
199
  ),
@@ -196,7 +202,7 @@ class MessagesClient:
196
202
  raise UnprocessableEntityError(
197
203
  typing.cast(
198
204
  HttpValidationError,
199
- parse_obj_as(
205
+ construct_type(
200
206
  type_=HttpValidationError, # type: ignore
201
207
  object_=_response.json(),
202
208
  ),
@@ -287,7 +293,7 @@ class MessagesClient:
287
293
  if 200 <= _response.status_code < 300:
288
294
  return typing.cast(
289
295
  LettaSchemasMessageMessage,
290
- parse_obj_as(
296
+ construct_type(
291
297
  type_=LettaSchemasMessageMessage, # type: ignore
292
298
  object_=_response.json(),
293
299
  ),
@@ -296,7 +302,7 @@ class MessagesClient:
296
302
  raise UnprocessableEntityError(
297
303
  typing.cast(
298
304
  HttpValidationError,
299
- parse_obj_as(
305
+ construct_type(
300
306
  type_=HttpValidationError, # type: ignore
301
307
  object_=_response.json(),
302
308
  ),
@@ -312,6 +318,7 @@ class MessagesClient:
312
318
  agent_id: str,
313
319
  *,
314
320
  messages: typing.Sequence[MessageCreate],
321
+ use_assistant_message: typing.Optional[bool] = OMIT,
315
322
  assistant_message_tool_name: typing.Optional[str] = OMIT,
316
323
  assistant_message_tool_kwarg: typing.Optional[str] = OMIT,
317
324
  stream_tokens: typing.Optional[bool] = OMIT,
@@ -329,6 +336,9 @@ class MessagesClient:
329
336
  messages : typing.Sequence[MessageCreate]
330
337
  The messages to be sent to the agent.
331
338
 
339
+ use_assistant_message : typing.Optional[bool]
340
+ Whether the server should parse specific tool call arguments (default `send_message`) as `AssistantMessage` objects.
341
+
332
342
  assistant_message_tool_name : typing.Optional[str]
333
343
  The name of the designated message tool.
334
344
 
@@ -345,6 +355,25 @@ class MessagesClient:
345
355
  ------
346
356
  typing.Iterator[LettaStreamingResponse]
347
357
  Successful response
358
+
359
+ Examples
360
+ --------
361
+ from letta import Letta, MessageCreate
362
+
363
+ client = Letta(
364
+ token="YOUR_TOKEN",
365
+ )
366
+ response = client.agents.messages.stream(
367
+ agent_id="agent_id",
368
+ messages=[
369
+ MessageCreate(
370
+ role="user",
371
+ text="text",
372
+ )
373
+ ],
374
+ )
375
+ for chunk in response:
376
+ yield chunk
348
377
  """
349
378
  with self._client_wrapper.httpx_client.stream(
350
379
  f"v1/agents/{jsonable_encoder(agent_id)}/messages/stream",
@@ -353,6 +382,7 @@ class MessagesClient:
353
382
  "messages": convert_and_respect_annotation_metadata(
354
383
  object_=messages, annotation=typing.Sequence[MessageCreate], direction="write"
355
384
  ),
385
+ "use_assistant_message": use_assistant_message,
356
386
  "assistant_message_tool_name": assistant_message_tool_name,
357
387
  "assistant_message_tool_kwarg": assistant_message_tool_kwarg,
358
388
  "stream_tokens": stream_tokens,
@@ -370,7 +400,7 @@ class MessagesClient:
370
400
  try:
371
401
  yield typing.cast(
372
402
  LettaStreamingResponse,
373
- parse_obj_as(
403
+ construct_type(
374
404
  type_=LettaStreamingResponse, # type: ignore
375
405
  object_=json.loads(_sse.data),
376
406
  ),
@@ -383,7 +413,7 @@ class MessagesClient:
383
413
  raise UnprocessableEntityError(
384
414
  typing.cast(
385
415
  HttpValidationError,
386
- parse_obj_as(
416
+ construct_type(
387
417
  type_=HttpValidationError, # type: ignore
388
418
  object_=_response.json(),
389
419
  ),
@@ -394,6 +424,99 @@ class MessagesClient:
394
424
  raise ApiError(status_code=_response.status_code, body=_response.text)
395
425
  raise ApiError(status_code=_response.status_code, body=_response_json)
396
426
 
427
+ def create_async(
428
+ self,
429
+ agent_id: str,
430
+ *,
431
+ messages: typing.Sequence[MessageCreate],
432
+ use_assistant_message: typing.Optional[bool] = OMIT,
433
+ assistant_message_tool_name: typing.Optional[str] = OMIT,
434
+ assistant_message_tool_kwarg: typing.Optional[str] = OMIT,
435
+ request_options: typing.Optional[RequestOptions] = None,
436
+ ) -> Job:
437
+ """
438
+ Asynchronously process a user message and return a job ID.
439
+ The actual processing happens in the background, and the status can be checked using the job ID.
440
+
441
+ Parameters
442
+ ----------
443
+ agent_id : str
444
+
445
+ messages : typing.Sequence[MessageCreate]
446
+ The messages to be sent to the agent.
447
+
448
+ use_assistant_message : typing.Optional[bool]
449
+ Whether the server should parse specific tool call arguments (default `send_message`) as `AssistantMessage` objects.
450
+
451
+ assistant_message_tool_name : typing.Optional[str]
452
+ The name of the designated message tool.
453
+
454
+ assistant_message_tool_kwarg : typing.Optional[str]
455
+ The name of the message argument in the designated message tool.
456
+
457
+ request_options : typing.Optional[RequestOptions]
458
+ Request-specific configuration.
459
+
460
+ Returns
461
+ -------
462
+ Job
463
+ Successful Response
464
+
465
+ Examples
466
+ --------
467
+ from letta import Letta, MessageCreate
468
+
469
+ client = Letta(
470
+ token="YOUR_TOKEN",
471
+ )
472
+ client.agents.messages.create_async(
473
+ agent_id="agent_id",
474
+ messages=[
475
+ MessageCreate(
476
+ role="user",
477
+ text="text",
478
+ )
479
+ ],
480
+ )
481
+ """
482
+ _response = self._client_wrapper.httpx_client.request(
483
+ f"v1/agents/{jsonable_encoder(agent_id)}/messages/async",
484
+ method="POST",
485
+ json={
486
+ "messages": convert_and_respect_annotation_metadata(
487
+ object_=messages, annotation=typing.Sequence[MessageCreate], direction="write"
488
+ ),
489
+ "use_assistant_message": use_assistant_message,
490
+ "assistant_message_tool_name": assistant_message_tool_name,
491
+ "assistant_message_tool_kwarg": assistant_message_tool_kwarg,
492
+ },
493
+ request_options=request_options,
494
+ omit=OMIT,
495
+ )
496
+ try:
497
+ if 200 <= _response.status_code < 300:
498
+ return typing.cast(
499
+ Job,
500
+ construct_type(
501
+ type_=Job, # type: ignore
502
+ object_=_response.json(),
503
+ ),
504
+ )
505
+ if _response.status_code == 422:
506
+ raise UnprocessableEntityError(
507
+ typing.cast(
508
+ HttpValidationError,
509
+ construct_type(
510
+ type_=HttpValidationError, # type: ignore
511
+ object_=_response.json(),
512
+ ),
513
+ )
514
+ )
515
+ _response_json = _response.json()
516
+ except JSONDecodeError:
517
+ raise ApiError(status_code=_response.status_code, body=_response.text)
518
+ raise ApiError(status_code=_response.status_code, body=_response_json)
519
+
397
520
 
398
521
  class AsyncMessagesClient:
399
522
  def __init__(self, *, client_wrapper: AsyncClientWrapper):
@@ -475,7 +598,7 @@ class AsyncMessagesClient:
475
598
  if 200 <= _response.status_code < 300:
476
599
  return typing.cast(
477
600
  MessagesListResponse,
478
- parse_obj_as(
601
+ construct_type(
479
602
  type_=MessagesListResponse, # type: ignore
480
603
  object_=_response.json(),
481
604
  ),
@@ -484,7 +607,7 @@ class AsyncMessagesClient:
484
607
  raise UnprocessableEntityError(
485
608
  typing.cast(
486
609
  HttpValidationError,
487
- parse_obj_as(
610
+ construct_type(
488
611
  type_=HttpValidationError, # type: ignore
489
612
  object_=_response.json(),
490
613
  ),
@@ -500,6 +623,7 @@ class AsyncMessagesClient:
500
623
  agent_id: str,
501
624
  *,
502
625
  messages: typing.Sequence[MessageCreate],
626
+ use_assistant_message: typing.Optional[bool] = OMIT,
503
627
  assistant_message_tool_name: typing.Optional[str] = OMIT,
504
628
  assistant_message_tool_kwarg: typing.Optional[str] = OMIT,
505
629
  request_options: typing.Optional[RequestOptions] = None,
@@ -515,6 +639,9 @@ class AsyncMessagesClient:
515
639
  messages : typing.Sequence[MessageCreate]
516
640
  The messages to be sent to the agent.
517
641
 
642
+ use_assistant_message : typing.Optional[bool]
643
+ Whether the server should parse specific tool call arguments (default `send_message`) as `AssistantMessage` objects.
644
+
518
645
  assistant_message_tool_name : typing.Optional[str]
519
646
  The name of the designated message tool.
520
647
 
@@ -561,6 +688,7 @@ class AsyncMessagesClient:
561
688
  "messages": convert_and_respect_annotation_metadata(
562
689
  object_=messages, annotation=typing.Sequence[MessageCreate], direction="write"
563
690
  ),
691
+ "use_assistant_message": use_assistant_message,
564
692
  "assistant_message_tool_name": assistant_message_tool_name,
565
693
  "assistant_message_tool_kwarg": assistant_message_tool_kwarg,
566
694
  },
@@ -571,7 +699,7 @@ class AsyncMessagesClient:
571
699
  if 200 <= _response.status_code < 300:
572
700
  return typing.cast(
573
701
  LettaResponse,
574
- parse_obj_as(
702
+ construct_type(
575
703
  type_=LettaResponse, # type: ignore
576
704
  object_=_response.json(),
577
705
  ),
@@ -580,7 +708,7 @@ class AsyncMessagesClient:
580
708
  raise UnprocessableEntityError(
581
709
  typing.cast(
582
710
  HttpValidationError,
583
- parse_obj_as(
711
+ construct_type(
584
712
  type_=HttpValidationError, # type: ignore
585
713
  object_=_response.json(),
586
714
  ),
@@ -679,7 +807,7 @@ class AsyncMessagesClient:
679
807
  if 200 <= _response.status_code < 300:
680
808
  return typing.cast(
681
809
  LettaSchemasMessageMessage,
682
- parse_obj_as(
810
+ construct_type(
683
811
  type_=LettaSchemasMessageMessage, # type: ignore
684
812
  object_=_response.json(),
685
813
  ),
@@ -688,7 +816,7 @@ class AsyncMessagesClient:
688
816
  raise UnprocessableEntityError(
689
817
  typing.cast(
690
818
  HttpValidationError,
691
- parse_obj_as(
819
+ construct_type(
692
820
  type_=HttpValidationError, # type: ignore
693
821
  object_=_response.json(),
694
822
  ),
@@ -704,6 +832,7 @@ class AsyncMessagesClient:
704
832
  agent_id: str,
705
833
  *,
706
834
  messages: typing.Sequence[MessageCreate],
835
+ use_assistant_message: typing.Optional[bool] = OMIT,
707
836
  assistant_message_tool_name: typing.Optional[str] = OMIT,
708
837
  assistant_message_tool_kwarg: typing.Optional[str] = OMIT,
709
838
  stream_tokens: typing.Optional[bool] = OMIT,
@@ -721,6 +850,9 @@ class AsyncMessagesClient:
721
850
  messages : typing.Sequence[MessageCreate]
722
851
  The messages to be sent to the agent.
723
852
 
853
+ use_assistant_message : typing.Optional[bool]
854
+ Whether the server should parse specific tool call arguments (default `send_message`) as `AssistantMessage` objects.
855
+
724
856
  assistant_message_tool_name : typing.Optional[str]
725
857
  The name of the designated message tool.
726
858
 
@@ -737,6 +869,33 @@ class AsyncMessagesClient:
737
869
  ------
738
870
  typing.AsyncIterator[LettaStreamingResponse]
739
871
  Successful response
872
+
873
+ Examples
874
+ --------
875
+ import asyncio
876
+
877
+ from letta import AsyncLetta, MessageCreate
878
+
879
+ client = AsyncLetta(
880
+ token="YOUR_TOKEN",
881
+ )
882
+
883
+
884
+ async def main() -> None:
885
+ response = await client.agents.messages.stream(
886
+ agent_id="agent_id",
887
+ messages=[
888
+ MessageCreate(
889
+ role="user",
890
+ text="text",
891
+ )
892
+ ],
893
+ )
894
+ async for chunk in response:
895
+ yield chunk
896
+
897
+
898
+ asyncio.run(main())
740
899
  """
741
900
  async with self._client_wrapper.httpx_client.stream(
742
901
  f"v1/agents/{jsonable_encoder(agent_id)}/messages/stream",
@@ -745,6 +904,7 @@ class AsyncMessagesClient:
745
904
  "messages": convert_and_respect_annotation_metadata(
746
905
  object_=messages, annotation=typing.Sequence[MessageCreate], direction="write"
747
906
  ),
907
+ "use_assistant_message": use_assistant_message,
748
908
  "assistant_message_tool_name": assistant_message_tool_name,
749
909
  "assistant_message_tool_kwarg": assistant_message_tool_kwarg,
750
910
  "stream_tokens": stream_tokens,
@@ -762,7 +922,7 @@ class AsyncMessagesClient:
762
922
  try:
763
923
  yield typing.cast(
764
924
  LettaStreamingResponse,
765
- parse_obj_as(
925
+ construct_type(
766
926
  type_=LettaStreamingResponse, # type: ignore
767
927
  object_=json.loads(_sse.data),
768
928
  ),
@@ -775,7 +935,7 @@ class AsyncMessagesClient:
775
935
  raise UnprocessableEntityError(
776
936
  typing.cast(
777
937
  HttpValidationError,
778
- parse_obj_as(
938
+ construct_type(
779
939
  type_=HttpValidationError, # type: ignore
780
940
  object_=_response.json(),
781
941
  ),
@@ -785,3 +945,104 @@ class AsyncMessagesClient:
785
945
  except JSONDecodeError:
786
946
  raise ApiError(status_code=_response.status_code, body=_response.text)
787
947
  raise ApiError(status_code=_response.status_code, body=_response_json)
948
+
949
+ async def create_async(
950
+ self,
951
+ agent_id: str,
952
+ *,
953
+ messages: typing.Sequence[MessageCreate],
954
+ use_assistant_message: typing.Optional[bool] = OMIT,
955
+ assistant_message_tool_name: typing.Optional[str] = OMIT,
956
+ assistant_message_tool_kwarg: typing.Optional[str] = OMIT,
957
+ request_options: typing.Optional[RequestOptions] = None,
958
+ ) -> Job:
959
+ """
960
+ Asynchronously process a user message and return a job ID.
961
+ The actual processing happens in the background, and the status can be checked using the job ID.
962
+
963
+ Parameters
964
+ ----------
965
+ agent_id : str
966
+
967
+ messages : typing.Sequence[MessageCreate]
968
+ The messages to be sent to the agent.
969
+
970
+ use_assistant_message : typing.Optional[bool]
971
+ Whether the server should parse specific tool call arguments (default `send_message`) as `AssistantMessage` objects.
972
+
973
+ assistant_message_tool_name : typing.Optional[str]
974
+ The name of the designated message tool.
975
+
976
+ assistant_message_tool_kwarg : typing.Optional[str]
977
+ The name of the message argument in the designated message tool.
978
+
979
+ request_options : typing.Optional[RequestOptions]
980
+ Request-specific configuration.
981
+
982
+ Returns
983
+ -------
984
+ Job
985
+ Successful Response
986
+
987
+ Examples
988
+ --------
989
+ import asyncio
990
+
991
+ from letta import AsyncLetta, MessageCreate
992
+
993
+ client = AsyncLetta(
994
+ token="YOUR_TOKEN",
995
+ )
996
+
997
+
998
+ async def main() -> None:
999
+ await client.agents.messages.create_async(
1000
+ agent_id="agent_id",
1001
+ messages=[
1002
+ MessageCreate(
1003
+ role="user",
1004
+ text="text",
1005
+ )
1006
+ ],
1007
+ )
1008
+
1009
+
1010
+ asyncio.run(main())
1011
+ """
1012
+ _response = await self._client_wrapper.httpx_client.request(
1013
+ f"v1/agents/{jsonable_encoder(agent_id)}/messages/async",
1014
+ method="POST",
1015
+ json={
1016
+ "messages": convert_and_respect_annotation_metadata(
1017
+ object_=messages, annotation=typing.Sequence[MessageCreate], direction="write"
1018
+ ),
1019
+ "use_assistant_message": use_assistant_message,
1020
+ "assistant_message_tool_name": assistant_message_tool_name,
1021
+ "assistant_message_tool_kwarg": assistant_message_tool_kwarg,
1022
+ },
1023
+ request_options=request_options,
1024
+ omit=OMIT,
1025
+ )
1026
+ try:
1027
+ if 200 <= _response.status_code < 300:
1028
+ return typing.cast(
1029
+ Job,
1030
+ construct_type(
1031
+ type_=Job, # type: ignore
1032
+ object_=_response.json(),
1033
+ ),
1034
+ )
1035
+ if _response.status_code == 422:
1036
+ raise UnprocessableEntityError(
1037
+ typing.cast(
1038
+ HttpValidationError,
1039
+ construct_type(
1040
+ type_=HttpValidationError, # type: ignore
1041
+ object_=_response.json(),
1042
+ ),
1043
+ )
1044
+ )
1045
+ _response_json = _response.json()
1046
+ except JSONDecodeError:
1047
+ raise ApiError(status_code=_response.status_code, body=_response.text)
1048
+ raise ApiError(status_code=_response.status_code, body=_response_json)
@@ -1,7 +1,41 @@
1
1
  # This file was auto-generated by Fern from our API Definition.
2
2
 
3
- from .letta_streaming_response import LettaStreamingResponse
3
+ from .letta_streaming_response import (
4
+ LettaStreamingResponse,
5
+ LettaStreamingResponse_AssistantMessage,
6
+ LettaStreamingResponse_ReasoningMessage,
7
+ LettaStreamingResponse_SystemMessage,
8
+ LettaStreamingResponse_ToolCallMessage,
9
+ LettaStreamingResponse_ToolReturnMessage,
10
+ LettaStreamingResponse_UsageStatistics,
11
+ LettaStreamingResponse_UserMessage,
12
+ )
4
13
  from .messages_list_response import MessagesListResponse
5
- from .messages_list_response_item import MessagesListResponseItem
14
+ from .messages_list_response_item import (
15
+ MessagesListResponseItem,
16
+ MessagesListResponseItem_AssistantMessage,
17
+ MessagesListResponseItem_ReasoningMessage,
18
+ MessagesListResponseItem_SystemMessage,
19
+ MessagesListResponseItem_ToolCallMessage,
20
+ MessagesListResponseItem_ToolReturnMessage,
21
+ MessagesListResponseItem_UserMessage,
22
+ )
6
23
 
7
- __all__ = ["LettaStreamingResponse", "MessagesListResponse", "MessagesListResponseItem"]
24
+ __all__ = [
25
+ "LettaStreamingResponse",
26
+ "LettaStreamingResponse_AssistantMessage",
27
+ "LettaStreamingResponse_ReasoningMessage",
28
+ "LettaStreamingResponse_SystemMessage",
29
+ "LettaStreamingResponse_ToolCallMessage",
30
+ "LettaStreamingResponse_ToolReturnMessage",
31
+ "LettaStreamingResponse_UsageStatistics",
32
+ "LettaStreamingResponse_UserMessage",
33
+ "MessagesListResponse",
34
+ "MessagesListResponseItem",
35
+ "MessagesListResponseItem_AssistantMessage",
36
+ "MessagesListResponseItem_ReasoningMessage",
37
+ "MessagesListResponseItem_SystemMessage",
38
+ "MessagesListResponseItem_ToolCallMessage",
39
+ "MessagesListResponseItem_ToolReturnMessage",
40
+ "MessagesListResponseItem_UserMessage",
41
+ ]