letta-client 1.0.0a1__py3-none-any.whl → 1.0.0a3__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.

Files changed (202) hide show
  1. letta_client/__init__.py +149 -23
  2. letta_client/agents/__init__.py +15 -17
  3. letta_client/agents/blocks/__init__.py +3 -0
  4. letta_client/agents/blocks/client.py +77 -4
  5. letta_client/agents/blocks/raw_client.py +63 -2
  6. letta_client/agents/blocks/types/__init__.py +7 -0
  7. letta_client/agents/blocks/types/blocks_list_request_order.py +5 -0
  8. letta_client/agents/client.py +46 -13
  9. letta_client/agents/files/__init__.py +3 -0
  10. letta_client/agents/files/client.py +71 -10
  11. letta_client/agents/files/raw_client.py +51 -10
  12. letta_client/agents/files/types/__init__.py +7 -0
  13. letta_client/{types/tool_return_status.py → agents/files/types/files_list_request_order.py} +1 -1
  14. letta_client/agents/folders/__init__.py +3 -0
  15. letta_client/agents/folders/client.py +77 -4
  16. letta_client/agents/folders/raw_client.py +63 -2
  17. letta_client/agents/folders/types/__init__.py +7 -0
  18. letta_client/agents/folders/types/folders_list_request_order.py +5 -0
  19. letta_client/agents/groups/__init__.py +3 -0
  20. letta_client/agents/groups/client.py +71 -2
  21. letta_client/agents/groups/raw_client.py +51 -0
  22. letta_client/agents/groups/types/__init__.py +7 -0
  23. letta_client/agents/groups/types/groups_list_request_order.py +5 -0
  24. letta_client/agents/messages/__init__.py +2 -0
  25. letta_client/agents/messages/client.py +55 -14
  26. letta_client/agents/messages/raw_client.py +35 -14
  27. letta_client/agents/messages/types/__init__.py +2 -0
  28. letta_client/agents/messages/types/messages_list_request_order.py +5 -0
  29. letta_client/agents/passages/client.py +29 -0
  30. letta_client/agents/raw_client.py +4 -4
  31. letta_client/agents/sources/__init__.py +3 -0
  32. letta_client/agents/sources/client.py +77 -4
  33. letta_client/agents/sources/raw_client.py +63 -2
  34. letta_client/agents/sources/types/__init__.py +7 -0
  35. letta_client/agents/sources/types/sources_list_request_order.py +5 -0
  36. letta_client/agents/tools/__init__.py +3 -0
  37. letta_client/agents/tools/client.py +77 -4
  38. letta_client/agents/tools/raw_client.py +63 -2
  39. letta_client/agents/tools/types/__init__.py +7 -0
  40. letta_client/agents/tools/types/tools_list_request_order.py +5 -0
  41. letta_client/archives/client.py +16 -2
  42. letta_client/base_client.py +3 -0
  43. letta_client/batches/client.py +12 -2
  44. letta_client/batches/messages/client.py +10 -0
  45. letta_client/blocks/agents/client.py +8 -0
  46. letta_client/blocks/client.py +32 -2
  47. letta_client/chat/__init__.py +7 -0
  48. letta_client/chat/client.py +255 -0
  49. letta_client/chat/raw_client.py +269 -0
  50. letta_client/chat/types/__init__.py +8 -0
  51. letta_client/chat/types/chat_completion_request_messages_item.py +19 -0
  52. letta_client/chat/types/chat_completion_request_stop.py +5 -0
  53. letta_client/client_side_access_tokens/client.py +10 -2
  54. letta_client/core/client_wrapper.py +2 -2
  55. letta_client/errors/__init__.py +2 -0
  56. letta_client/errors/gone_error.py +10 -0
  57. letta_client/folders/agents/client.py +8 -0
  58. letta_client/folders/client.py +20 -4
  59. letta_client/folders/files/client.py +14 -0
  60. letta_client/folders/passages/client.py +8 -0
  61. letta_client/groups/client.py +16 -2
  62. letta_client/groups/messages/client.py +14 -0
  63. letta_client/identities/agents/client.py +8 -0
  64. letta_client/identities/blocks/client.py +8 -0
  65. letta_client/identities/client.py +20 -2
  66. letta_client/jobs/__init__.py +3 -0
  67. letta_client/jobs/client.py +61 -12
  68. letta_client/jobs/raw_client.py +29 -8
  69. letta_client/jobs/types/__init__.py +7 -0
  70. letta_client/jobs/types/jobs_list_request_order.py +5 -0
  71. letta_client/models/client.py +8 -2
  72. letta_client/projects/client.py +10 -2
  73. letta_client/providers/client.py +90 -2
  74. letta_client/providers/raw_client.py +102 -0
  75. letta_client/runs/__init__.py +11 -2
  76. letta_client/runs/client.py +150 -18
  77. letta_client/runs/messages/client.py +30 -2
  78. letta_client/runs/messages/raw_client.py +10 -0
  79. letta_client/runs/raw_client.py +144 -14
  80. letta_client/runs/steps/__init__.py +3 -0
  81. letta_client/runs/steps/client.py +39 -30
  82. letta_client/runs/steps/raw_client.py +19 -28
  83. letta_client/runs/steps/types/__init__.py +7 -0
  84. letta_client/runs/steps/types/steps_list_request_order.py +5 -0
  85. letta_client/runs/types/__init__.py +2 -1
  86. letta_client/runs/types/runs_list_request_order.py +5 -0
  87. letta_client/sources/client.py +8 -2
  88. letta_client/sources/files/client.py +12 -0
  89. letta_client/sources/passages/client.py +6 -0
  90. letta_client/steps/client.py +26 -2
  91. letta_client/steps/messages/client.py +8 -0
  92. letta_client/tags/client.py +16 -2
  93. letta_client/templates/__init__.py +12 -0
  94. letta_client/templates/client.py +30 -4
  95. letta_client/templates/raw_client.py +2 -2
  96. letta_client/templates/types/__init__.py +24 -0
  97. letta_client/templates/types/templates_create_agents_from_template_response_agents_item_llm_config.py +4 -0
  98. letta_client/templates/types/templates_create_agents_from_template_response_agents_item_llm_config_display_name.py +14 -0
  99. letta_client/templates/types/templates_create_agents_from_template_response_agents_item_llm_config_display_name_item.py +5 -0
  100. letta_client/templates/types/templates_create_agents_from_template_response_agents_item_secrets_item.py +4 -0
  101. letta_client/templates/types/templates_create_agents_from_template_response_agents_item_secrets_item_value_enc.py +14 -0
  102. letta_client/templates/types/templates_create_agents_from_template_response_agents_item_secrets_item_value_enc_item.py +5 -0
  103. letta_client/templates/types/templates_create_agents_from_template_response_agents_item_tool_exec_environment_variables_item.py +6 -0
  104. letta_client/templates/types/templates_create_agents_from_template_response_agents_item_tool_exec_environment_variables_item_value_enc.py +16 -0
  105. letta_client/templates/types/templates_create_agents_from_template_response_agents_item_tool_exec_environment_variables_item_value_enc_item.py +7 -0
  106. letta_client/templates/types/templates_create_agents_from_template_response_agents_item_tools_item_tool_type.py +1 -1
  107. letta_client/tools/client.py +30 -220
  108. letta_client/tools/raw_client.py +0 -292
  109. letta_client/types/__init__.py +130 -22
  110. letta_client/types/agent_environment_variable.py +5 -0
  111. letta_client/types/{action_parameters_model.py → annotation.py} +4 -10
  112. letta_client/types/{action_response_model.py → annotation_url_citation.py} +4 -9
  113. letta_client/types/approval_create.py +8 -2
  114. letta_client/types/approval_create_approvals_item.py +8 -0
  115. letta_client/types/approval_response_message.py +8 -2
  116. letta_client/types/approval_response_message_approvals_item.py +8 -0
  117. letta_client/types/approval_return.py +34 -0
  118. letta_client/{agents/templates/types/templates_migrate_response.py → types/audio.py} +4 -4
  119. letta_client/types/chat_completion.py +30 -0
  120. letta_client/types/chat_completion_assistant_message_param.py +30 -0
  121. letta_client/types/chat_completion_assistant_message_param_content.py +9 -0
  122. letta_client/types/chat_completion_assistant_message_param_content_item.py +10 -0
  123. letta_client/types/chat_completion_assistant_message_param_tool_calls_item.py +10 -0
  124. letta_client/types/chat_completion_audio.py +23 -0
  125. letta_client/types/chat_completion_content_part_image_param.py +22 -0
  126. letta_client/types/chat_completion_content_part_input_audio_param.py +22 -0
  127. letta_client/types/chat_completion_content_part_refusal_param.py +21 -0
  128. letta_client/types/chat_completion_content_part_text_param.py +21 -0
  129. letta_client/types/chat_completion_developer_message_param.py +23 -0
  130. letta_client/types/chat_completion_developer_message_param_content.py +7 -0
  131. letta_client/types/chat_completion_function_message_param.py +22 -0
  132. letta_client/types/chat_completion_message.py +30 -0
  133. letta_client/types/chat_completion_message_custom_tool_call.py +23 -0
  134. letta_client/types/chat_completion_message_custom_tool_call_param.py +23 -0
  135. letta_client/types/chat_completion_message_function_tool_call_input.py +25 -0
  136. letta_client/types/{chat_completion_message_function_tool_call.py → chat_completion_message_function_tool_call_output.py} +3 -3
  137. letta_client/types/chat_completion_message_function_tool_call_param.py +25 -0
  138. letta_client/types/chat_completion_message_tool_calls_item.py +10 -0
  139. letta_client/types/chat_completion_service_tier.py +5 -0
  140. letta_client/types/chat_completion_system_message_param.py +23 -0
  141. letta_client/types/chat_completion_system_message_param_content.py +7 -0
  142. letta_client/types/chat_completion_token_logprob.py +24 -0
  143. letta_client/types/chat_completion_tool_message_param.py +23 -0
  144. letta_client/types/chat_completion_tool_message_param_content.py +7 -0
  145. letta_client/types/chat_completion_user_message_param.py +23 -0
  146. letta_client/types/chat_completion_user_message_param_content.py +7 -0
  147. letta_client/types/chat_completion_user_message_param_content_item.py +15 -0
  148. letta_client/types/choice.py +26 -0
  149. letta_client/types/choice_finish_reason.py +7 -0
  150. letta_client/types/choice_logprobs.py +22 -0
  151. letta_client/types/completion_tokens_details.py +23 -0
  152. letta_client/types/{auth_scheme_field.py → completion_usage.py} +8 -13
  153. letta_client/types/custom_input.py +21 -0
  154. letta_client/types/custom_output.py +21 -0
  155. letta_client/types/file.py +22 -0
  156. letta_client/types/file_file.py +22 -0
  157. letta_client/types/function_call_input.py +21 -0
  158. letta_client/types/function_call_output.py +21 -0
  159. letta_client/types/{function.py → function_output.py} +1 -1
  160. letta_client/types/image_url.py +22 -0
  161. letta_client/types/image_url_detail.py +5 -0
  162. letta_client/types/input_audio.py +22 -0
  163. letta_client/types/input_audio_format.py +5 -0
  164. letta_client/types/internal_template_agent_create.py +2 -2
  165. letta_client/types/letta_schemas_agent_file_agent_schema.py +2 -2
  166. letta_client/types/letta_schemas_agent_file_message_schema.py +27 -4
  167. letta_client/types/letta_schemas_agent_file_message_schema_approvals_item.py +8 -0
  168. letta_client/types/letta_schemas_letta_message_tool_return.py +26 -0
  169. letta_client/types/letta_schemas_letta_message_tool_return_status.py +5 -0
  170. letta_client/types/{tool_return.py → letta_schemas_message_tool_return.py} +9 -3
  171. letta_client/types/letta_schemas_message_tool_return_status.py +5 -0
  172. letta_client/types/llm_config.py +5 -0
  173. letta_client/types/message.py +10 -4
  174. letta_client/types/message_approvals_item.py +8 -0
  175. letta_client/types/omitted_reasoning_content.py +4 -0
  176. letta_client/types/openai_types_chat_chat_completion_message_function_tool_call_function.py +21 -0
  177. letta_client/types/openai_types_chat_chat_completion_message_function_tool_call_param_function.py +21 -0
  178. letta_client/types/prompt_tokens_details.py +21 -0
  179. letta_client/types/provider.py +10 -0
  180. letta_client/types/run_metrics.py +58 -0
  181. letta_client/types/sandbox_environment_variable.py +5 -0
  182. letta_client/types/text_content.py +5 -0
  183. letta_client/types/tool_call_content.py +5 -0
  184. letta_client/types/tool_call_message.py +2 -0
  185. letta_client/types/tool_call_message_tool_calls.py +8 -0
  186. letta_client/types/tool_return_message.py +8 -5
  187. letta_client/types/tool_type.py +1 -1
  188. letta_client/types/top_logprob.py +22 -0
  189. letta_client/voice/client.py +14 -0
  190. letta_client/voice/raw_client.py +37 -0
  191. letta_client-1.0.0a3.dist-info/METADATA +422 -0
  192. {letta_client-1.0.0a1.dist-info → letta_client-1.0.0a3.dist-info}/RECORD +193 -115
  193. letta_client/agents/templates/__init__.py +0 -7
  194. letta_client/agents/templates/client.py +0 -307
  195. letta_client/agents/templates/raw_client.py +0 -275
  196. letta_client/agents/templates/types/__init__.py +0 -7
  197. letta_client/types/action_model.py +0 -39
  198. letta_client/types/app_auth_scheme.py +0 -35
  199. letta_client/types/app_auth_scheme_auth_mode.py +0 -19
  200. letta_client/types/app_model.py +0 -45
  201. letta_client-1.0.0a1.dist-info/METADATA +0 -211
  202. {letta_client-1.0.0a1.dist-info → letta_client-1.0.0a3.dist-info}/WHEEL +0 -0
@@ -0,0 +1,22 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+
5
+ import pydantic
6
+ from ..core.pydantic_utilities import IS_PYDANTIC_V2
7
+ from ..core.unchecked_base_model import UncheckedBaseModel
8
+
9
+
10
+ class TopLogprob(UncheckedBaseModel):
11
+ token: str
12
+ bytes: typing.Optional[typing.List[int]] = None
13
+ logprob: float
14
+
15
+ if IS_PYDANTIC_V2:
16
+ model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2
17
+ else:
18
+
19
+ class Config:
20
+ frozen = True
21
+ smart_union = True
22
+ extra = pydantic.Extra.allow
@@ -33,6 +33,13 @@ class VoiceClient:
33
33
  request_options: typing.Optional[RequestOptions] = None,
34
34
  ) -> typing.Optional[typing.Any]:
35
35
  """
36
+ DEPRECATED: This voice-beta endpoint has been deprecated.
37
+
38
+ The voice functionality has been integrated into the main chat completions endpoint.
39
+ Please use the standard /v1/agents/{agent_id}/messages endpoint instead.
40
+
41
+ This endpoint will be removed in a future version.
42
+
36
43
  Parameters
37
44
  ----------
38
45
  agent_id : str
@@ -89,6 +96,13 @@ class AsyncVoiceClient:
89
96
  request_options: typing.Optional[RequestOptions] = None,
90
97
  ) -> typing.Optional[typing.Any]:
91
98
  """
99
+ DEPRECATED: This voice-beta endpoint has been deprecated.
100
+
101
+ The voice functionality has been integrated into the main chat completions endpoint.
102
+ Please use the standard /v1/agents/{agent_id}/messages endpoint instead.
103
+
104
+ This endpoint will be removed in a future version.
105
+
92
106
  Parameters
93
107
  ----------
94
108
  agent_id : str
@@ -9,6 +9,7 @@ from ..core.http_response import AsyncHttpResponse, HttpResponse
9
9
  from ..core.jsonable_encoder import jsonable_encoder
10
10
  from ..core.request_options import RequestOptions
11
11
  from ..core.unchecked_base_model import construct_type
12
+ from ..errors.gone_error import GoneError
12
13
  from ..errors.unprocessable_entity_error import UnprocessableEntityError
13
14
  from ..types.http_validation_error import HttpValidationError
14
15
 
@@ -28,6 +29,13 @@ class RawVoiceClient:
28
29
  request_options: typing.Optional[RequestOptions] = None,
29
30
  ) -> HttpResponse[typing.Optional[typing.Any]]:
30
31
  """
32
+ DEPRECATED: This voice-beta endpoint has been deprecated.
33
+
34
+ The voice functionality has been integrated into the main chat completions endpoint.
35
+ Please use the standard /v1/agents/{agent_id}/messages endpoint instead.
36
+
37
+ This endpoint will be removed in a future version.
38
+
31
39
  Parameters
32
40
  ----------
33
41
  agent_id : str
@@ -64,6 +72,17 @@ class RawVoiceClient:
64
72
  ),
65
73
  )
66
74
  return HttpResponse(response=_response, data=_data)
75
+ if _response.status_code == 410:
76
+ raise GoneError(
77
+ headers=dict(_response.headers),
78
+ body=typing.cast(
79
+ typing.Optional[typing.Any],
80
+ construct_type(
81
+ type_=typing.Optional[typing.Any], # type: ignore
82
+ object_=_response.json(),
83
+ ),
84
+ ),
85
+ )
67
86
  if _response.status_code == 422:
68
87
  raise UnprocessableEntityError(
69
88
  headers=dict(_response.headers),
@@ -93,6 +112,13 @@ class AsyncRawVoiceClient:
93
112
  request_options: typing.Optional[RequestOptions] = None,
94
113
  ) -> AsyncHttpResponse[typing.Optional[typing.Any]]:
95
114
  """
115
+ DEPRECATED: This voice-beta endpoint has been deprecated.
116
+
117
+ The voice functionality has been integrated into the main chat completions endpoint.
118
+ Please use the standard /v1/agents/{agent_id}/messages endpoint instead.
119
+
120
+ This endpoint will be removed in a future version.
121
+
96
122
  Parameters
97
123
  ----------
98
124
  agent_id : str
@@ -129,6 +155,17 @@ class AsyncRawVoiceClient:
129
155
  ),
130
156
  )
131
157
  return AsyncHttpResponse(response=_response, data=_data)
158
+ if _response.status_code == 410:
159
+ raise GoneError(
160
+ headers=dict(_response.headers),
161
+ body=typing.cast(
162
+ typing.Optional[typing.Any],
163
+ construct_type(
164
+ type_=typing.Optional[typing.Any], # type: ignore
165
+ object_=_response.json(),
166
+ ),
167
+ ),
168
+ )
132
169
  if _response.status_code == 422:
133
170
  raise UnprocessableEntityError(
134
171
  headers=dict(_response.headers),
@@ -0,0 +1,422 @@
1
+ Metadata-Version: 2.1
2
+ Name: letta-client
3
+ Version: 1.0.0a3
4
+ Summary:
5
+ Requires-Python: >=3.8,<4.0
6
+ Classifier: Intended Audience :: Developers
7
+ Classifier: Operating System :: MacOS
8
+ Classifier: Operating System :: Microsoft :: Windows
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Operating System :: POSIX
11
+ Classifier: Operating System :: POSIX :: Linux
12
+ Classifier: Programming Language :: Python
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.8
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Classifier: Typing :: Typed
21
+ Requires-Dist: httpx (>=0.21.2)
22
+ Requires-Dist: httpx-sse (==0.4.0)
23
+ Requires-Dist: pydantic (>=1.9.2)
24
+ Requires-Dist: pydantic-core (>=2.18.2)
25
+ Requires-Dist: typing_extensions (>=4.0.0)
26
+ Description-Content-Type: text/markdown
27
+
28
+ # Letta Python SDK
29
+
30
+ [![pypi](https://img.shields.io/pypi/v/letta-client)](https://pypi.python.org/pypi/letta-client)
31
+
32
+ Letta is the platform for building stateful agents: open AI with advanced memory that can learn and self-improve over time.
33
+
34
+ ### Quicklinks:
35
+ * [**Developer Documentation**](https://docs.letta.com): Learn how to create agents using Python or TypeScript
36
+ * [**Python API Reference**](./reference.md): Complete Python SDK documentation
37
+ * [**Agent Development Environment (ADE)**](https://docs.letta.com/guides/ade/overview): A no-code UI for building stateful agents
38
+ * [**Letta Cloud**](https://app.letta.com/): The fastest way to try Letta
39
+
40
+ ## Get started
41
+
42
+ Install the Letta Python SDK:
43
+
44
+ ```bash
45
+ pip install letta-client
46
+ ```
47
+
48
+ ## Simple Hello World example
49
+
50
+ In the example below, we'll create a stateful agent with two memory blocks. We'll initialize the `human` memory block with incorrect information, and correct the agent in our first message - which will trigger the agent to update its own memory with a tool call.
51
+
52
+ *To run the examples, you'll need to get a `LETTA_API_KEY` from [Letta Cloud](https://app.letta.com/api-keys), or run your own self-hosted server (see [our guide](https://docs.letta.com/guides/selfhosting))*
53
+
54
+ ```python
55
+ from letta_client import Letta
56
+
57
+ client = Letta(token="LETTA_API_KEY")
58
+ # client = Letta(base_url="http://localhost:8283") # if self-hosting
59
+
60
+ agent_state = client.agents.create(
61
+ model="openai/gpt-4o-mini",
62
+ embedding="openai/text-embedding-3-small",
63
+ memory_blocks=[
64
+ {
65
+ "label": "human",
66
+ "value": "The human's name is Chad. They like vibe coding."
67
+ },
68
+ {
69
+ "label": "persona",
70
+ "value": "My name is Sam, a helpful assistant."
71
+ }
72
+ ],
73
+ tools=["web_search", "run_code"]
74
+ )
75
+
76
+ print(agent_state.id)
77
+ # agent-d9be...0846
78
+
79
+ response = client.agents.messages.create(
80
+ agent_id=agent_state.id,
81
+ messages=[
82
+ {
83
+ "role": "user",
84
+ "content": "Hey, nice to meet you, my name is Brad."
85
+ }
86
+ ]
87
+ )
88
+
89
+ # the agent will think, then edit its memory using a tool
90
+ for message in response.messages:
91
+ print(message)
92
+
93
+ # The content of this memory block will be something like
94
+ # "The human's name is Brad. They like vibe coding."
95
+ # Fetch this block's content with:
96
+ human_block = client.agents.blocks.retrieve(agent_id=agent_state.id, block_label="human")
97
+ print(human_block.value)
98
+ ```
99
+
100
+ ## Core concepts in Letta:
101
+
102
+ Letta is built on the [MemGPT](https://arxiv.org/abs/2310.08560) research paper, which introduced the concept of the "LLM Operating System" for memory management:
103
+
104
+ 1. [**Memory Hierarchy**](https://docs.letta.com/guides/agents/memory): Agents have self-editing memory split between in-context and out-of-context memory
105
+ 2. [**Memory Blocks**](https://docs.letta.com/guides/agents/memory-blocks): In-context memory is composed of persistent editable blocks
106
+ 3. [**Agentic Context Engineering**](https://docs.letta.com/guides/agents/context-engineering): Agents control their context window using tools to edit, delete, or search memory
107
+ 4. [**Perpetual Self-Improving Agents**](https://docs.letta.com/guides/agents/overview): Every agent has a perpetual (infinite) message history
108
+
109
+ ## Local Development
110
+
111
+ Connect to a local Letta server instead of the cloud:
112
+
113
+ ```python
114
+ from letta_client import Letta
115
+
116
+ client = Letta(base_url="http://localhost:8283")
117
+ ```
118
+
119
+ Run Letta locally with Docker:
120
+
121
+ ```bash
122
+ docker run \
123
+ -v ~/.letta/.persist/pgdata:/var/lib/postgresql/data \
124
+ -p 8283:8283 \
125
+ -e OPENAI_API_KEY="your_key" \
126
+ letta/letta:latest
127
+ ```
128
+
129
+ See the [self-hosting guide](https://docs.letta.com/guides/selfhosting) for more options.
130
+
131
+ ## Key Features
132
+
133
+ ### Memory Management ([full guide](https://docs.letta.com/guides/agents/memory-blocks))
134
+
135
+ Memory blocks are persistent, editable sections of an agent's context window:
136
+
137
+ ```python
138
+ # Create agent with memory blocks
139
+ agent = client.agents.create(
140
+ memory_blocks=[
141
+ {"label": "persona", "value": "I'm a helpful assistant."},
142
+ {"label": "human", "value": "User preferences and info."}
143
+ ]
144
+ )
145
+
146
+ # Modify blocks manually
147
+ client.agents.blocks.modify(
148
+ agent_id=agent.id,
149
+ block_label="human",
150
+ value="Updated user information"
151
+ )
152
+
153
+ # Retrieve a block
154
+ block = client.agents.blocks.retrieve(agent_id=agent.id, block_label="human")
155
+ ```
156
+
157
+ ### Multi-agent Shared Memory ([full guide](https://docs.letta.com/guides/agents/multi-agent-shared-memory))
158
+
159
+ Memory blocks can be attached to multiple agents. All agents will have an up-to-date view on the contents of the memory block -- if one agent modifies it, the other will see it immediately.
160
+
161
+ Here is how to attach a single memory block to multiple agents:
162
+
163
+ ```python
164
+ # Create shared block
165
+ shared_block = client.blocks.create(
166
+ label="organization",
167
+ value="Shared team context"
168
+ )
169
+
170
+ # Attach to multiple agents
171
+ agent1 = client.agents.create(
172
+ memory_blocks=[{"label": "persona", "value": "I am a supervisor"}],
173
+ block_ids=[shared_block.id]
174
+ )
175
+
176
+ agent2 = client.agents.create(
177
+ memory_blocks=[{"label": "persona", "value": "I am a worker"}],
178
+ block_ids=[shared_block.id]
179
+ )
180
+ ```
181
+
182
+ ### Sleep-time Agents ([full guide](https://docs.letta.com/guides/agents/architectures/sleeptime))
183
+
184
+ Background agents that share memory with your primary agent:
185
+
186
+ ```python
187
+ agent = client.agents.create(
188
+ model="openai/gpt-4o-mini",
189
+ enable_sleeptime=True # creates a sleep-time agent
190
+ )
191
+ ```
192
+
193
+ ### Agent File Import/Export ([full guide](https://docs.letta.com/guides/agents/agent-file))
194
+
195
+ Save and share agents with the `.af` file format:
196
+
197
+ ```python
198
+ # Import agent
199
+ with open('/path/to/agent.af', 'rb') as f:
200
+ agent = client.agents.import_agent_serialized(file=f)
201
+
202
+ # Export agent
203
+ schema = client.agents.export_agent_serialized(agent_id=agent.id)
204
+ ```
205
+
206
+ ### MCP Tools ([full guide](https://docs.letta.com/guides/mcp/overview))
207
+
208
+ Connect to Model Context Protocol servers:
209
+
210
+ ```python
211
+ # Add tool from MCP server
212
+ tool = client.tools.add_mcp_tool(
213
+ server_name="weather-server",
214
+ tool_name="get_weather"
215
+ )
216
+
217
+ # Create agent with MCP tool
218
+ agent = client.agents.create(
219
+ model="openai/gpt-4o-mini",
220
+ tool_ids=[tool.id]
221
+ )
222
+ ```
223
+
224
+ ### Filesystem ([full guide](https://docs.letta.com/guides/agents/filesystem))
225
+
226
+ Give agents access to files:
227
+
228
+ ```python
229
+ # Get an available embedding config
230
+ embedding_configs = client.models.list_embedding_models()
231
+
232
+ # Create folder and upload file
233
+ folder = client.folders.create(
234
+ name="my_folder",
235
+ embedding_config=embedding_configs[0]
236
+ )
237
+ with open("file.txt", "rb") as f:
238
+ client.folders.files.upload(file=f, folder_id=folder.id)
239
+
240
+ # Attach to agent
241
+ client.agents.folders.attach(agent_id=agent.id, folder_id=folder.id)
242
+ ```
243
+
244
+ ### Long-running Agents ([full guide](https://docs.letta.com/guides/agents/long-running))
245
+
246
+ Background execution with resumable streaming:
247
+
248
+ ```python
249
+ stream = client.agents.messages.create_stream(
250
+ agent_id=agent.id,
251
+ messages=[{"role": "user", "content": "Analyze this dataset"}],
252
+ background=True
253
+ )
254
+
255
+ run_id = None
256
+ last_seq_id = None
257
+ for chunk in stream:
258
+ run_id = chunk.run_id
259
+ last_seq_id = chunk.seq_id
260
+
261
+ # Resume if disconnected
262
+ for chunk in client.runs.stream(run_id=run_id, starting_after=last_seq_id):
263
+ print(chunk)
264
+ ```
265
+
266
+ ### Streaming ([full guide](https://docs.letta.com/guides/agents/streaming))
267
+
268
+ Stream responses in real-time:
269
+
270
+ ```python
271
+ stream = client.agents.messages.create_stream(
272
+ agent_id=agent.id,
273
+ messages=[{"role": "user", "content": "Hello!"}]
274
+ )
275
+
276
+ for chunk in stream:
277
+ print(chunk)
278
+ ```
279
+
280
+ ### Message Types ([full guide](https://docs.letta.com/guides/agents/message-types))
281
+
282
+ Agent responses contain different message types. Handle them with the `message_type` discriminator:
283
+
284
+ ```python
285
+ messages = client.agents.messages.list(agent_id=agent.id)
286
+
287
+ for message in messages:
288
+ if message.message_type == "user_message":
289
+ print(f"User: {message.content}")
290
+ elif message.message_type == "assistant_message":
291
+ print(f"Agent: {message.content}")
292
+ elif message.message_type == "reasoning_message":
293
+ print(f"Reasoning: {message.reasoning}")
294
+ elif message.message_type == "tool_call_message":
295
+ print(f"Tool: {message.tool_call.name}")
296
+ elif message.message_type == "tool_return_message":
297
+ print(f"Result: {message.tool_return}")
298
+ ```
299
+
300
+ ## Python Support
301
+
302
+ Full type hints and async support:
303
+
304
+ ```python
305
+ from letta_client import Letta
306
+ from letta_client.types import CreateAgentRequest
307
+
308
+ # Sync client
309
+ client = Letta(token="LETTA_API_KEY")
310
+
311
+ # Async client
312
+ from letta_client import AsyncLetta
313
+
314
+ async_client = AsyncLetta(token="LETTA_API_KEY")
315
+ agent = await async_client.agents.create(
316
+ model="openai/gpt-4o-mini",
317
+ memory_blocks=[...]
318
+ )
319
+ ```
320
+
321
+ ## Error Handling
322
+
323
+ ```python
324
+ from letta_client.core.api_error import ApiError
325
+
326
+ try:
327
+ client.agents.messages.create(agent_id=agent_id, messages=[...])
328
+ except ApiError as e:
329
+ print(e.status_code)
330
+ print(e.message)
331
+ print(e.body)
332
+ ```
333
+
334
+ ## Advanced Configuration
335
+
336
+ ### Retries
337
+
338
+ ```python
339
+ response = client.agents.create(
340
+ {...},
341
+ request_options={"max_retries": 3} # Default: 2
342
+ )
343
+ ```
344
+
345
+ ### Timeouts
346
+
347
+ ```python
348
+ response = client.agents.create(
349
+ {...},
350
+ request_options={"timeout_in_seconds": 30} # Default: 60
351
+ )
352
+ ```
353
+
354
+ ### Custom Headers
355
+
356
+ ```python
357
+ response = client.agents.create(
358
+ {...},
359
+ request_options={
360
+ "additional_headers": {
361
+ "X-Custom-Header": "value"
362
+ }
363
+ }
364
+ )
365
+ ```
366
+
367
+ ### Raw Response Access
368
+
369
+ ```python
370
+ response = client.agents.with_raw_response.create({...})
371
+
372
+ print(response.headers["X-My-Header"])
373
+ print(response.data) # access the underlying object
374
+ ```
375
+
376
+ ### Custom HTTP Client
377
+
378
+ ```python
379
+ import httpx
380
+ from letta_client import Letta
381
+
382
+ client = Letta(
383
+ httpx_client=httpx.Client(
384
+ proxies="http://my.test.proxy.example.com",
385
+ transport=httpx.HTTPTransport(local_address="0.0.0.0"),
386
+ )
387
+ )
388
+ ```
389
+
390
+ ## Runtime Compatibility
391
+
392
+ Works with:
393
+ - Python 3.8+
394
+ - Supports async/await
395
+ - Compatible with type checkers (mypy, pyright)
396
+
397
+ ## Contributing
398
+
399
+ Letta is an open source project built by over a hundred contributors. There are many ways to get involved in the Letta OSS project!
400
+
401
+ * [**Join the Discord**](https://discord.gg/letta): Chat with the Letta devs and other AI developers.
402
+ * [**Chat on our forum**](https://forum.letta.com/): If you're not into Discord, check out our developer forum.
403
+ * **Follow our socials**: [Twitter/X](https://twitter.com/Letta_AI), [LinkedIn](https://www.linkedin.com/company/letta-ai/), [YouTube](https://www.youtube.com/@letta-ai)
404
+
405
+ This SDK is generated programmatically. For SDK changes, please [open an issue](https://github.com/letta-ai/letta-python/issues).
406
+
407
+ README contributions are always welcome!
408
+
409
+ ## Resources
410
+
411
+ - [Documentation](https://docs.letta.com)
412
+ - [Python API Reference](./reference.md)
413
+ - [Example Applications](https://github.com/letta-ai/letta-chatbot-example)
414
+
415
+ ## License
416
+
417
+ MIT
418
+
419
+ ---
420
+
421
+ ***Legal notices**: By using Letta and related Letta services (such as the Letta endpoint or hosted service), you are agreeing to our [privacy policy](https://www.letta.com/privacy-policy) and [terms of service](https://www.letta.com/terms-of-service).*
422
+