letta-client 0.1.0__py3-none-any.whl → 0.1.2__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 (201) hide show
  1. letta/__init__.py +293 -0
  2. letta/agents/__init__.py +28 -0
  3. letta/agents/archival_memory/__init__.py +2 -0
  4. letta/agents/archival_memory/client.py +591 -0
  5. letta/agents/client.py +2166 -0
  6. letta/agents/context/__init__.py +2 -0
  7. letta/agents/context/client.py +145 -0
  8. letta/agents/memory/__init__.py +5 -0
  9. letta/agents/memory/client.py +149 -0
  10. letta/agents/memory/messages/__init__.py +2 -0
  11. letta/agents/memory/messages/client.py +147 -0
  12. letta/agents/memory_blocks/__init__.py +2 -0
  13. letta/agents/memory_blocks/client.py +364 -0
  14. letta/agents/messages/__init__.py +5 -0
  15. letta/agents/messages/client.py +787 -0
  16. letta/agents/messages/types/__init__.py +7 -0
  17. letta/agents/messages/types/letta_streaming_response.py +20 -0
  18. letta/agents/messages/types/messages_list_response.py +7 -0
  19. letta/agents/messages/types/messages_list_response_item.py +13 -0
  20. letta/agents/recall_memory/__init__.py +2 -0
  21. letta/agents/recall_memory/client.py +147 -0
  22. letta/agents/sources/__init__.py +2 -0
  23. letta/agents/sources/client.py +145 -0
  24. letta/agents/tools/__init__.py +2 -0
  25. letta/agents/tools/client.py +408 -0
  26. letta/agents/types/__init__.py +13 -0
  27. letta/agents/types/agents_create_version_response.py +22 -0
  28. letta/agents/types/agents_migrate_response.py +19 -0
  29. letta/agents/types/create_agent_request_tool_rules_item.py +9 -0
  30. letta/agents/types/update_agent_tool_rules_item.py +9 -0
  31. letta/blocks/__init__.py +2 -0
  32. letta/blocks/client.py +1054 -0
  33. letta/client.py +164 -0
  34. letta/core/__init__.py +47 -0
  35. letta/core/api_error.py +15 -0
  36. letta/core/client_wrapper.py +76 -0
  37. letta/core/datetime_utils.py +28 -0
  38. letta/core/file.py +67 -0
  39. letta/core/http_client.py +499 -0
  40. letta/core/jsonable_encoder.py +101 -0
  41. letta/core/pydantic_utilities.py +296 -0
  42. letta/core/query_encoder.py +58 -0
  43. letta/core/remove_none_from_dict.py +11 -0
  44. letta/core/request_options.py +35 -0
  45. letta/core/serialization.py +272 -0
  46. letta/environment.py +8 -0
  47. letta/errors/__init__.py +8 -0
  48. letta/errors/conflict_error.py +9 -0
  49. letta/errors/internal_server_error.py +9 -0
  50. letta/errors/not_found_error.py +9 -0
  51. letta/errors/unprocessable_entity_error.py +9 -0
  52. letta/health/__init__.py +2 -0
  53. letta/health/client.py +108 -0
  54. letta/jobs/__init__.py +2 -0
  55. letta/jobs/client.py +503 -0
  56. letta/models/__init__.py +2 -0
  57. letta/models/client.py +201 -0
  58. letta/sources/__init__.py +5 -0
  59. letta/sources/client.py +1154 -0
  60. letta/sources/files/__init__.py +2 -0
  61. letta/sources/files/client.py +436 -0
  62. letta/sources/passages/__init__.py +2 -0
  63. letta/sources/passages/client.py +145 -0
  64. letta/tools/__init__.py +2 -0
  65. letta/tools/client.py +1823 -0
  66. letta/types/__init__.py +263 -0
  67. letta/types/action_model.py +36 -0
  68. letta/types/action_parameters_model.py +26 -0
  69. letta/types/action_response_model.py +26 -0
  70. letta/types/agent_state.py +139 -0
  71. letta/types/agent_state_tool_rules_item.py +9 -0
  72. letta/types/agent_type.py +8 -0
  73. letta/types/app_auth_scheme.py +34 -0
  74. letta/types/app_auth_scheme_auth_mode.py +7 -0
  75. letta/types/app_model.py +44 -0
  76. letta/types/archival_memory_summary.py +22 -0
  77. letta/types/assistant_file.py +33 -0
  78. letta/types/assistant_message_input.py +23 -0
  79. letta/types/assistant_message_output.py +23 -0
  80. letta/types/auth_request.py +22 -0
  81. letta/types/auth_response.py +29 -0
  82. letta/types/auth_scheme_field.py +30 -0
  83. letta/types/block.py +91 -0
  84. letta/types/block_update.py +60 -0
  85. letta/types/chat_completion_request.py +49 -0
  86. letta/types/chat_completion_request_function_call.py +6 -0
  87. letta/types/chat_completion_request_messages_item.py +11 -0
  88. letta/types/chat_completion_request_stop.py +5 -0
  89. letta/types/chat_completion_request_tool_choice.py +8 -0
  90. letta/types/chat_completion_response.py +32 -0
  91. letta/types/child_tool_rule.py +33 -0
  92. letta/types/choice.py +25 -0
  93. letta/types/conditional_tool_rule.py +43 -0
  94. letta/types/conflict_error_body.py +21 -0
  95. letta/types/context_window_overview.py +105 -0
  96. letta/types/create_assistant_file_request.py +22 -0
  97. letta/types/create_assistant_request.py +57 -0
  98. letta/types/create_block.py +56 -0
  99. letta/types/delete_assistant_file_response.py +28 -0
  100. letta/types/delete_assistant_response.py +28 -0
  101. letta/types/e_2_b_sandbox_config.py +32 -0
  102. letta/types/embedding_config.py +72 -0
  103. letta/types/embedding_config_embedding_endpoint_type.py +26 -0
  104. letta/types/file_metadata.py +82 -0
  105. letta/types/function_call_input.py +19 -0
  106. letta/types/function_call_output.py +20 -0
  107. letta/types/function_schema.py +21 -0
  108. letta/types/health.py +24 -0
  109. letta/types/http_validation_error.py +20 -0
  110. letta/types/init_tool_rule.py +29 -0
  111. letta/types/internal_server_error_body.py +19 -0
  112. letta/types/job.py +79 -0
  113. letta/types/job_status.py +5 -0
  114. letta/types/letta_request.py +33 -0
  115. letta/types/letta_response.py +125 -0
  116. letta/types/letta_response_assistant_message.py +23 -0
  117. letta/types/letta_response_letta_usage_statistics.py +47 -0
  118. letta/types/letta_response_reasoning_message.py +32 -0
  119. letta/types/letta_response_system_message.py +32 -0
  120. letta/types/letta_response_tool_call.py +21 -0
  121. letta/types/letta_response_tool_call_delta.py +21 -0
  122. letta/types/letta_response_tool_call_message.py +33 -0
  123. letta/types/letta_response_tool_call_message_tool_call.py +9 -0
  124. letta/types/letta_response_tool_call_message_tool_call_one.py +21 -0
  125. letta/types/letta_response_tool_call_message_tool_call_zero.py +21 -0
  126. letta/types/letta_response_tool_return_message.py +41 -0
  127. letta/types/letta_response_tool_return_message_status.py +5 -0
  128. letta/types/letta_response_usage_message.py +40 -0
  129. letta/types/letta_response_usage_message_usage.py +47 -0
  130. letta/types/letta_response_user_message.py +32 -0
  131. letta/types/letta_schemas_letta_message_tool_call.py +21 -0
  132. letta/types/letta_schemas_message_message.py +103 -0
  133. letta/types/letta_schemas_openai_chat_completion_request_tool.py +21 -0
  134. letta/types/letta_schemas_openai_chat_completion_request_tool_call.py +24 -0
  135. letta/types/letta_schemas_openai_chat_completion_request_tool_call_function.py +20 -0
  136. letta/types/letta_schemas_openai_chat_completion_response_message.py +24 -0
  137. letta/types/letta_schemas_openai_chat_completion_response_tool_call.py +22 -0
  138. letta/types/letta_schemas_openai_chat_completions_tool_call_function.py +27 -0
  139. letta/types/letta_schemas_openai_chat_completions_tool_call_input.py +29 -0
  140. letta/types/letta_schemas_openai_chat_completions_tool_call_output.py +29 -0
  141. letta/types/letta_schemas_tool_tool.py +88 -0
  142. letta/types/letta_usage_statistics.py +47 -0
  143. letta/types/llm_config.py +60 -0
  144. letta/types/llm_config_model_endpoint_type.py +26 -0
  145. letta/types/local_sandbox_config.py +32 -0
  146. letta/types/log_prob_token.py +21 -0
  147. letta/types/memory.py +32 -0
  148. letta/types/message_content_log_prob.py +23 -0
  149. letta/types/message_create.py +37 -0
  150. letta/types/message_create_role.py +5 -0
  151. letta/types/message_role.py +5 -0
  152. letta/types/not_found_error_body.py +20 -0
  153. letta/types/not_found_error_body_message.py +11 -0
  154. letta/types/open_ai_assistant.py +67 -0
  155. letta/types/organization.py +33 -0
  156. letta/types/organization_create.py +22 -0
  157. letta/types/passage.py +107 -0
  158. letta/types/reasoning_message.py +32 -0
  159. letta/types/recall_memory_summary.py +22 -0
  160. letta/types/response_format.py +19 -0
  161. letta/types/sandbox_config.py +59 -0
  162. letta/types/sandbox_config_create.py +23 -0
  163. letta/types/sandbox_config_create_config.py +7 -0
  164. letta/types/sandbox_config_update.py +27 -0
  165. letta/types/sandbox_config_update_config.py +7 -0
  166. letta/types/sandbox_environment_variable.py +68 -0
  167. letta/types/sandbox_environment_variable_create.py +32 -0
  168. letta/types/sandbox_environment_variable_update.py +36 -0
  169. letta/types/sandbox_type.py +5 -0
  170. letta/types/source.py +85 -0
  171. letta/types/system_message_input.py +21 -0
  172. letta/types/system_message_output.py +32 -0
  173. letta/types/terminal_tool_rule.py +29 -0
  174. letta/types/tool_call_delta.py +21 -0
  175. letta/types/tool_call_function_output.py +27 -0
  176. letta/types/tool_call_message.py +33 -0
  177. letta/types/tool_call_message_tool_call.py +7 -0
  178. letta/types/tool_create.py +57 -0
  179. letta/types/tool_function_choice.py +21 -0
  180. letta/types/tool_input.py +21 -0
  181. letta/types/tool_message.py +21 -0
  182. letta/types/tool_return_message.py +41 -0
  183. letta/types/tool_return_message_status.py +5 -0
  184. letta/types/tool_rule_type.py +10 -0
  185. letta/types/usage_message.py +31 -0
  186. letta/types/usage_statistics.py +21 -0
  187. letta/types/user.py +57 -0
  188. letta/types/user_create.py +27 -0
  189. letta/types/user_message_input.py +22 -0
  190. letta/types/user_message_input_content.py +5 -0
  191. letta/types/user_message_output.py +32 -0
  192. letta/types/user_update.py +32 -0
  193. letta/types/validation_error.py +22 -0
  194. letta/types/validation_error_loc_item.py +5 -0
  195. letta/version.py +3 -0
  196. letta_client-0.1.2.dist-info/METADATA +189 -0
  197. letta_client-0.1.2.dist-info/RECORD +199 -0
  198. {letta_client-0.1.0.dist-info → letta_client-0.1.2.dist-info}/WHEEL +1 -1
  199. letta_client-0.1.0.dist-info/METADATA +0 -15
  200. letta_client-0.1.0.dist-info/RECORD +0 -4
  201. /letta_client/__init__.py → /letta/py.typed +0 -0
letta/agents/client.py ADDED
@@ -0,0 +1,2166 @@
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 .context.client import ContextClient
6
+ from .tools.client import ToolsClient
7
+ from .sources.client import SourcesClient
8
+ from .memory.client import MemoryClient
9
+ from .memory_blocks.client import MemoryBlocksClient
10
+ from .recall_memory.client import RecallMemoryClient
11
+ from .archival_memory.client import ArchivalMemoryClient
12
+ from .messages.client import MessagesClient
13
+ from ..core.request_options import RequestOptions
14
+ from ..types.agent_state import AgentState
15
+ from ..core.pydantic_utilities import parse_obj_as
16
+ from ..errors.unprocessable_entity_error import UnprocessableEntityError
17
+ from ..types.http_validation_error import HttpValidationError
18
+ from json.decoder import JSONDecodeError
19
+ from ..core.api_error import ApiError
20
+ from ..types.create_block import CreateBlock
21
+ from .types.create_agent_request_tool_rules_item import CreateAgentRequestToolRulesItem
22
+ from ..types.agent_type import AgentType
23
+ from ..types.llm_config import LlmConfig
24
+ from ..types.embedding_config import EmbeddingConfig
25
+ from ..types.message_create import MessageCreate
26
+ from ..core.serialization import convert_and_respect_annotation_metadata
27
+ from ..core.jsonable_encoder import jsonable_encoder
28
+ from .types.update_agent_tool_rules_item import UpdateAgentToolRulesItem
29
+ from ..types.block import Block
30
+ from ..types.job import Job
31
+ from .types.agents_create_version_response import AgentsCreateVersionResponse
32
+ from ..errors.not_found_error import NotFoundError
33
+ from ..errors.internal_server_error import InternalServerError
34
+ from .types.agents_migrate_response import AgentsMigrateResponse
35
+ from ..errors.conflict_error import ConflictError
36
+ from ..types.conflict_error_body import ConflictErrorBody
37
+ from ..core.client_wrapper import AsyncClientWrapper
38
+ from .context.client import AsyncContextClient
39
+ from .tools.client import AsyncToolsClient
40
+ from .sources.client import AsyncSourcesClient
41
+ from .memory.client import AsyncMemoryClient
42
+ from .memory_blocks.client import AsyncMemoryBlocksClient
43
+ from .recall_memory.client import AsyncRecallMemoryClient
44
+ from .archival_memory.client import AsyncArchivalMemoryClient
45
+ from .messages.client import AsyncMessagesClient
46
+
47
+ # this is used as the default value for optional parameters
48
+ OMIT = typing.cast(typing.Any, ...)
49
+
50
+
51
+ class AgentsClient:
52
+ def __init__(self, *, client_wrapper: SyncClientWrapper):
53
+ self._client_wrapper = client_wrapper
54
+ self.context = ContextClient(client_wrapper=self._client_wrapper)
55
+ self.tools = ToolsClient(client_wrapper=self._client_wrapper)
56
+ self.sources = SourcesClient(client_wrapper=self._client_wrapper)
57
+ self.memory = MemoryClient(client_wrapper=self._client_wrapper)
58
+ self.memory_blocks = MemoryBlocksClient(client_wrapper=self._client_wrapper)
59
+ self.recall_memory = RecallMemoryClient(client_wrapper=self._client_wrapper)
60
+ self.archival_memory = ArchivalMemoryClient(client_wrapper=self._client_wrapper)
61
+ self.messages = MessagesClient(client_wrapper=self._client_wrapper)
62
+
63
+ def list(
64
+ self,
65
+ *,
66
+ name: typing.Optional[str] = None,
67
+ tags: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
68
+ match_all_tags: typing.Optional[bool] = None,
69
+ request_options: typing.Optional[RequestOptions] = None,
70
+ ) -> typing.List[AgentState]:
71
+ """
72
+ List all agents associated with a given user.
73
+ This endpoint retrieves a list of all agents and their configurations associated with the specified user ID.
74
+
75
+ Parameters
76
+ ----------
77
+ name : typing.Optional[str]
78
+ Name of the agent
79
+
80
+ tags : typing.Optional[typing.Union[str, typing.Sequence[str]]]
81
+ List of tags to filter agents by
82
+
83
+ match_all_tags : typing.Optional[bool]
84
+ If True, only returns agents that match ALL given tags. Otherwise, return agents that have ANY of the passed in tags.
85
+
86
+ request_options : typing.Optional[RequestOptions]
87
+ Request-specific configuration.
88
+
89
+ Returns
90
+ -------
91
+ typing.List[AgentState]
92
+ Successful Response
93
+
94
+ Examples
95
+ --------
96
+ from letta import Letta
97
+
98
+ client = Letta(
99
+ token="YOUR_TOKEN",
100
+ )
101
+ client.agents.list()
102
+ """
103
+ _response = self._client_wrapper.httpx_client.request(
104
+ "v1/agents/",
105
+ method="GET",
106
+ params={
107
+ "name": name,
108
+ "tags": tags,
109
+ "match_all_tags": match_all_tags,
110
+ },
111
+ request_options=request_options,
112
+ )
113
+ try:
114
+ if 200 <= _response.status_code < 300:
115
+ return typing.cast(
116
+ typing.List[AgentState],
117
+ parse_obj_as(
118
+ type_=typing.List[AgentState], # type: ignore
119
+ object_=_response.json(),
120
+ ),
121
+ )
122
+ if _response.status_code == 422:
123
+ raise UnprocessableEntityError(
124
+ typing.cast(
125
+ HttpValidationError,
126
+ parse_obj_as(
127
+ type_=HttpValidationError, # type: ignore
128
+ object_=_response.json(),
129
+ ),
130
+ )
131
+ )
132
+ _response_json = _response.json()
133
+ except JSONDecodeError:
134
+ raise ApiError(status_code=_response.status_code, body=_response.text)
135
+ raise ApiError(status_code=_response.status_code, body=_response_json)
136
+
137
+ def create(
138
+ self,
139
+ *,
140
+ memory_blocks: typing.Sequence[CreateBlock],
141
+ name: typing.Optional[str] = OMIT,
142
+ tools: typing.Optional[typing.Sequence[str]] = OMIT,
143
+ tool_ids: typing.Optional[typing.Sequence[str]] = OMIT,
144
+ source_ids: typing.Optional[typing.Sequence[str]] = OMIT,
145
+ block_ids: typing.Optional[typing.Sequence[str]] = OMIT,
146
+ tool_rules: typing.Optional[typing.Sequence[CreateAgentRequestToolRulesItem]] = OMIT,
147
+ tags: typing.Optional[typing.Sequence[str]] = OMIT,
148
+ system: typing.Optional[str] = OMIT,
149
+ agent_type: typing.Optional[AgentType] = OMIT,
150
+ llm_config: typing.Optional[LlmConfig] = OMIT,
151
+ embedding_config: typing.Optional[EmbeddingConfig] = OMIT,
152
+ initial_message_sequence: typing.Optional[typing.Sequence[MessageCreate]] = OMIT,
153
+ include_base_tools: typing.Optional[bool] = OMIT,
154
+ description: typing.Optional[str] = OMIT,
155
+ metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
156
+ llm: typing.Optional[str] = OMIT,
157
+ embedding: typing.Optional[str] = OMIT,
158
+ context_window_limit: typing.Optional[int] = OMIT,
159
+ embedding_chunk_size: typing.Optional[int] = OMIT,
160
+ user_id: typing.Optional[str] = OMIT,
161
+ request_options: typing.Optional[RequestOptions] = None,
162
+ ) -> AgentState:
163
+ """
164
+ Create a new agent with the specified configuration.
165
+
166
+ Parameters
167
+ ----------
168
+ memory_blocks : typing.Sequence[CreateBlock]
169
+ The blocks to create in the agent's in-context memory.
170
+
171
+ name : typing.Optional[str]
172
+ The name of the agent.
173
+
174
+ tools : typing.Optional[typing.Sequence[str]]
175
+ The tools used by the agent.
176
+
177
+ tool_ids : typing.Optional[typing.Sequence[str]]
178
+ The ids of the tools used by the agent.
179
+
180
+ source_ids : typing.Optional[typing.Sequence[str]]
181
+ The ids of the sources used by the agent.
182
+
183
+ block_ids : typing.Optional[typing.Sequence[str]]
184
+ The ids of the blocks used by the agent.
185
+
186
+ tool_rules : typing.Optional[typing.Sequence[CreateAgentRequestToolRulesItem]]
187
+ The tool rules governing the agent.
188
+
189
+ tags : typing.Optional[typing.Sequence[str]]
190
+ The tags associated with the agent.
191
+
192
+ system : typing.Optional[str]
193
+ The system prompt used by the agent.
194
+
195
+ agent_type : typing.Optional[AgentType]
196
+ The type of agent.
197
+
198
+ llm_config : typing.Optional[LlmConfig]
199
+ The LLM configuration used by the agent.
200
+
201
+ embedding_config : typing.Optional[EmbeddingConfig]
202
+ The embedding configuration used by the agent.
203
+
204
+ initial_message_sequence : typing.Optional[typing.Sequence[MessageCreate]]
205
+ The initial set of messages to put in the agent's in-context memory.
206
+
207
+ include_base_tools : typing.Optional[bool]
208
+ The LLM configuration used by the agent.
209
+
210
+ description : typing.Optional[str]
211
+ The description of the agent.
212
+
213
+ metadata : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
214
+ The metadata of the agent.
215
+
216
+ llm : typing.Optional[str]
217
+ The LLM configuration handle used by the agent, specified in the format provider/model-name, as an alternative to specifying llm_config.
218
+
219
+ embedding : typing.Optional[str]
220
+ The embedding configuration handle used by the agent, specified in the format provider/model-name.
221
+
222
+ context_window_limit : typing.Optional[int]
223
+ The context window limit used by the agent.
224
+
225
+ embedding_chunk_size : typing.Optional[int]
226
+ The embedding chunk size used by the agent.
227
+
228
+ user_id : typing.Optional[str]
229
+
230
+ request_options : typing.Optional[RequestOptions]
231
+ Request-specific configuration.
232
+
233
+ Returns
234
+ -------
235
+ AgentState
236
+ Successful Response
237
+
238
+ Examples
239
+ --------
240
+ from letta import CreateBlock, Letta
241
+
242
+ client = Letta(
243
+ token="YOUR_TOKEN",
244
+ )
245
+ client.agents.create(
246
+ memory_blocks=[
247
+ CreateBlock(
248
+ value="value",
249
+ label="label",
250
+ )
251
+ ],
252
+ )
253
+ """
254
+ _response = self._client_wrapper.httpx_client.request(
255
+ "v1/agents/",
256
+ method="POST",
257
+ json={
258
+ "name": name,
259
+ "memory_blocks": convert_and_respect_annotation_metadata(
260
+ object_=memory_blocks, annotation=typing.Sequence[CreateBlock], direction="write"
261
+ ),
262
+ "tools": tools,
263
+ "tool_ids": tool_ids,
264
+ "source_ids": source_ids,
265
+ "block_ids": block_ids,
266
+ "tool_rules": convert_and_respect_annotation_metadata(
267
+ object_=tool_rules, annotation=typing.Sequence[CreateAgentRequestToolRulesItem], direction="write"
268
+ ),
269
+ "tags": tags,
270
+ "system": system,
271
+ "agent_type": agent_type,
272
+ "llm_config": convert_and_respect_annotation_metadata(
273
+ object_=llm_config, annotation=LlmConfig, direction="write"
274
+ ),
275
+ "embedding_config": convert_and_respect_annotation_metadata(
276
+ object_=embedding_config, annotation=EmbeddingConfig, direction="write"
277
+ ),
278
+ "initial_message_sequence": convert_and_respect_annotation_metadata(
279
+ object_=initial_message_sequence, annotation=typing.Sequence[MessageCreate], direction="write"
280
+ ),
281
+ "include_base_tools": include_base_tools,
282
+ "description": description,
283
+ "metadata_": metadata,
284
+ "llm": llm,
285
+ "embedding": embedding,
286
+ "context_window_limit": context_window_limit,
287
+ "embedding_chunk_size": embedding_chunk_size,
288
+ "user_id": user_id,
289
+ },
290
+ headers={
291
+ "content-type": "application/json",
292
+ },
293
+ request_options=request_options,
294
+ omit=OMIT,
295
+ )
296
+ try:
297
+ if 200 <= _response.status_code < 300:
298
+ return typing.cast(
299
+ AgentState,
300
+ parse_obj_as(
301
+ type_=AgentState, # type: ignore
302
+ object_=_response.json(),
303
+ ),
304
+ )
305
+ if _response.status_code == 422:
306
+ raise UnprocessableEntityError(
307
+ typing.cast(
308
+ HttpValidationError,
309
+ parse_obj_as(
310
+ type_=HttpValidationError, # type: ignore
311
+ object_=_response.json(),
312
+ ),
313
+ )
314
+ )
315
+ _response_json = _response.json()
316
+ except JSONDecodeError:
317
+ raise ApiError(status_code=_response.status_code, body=_response.text)
318
+ raise ApiError(status_code=_response.status_code, body=_response_json)
319
+
320
+ def get(self, agent_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> AgentState:
321
+ """
322
+ Get the state of the agent.
323
+
324
+ Parameters
325
+ ----------
326
+ agent_id : str
327
+
328
+ request_options : typing.Optional[RequestOptions]
329
+ Request-specific configuration.
330
+
331
+ Returns
332
+ -------
333
+ AgentState
334
+ Successful Response
335
+
336
+ Examples
337
+ --------
338
+ from letta import Letta
339
+
340
+ client = Letta(
341
+ token="YOUR_TOKEN",
342
+ )
343
+ client.agents.get(
344
+ agent_id="agent_id",
345
+ )
346
+ """
347
+ _response = self._client_wrapper.httpx_client.request(
348
+ f"v1/agents/{jsonable_encoder(agent_id)}",
349
+ method="GET",
350
+ request_options=request_options,
351
+ )
352
+ try:
353
+ if 200 <= _response.status_code < 300:
354
+ return typing.cast(
355
+ AgentState,
356
+ parse_obj_as(
357
+ type_=AgentState, # type: ignore
358
+ object_=_response.json(),
359
+ ),
360
+ )
361
+ if _response.status_code == 422:
362
+ raise UnprocessableEntityError(
363
+ typing.cast(
364
+ HttpValidationError,
365
+ parse_obj_as(
366
+ type_=HttpValidationError, # type: ignore
367
+ object_=_response.json(),
368
+ ),
369
+ )
370
+ )
371
+ _response_json = _response.json()
372
+ except JSONDecodeError:
373
+ raise ApiError(status_code=_response.status_code, body=_response.text)
374
+ raise ApiError(status_code=_response.status_code, body=_response_json)
375
+
376
+ def delete(self, agent_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> AgentState:
377
+ """
378
+ Delete an agent.
379
+
380
+ Parameters
381
+ ----------
382
+ agent_id : str
383
+
384
+ request_options : typing.Optional[RequestOptions]
385
+ Request-specific configuration.
386
+
387
+ Returns
388
+ -------
389
+ AgentState
390
+ Successful Response
391
+
392
+ Examples
393
+ --------
394
+ from letta import Letta
395
+
396
+ client = Letta(
397
+ token="YOUR_TOKEN",
398
+ )
399
+ client.agents.delete(
400
+ agent_id="agent_id",
401
+ )
402
+ """
403
+ _response = self._client_wrapper.httpx_client.request(
404
+ f"v1/agents/{jsonable_encoder(agent_id)}",
405
+ method="DELETE",
406
+ request_options=request_options,
407
+ )
408
+ try:
409
+ if 200 <= _response.status_code < 300:
410
+ return typing.cast(
411
+ AgentState,
412
+ parse_obj_as(
413
+ type_=AgentState, # type: ignore
414
+ object_=_response.json(),
415
+ ),
416
+ )
417
+ if _response.status_code == 422:
418
+ raise UnprocessableEntityError(
419
+ typing.cast(
420
+ HttpValidationError,
421
+ parse_obj_as(
422
+ type_=HttpValidationError, # type: ignore
423
+ object_=_response.json(),
424
+ ),
425
+ )
426
+ )
427
+ _response_json = _response.json()
428
+ except JSONDecodeError:
429
+ raise ApiError(status_code=_response.status_code, body=_response.text)
430
+ raise ApiError(status_code=_response.status_code, body=_response_json)
431
+
432
+ def update(
433
+ self,
434
+ agent_id: str,
435
+ *,
436
+ name: typing.Optional[str] = OMIT,
437
+ tool_ids: typing.Optional[typing.Sequence[str]] = OMIT,
438
+ source_ids: typing.Optional[typing.Sequence[str]] = OMIT,
439
+ block_ids: typing.Optional[typing.Sequence[str]] = OMIT,
440
+ tags: typing.Optional[typing.Sequence[str]] = OMIT,
441
+ system: typing.Optional[str] = OMIT,
442
+ tool_rules: typing.Optional[typing.Sequence[UpdateAgentToolRulesItem]] = OMIT,
443
+ llm_config: typing.Optional[LlmConfig] = OMIT,
444
+ embedding_config: typing.Optional[EmbeddingConfig] = OMIT,
445
+ message_ids: typing.Optional[typing.Sequence[str]] = OMIT,
446
+ description: typing.Optional[str] = OMIT,
447
+ metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
448
+ request_options: typing.Optional[RequestOptions] = None,
449
+ ) -> AgentState:
450
+ """
451
+ Update an exsiting agent
452
+
453
+ Parameters
454
+ ----------
455
+ agent_id : str
456
+
457
+ name : typing.Optional[str]
458
+ The name of the agent.
459
+
460
+ tool_ids : typing.Optional[typing.Sequence[str]]
461
+ The ids of the tools used by the agent.
462
+
463
+ source_ids : typing.Optional[typing.Sequence[str]]
464
+ The ids of the sources used by the agent.
465
+
466
+ block_ids : typing.Optional[typing.Sequence[str]]
467
+ The ids of the blocks used by the agent.
468
+
469
+ tags : typing.Optional[typing.Sequence[str]]
470
+ The tags associated with the agent.
471
+
472
+ system : typing.Optional[str]
473
+ The system prompt used by the agent.
474
+
475
+ tool_rules : typing.Optional[typing.Sequence[UpdateAgentToolRulesItem]]
476
+ The tool rules governing the agent.
477
+
478
+ llm_config : typing.Optional[LlmConfig]
479
+ The LLM configuration used by the agent.
480
+
481
+ embedding_config : typing.Optional[EmbeddingConfig]
482
+ The embedding configuration used by the agent.
483
+
484
+ message_ids : typing.Optional[typing.Sequence[str]]
485
+ The ids of the messages in the agent's in-context memory.
486
+
487
+ description : typing.Optional[str]
488
+ The description of the agent.
489
+
490
+ metadata : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
491
+ The metadata of the agent.
492
+
493
+ request_options : typing.Optional[RequestOptions]
494
+ Request-specific configuration.
495
+
496
+ Returns
497
+ -------
498
+ AgentState
499
+ Successful Response
500
+
501
+ Examples
502
+ --------
503
+ from letta import Letta
504
+
505
+ client = Letta(
506
+ token="YOUR_TOKEN",
507
+ )
508
+ client.agents.update(
509
+ agent_id="agent_id",
510
+ )
511
+ """
512
+ _response = self._client_wrapper.httpx_client.request(
513
+ f"v1/agents/{jsonable_encoder(agent_id)}",
514
+ method="PATCH",
515
+ json={
516
+ "name": name,
517
+ "tool_ids": tool_ids,
518
+ "source_ids": source_ids,
519
+ "block_ids": block_ids,
520
+ "tags": tags,
521
+ "system": system,
522
+ "tool_rules": convert_and_respect_annotation_metadata(
523
+ object_=tool_rules, annotation=typing.Sequence[UpdateAgentToolRulesItem], direction="write"
524
+ ),
525
+ "llm_config": convert_and_respect_annotation_metadata(
526
+ object_=llm_config, annotation=LlmConfig, direction="write"
527
+ ),
528
+ "embedding_config": convert_and_respect_annotation_metadata(
529
+ object_=embedding_config, annotation=EmbeddingConfig, direction="write"
530
+ ),
531
+ "message_ids": message_ids,
532
+ "description": description,
533
+ "metadata_": metadata,
534
+ },
535
+ headers={
536
+ "content-type": "application/json",
537
+ },
538
+ request_options=request_options,
539
+ omit=OMIT,
540
+ )
541
+ try:
542
+ if 200 <= _response.status_code < 300:
543
+ return typing.cast(
544
+ AgentState,
545
+ parse_obj_as(
546
+ type_=AgentState, # type: ignore
547
+ object_=_response.json(),
548
+ ),
549
+ )
550
+ if _response.status_code == 422:
551
+ raise UnprocessableEntityError(
552
+ typing.cast(
553
+ HttpValidationError,
554
+ parse_obj_as(
555
+ type_=HttpValidationError, # type: ignore
556
+ object_=_response.json(),
557
+ ),
558
+ )
559
+ )
560
+ _response_json = _response.json()
561
+ except JSONDecodeError:
562
+ raise ApiError(status_code=_response.status_code, body=_response.text)
563
+ raise ApiError(status_code=_response.status_code, body=_response_json)
564
+
565
+ def get_agent_memory_block(
566
+ self, agent_id: str, block_label: str, *, request_options: typing.Optional[RequestOptions] = None
567
+ ) -> Block:
568
+ """
569
+ Retrieve a memory block from an agent.
570
+
571
+ Parameters
572
+ ----------
573
+ agent_id : str
574
+
575
+ block_label : str
576
+
577
+ request_options : typing.Optional[RequestOptions]
578
+ Request-specific configuration.
579
+
580
+ Returns
581
+ -------
582
+ Block
583
+ Successful Response
584
+
585
+ Examples
586
+ --------
587
+ from letta import Letta
588
+
589
+ client = Letta(
590
+ token="YOUR_TOKEN",
591
+ )
592
+ client.agents.get_agent_memory_block(
593
+ agent_id="agent_id",
594
+ block_label="block_label",
595
+ )
596
+ """
597
+ _response = self._client_wrapper.httpx_client.request(
598
+ f"v1/agents/{jsonable_encoder(agent_id)}/memory/block/{jsonable_encoder(block_label)}",
599
+ method="GET",
600
+ request_options=request_options,
601
+ )
602
+ try:
603
+ if 200 <= _response.status_code < 300:
604
+ return typing.cast(
605
+ Block,
606
+ parse_obj_as(
607
+ type_=Block, # type: ignore
608
+ object_=_response.json(),
609
+ ),
610
+ )
611
+ if _response.status_code == 422:
612
+ raise UnprocessableEntityError(
613
+ typing.cast(
614
+ HttpValidationError,
615
+ parse_obj_as(
616
+ type_=HttpValidationError, # type: ignore
617
+ object_=_response.json(),
618
+ ),
619
+ )
620
+ )
621
+ _response_json = _response.json()
622
+ except JSONDecodeError:
623
+ raise ApiError(status_code=_response.status_code, body=_response.text)
624
+ raise ApiError(status_code=_response.status_code, body=_response_json)
625
+
626
+ def update_agent_memory_block_by_label(
627
+ self,
628
+ agent_id: str,
629
+ block_label: str,
630
+ *,
631
+ value: typing.Optional[str] = OMIT,
632
+ limit: typing.Optional[int] = OMIT,
633
+ name: typing.Optional[str] = OMIT,
634
+ is_template: typing.Optional[bool] = OMIT,
635
+ label: typing.Optional[str] = OMIT,
636
+ description: typing.Optional[str] = OMIT,
637
+ metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
638
+ request_options: typing.Optional[RequestOptions] = None,
639
+ ) -> Block:
640
+ """
641
+ Removes a memory block from an agent by unlnking it. If the block is not linked to any other agent, it is deleted.
642
+
643
+ Parameters
644
+ ----------
645
+ agent_id : str
646
+
647
+ block_label : str
648
+
649
+ value : typing.Optional[str]
650
+ Value of the block.
651
+
652
+ limit : typing.Optional[int]
653
+ Character limit of the block.
654
+
655
+ name : typing.Optional[str]
656
+ Name of the block if it is a template.
657
+
658
+ is_template : typing.Optional[bool]
659
+ Whether the block is a template (e.g. saved human/persona options).
660
+
661
+ label : typing.Optional[str]
662
+ Label of the block (e.g. 'human', 'persona') in the context window.
663
+
664
+ description : typing.Optional[str]
665
+ Description of the block.
666
+
667
+ metadata : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
668
+ Metadata of the block.
669
+
670
+ request_options : typing.Optional[RequestOptions]
671
+ Request-specific configuration.
672
+
673
+ Returns
674
+ -------
675
+ Block
676
+ Successful Response
677
+
678
+ Examples
679
+ --------
680
+ from letta import Letta
681
+
682
+ client = Letta(
683
+ token="YOUR_TOKEN",
684
+ )
685
+ client.agents.update_agent_memory_block_by_label(
686
+ agent_id="agent_id",
687
+ block_label="block_label",
688
+ )
689
+ """
690
+ _response = self._client_wrapper.httpx_client.request(
691
+ f"v1/agents/{jsonable_encoder(agent_id)}/memory/block/{jsonable_encoder(block_label)}",
692
+ method="PATCH",
693
+ json={
694
+ "value": value,
695
+ "limit": limit,
696
+ "name": name,
697
+ "is_template": is_template,
698
+ "label": label,
699
+ "description": description,
700
+ "metadata_": metadata,
701
+ },
702
+ request_options=request_options,
703
+ omit=OMIT,
704
+ )
705
+ try:
706
+ if 200 <= _response.status_code < 300:
707
+ return typing.cast(
708
+ Block,
709
+ parse_obj_as(
710
+ type_=Block, # type: ignore
711
+ object_=_response.json(),
712
+ ),
713
+ )
714
+ if _response.status_code == 422:
715
+ raise UnprocessableEntityError(
716
+ typing.cast(
717
+ HttpValidationError,
718
+ parse_obj_as(
719
+ type_=HttpValidationError, # type: ignore
720
+ object_=_response.json(),
721
+ ),
722
+ )
723
+ )
724
+ _response_json = _response.json()
725
+ except JSONDecodeError:
726
+ raise ApiError(status_code=_response.status_code, body=_response.text)
727
+ raise ApiError(status_code=_response.status_code, body=_response_json)
728
+
729
+ def get_agent_memory_blocks(
730
+ self, agent_id: str, *, request_options: typing.Optional[RequestOptions] = None
731
+ ) -> typing.List[Block]:
732
+ """
733
+ Retrieve the memory blocks of a specific agent.
734
+
735
+ Parameters
736
+ ----------
737
+ agent_id : str
738
+
739
+ request_options : typing.Optional[RequestOptions]
740
+ Request-specific configuration.
741
+
742
+ Returns
743
+ -------
744
+ typing.List[Block]
745
+ Successful Response
746
+
747
+ Examples
748
+ --------
749
+ from letta import Letta
750
+
751
+ client = Letta(
752
+ token="YOUR_TOKEN",
753
+ )
754
+ client.agents.get_agent_memory_blocks(
755
+ agent_id="agent_id",
756
+ )
757
+ """
758
+ _response = self._client_wrapper.httpx_client.request(
759
+ f"v1/agents/{jsonable_encoder(agent_id)}/memory/block",
760
+ method="GET",
761
+ request_options=request_options,
762
+ )
763
+ try:
764
+ if 200 <= _response.status_code < 300:
765
+ return typing.cast(
766
+ typing.List[Block],
767
+ parse_obj_as(
768
+ type_=typing.List[Block], # type: ignore
769
+ object_=_response.json(),
770
+ ),
771
+ )
772
+ if _response.status_code == 422:
773
+ raise UnprocessableEntityError(
774
+ typing.cast(
775
+ HttpValidationError,
776
+ parse_obj_as(
777
+ type_=HttpValidationError, # type: ignore
778
+ object_=_response.json(),
779
+ ),
780
+ )
781
+ )
782
+ _response_json = _response.json()
783
+ except JSONDecodeError:
784
+ raise ApiError(status_code=_response.status_code, body=_response.text)
785
+ raise ApiError(status_code=_response.status_code, body=_response_json)
786
+
787
+ def create_agent_message_async(
788
+ self,
789
+ agent_id: str,
790
+ *,
791
+ messages: typing.Sequence[MessageCreate],
792
+ assistant_message_tool_name: typing.Optional[str] = OMIT,
793
+ assistant_message_tool_kwarg: typing.Optional[str] = OMIT,
794
+ request_options: typing.Optional[RequestOptions] = None,
795
+ ) -> Job:
796
+ """
797
+ Asynchronously process a user message and return a job ID.
798
+ The actual processing happens in the background, and the status can be checked using the job ID.
799
+
800
+ Parameters
801
+ ----------
802
+ agent_id : str
803
+
804
+ messages : typing.Sequence[MessageCreate]
805
+ The messages to be sent to the agent.
806
+
807
+ assistant_message_tool_name : typing.Optional[str]
808
+ The name of the designated message tool.
809
+
810
+ assistant_message_tool_kwarg : typing.Optional[str]
811
+ The name of the message argument in the designated message tool.
812
+
813
+ request_options : typing.Optional[RequestOptions]
814
+ Request-specific configuration.
815
+
816
+ Returns
817
+ -------
818
+ Job
819
+ Successful Response
820
+
821
+ Examples
822
+ --------
823
+ from letta import Letta, MessageCreate
824
+
825
+ client = Letta(
826
+ token="YOUR_TOKEN",
827
+ )
828
+ client.agents.create_agent_message_async(
829
+ agent_id="agent_id",
830
+ messages=[
831
+ MessageCreate(
832
+ role="user",
833
+ text="text",
834
+ )
835
+ ],
836
+ )
837
+ """
838
+ _response = self._client_wrapper.httpx_client.request(
839
+ f"v1/agents/{jsonable_encoder(agent_id)}/messages/async",
840
+ method="POST",
841
+ json={
842
+ "messages": convert_and_respect_annotation_metadata(
843
+ object_=messages, annotation=typing.Sequence[MessageCreate], direction="write"
844
+ ),
845
+ "assistant_message_tool_name": assistant_message_tool_name,
846
+ "assistant_message_tool_kwarg": assistant_message_tool_kwarg,
847
+ },
848
+ request_options=request_options,
849
+ omit=OMIT,
850
+ )
851
+ try:
852
+ if 200 <= _response.status_code < 300:
853
+ return typing.cast(
854
+ Job,
855
+ parse_obj_as(
856
+ type_=Job, # type: ignore
857
+ object_=_response.json(),
858
+ ),
859
+ )
860
+ if _response.status_code == 422:
861
+ raise UnprocessableEntityError(
862
+ typing.cast(
863
+ HttpValidationError,
864
+ parse_obj_as(
865
+ type_=HttpValidationError, # type: ignore
866
+ object_=_response.json(),
867
+ ),
868
+ )
869
+ )
870
+ _response_json = _response.json()
871
+ except JSONDecodeError:
872
+ raise ApiError(status_code=_response.status_code, body=_response.text)
873
+ raise ApiError(status_code=_response.status_code, body=_response_json)
874
+
875
+ def create_version(
876
+ self,
877
+ agent_id: str,
878
+ *,
879
+ return_agent_id: typing.Optional[bool] = None,
880
+ migrate_deployed_agents: typing.Optional[bool] = OMIT,
881
+ request_options: typing.Optional[RequestOptions] = None,
882
+ ) -> AgentsCreateVersionResponse:
883
+ """
884
+ Creates a versioned version of an agent
885
+
886
+ Parameters
887
+ ----------
888
+ agent_id : str
889
+ The agent ID of the agent to migrate, if this agent is not a template, it will create a agent template from the agent provided as well
890
+
891
+ return_agent_id : typing.Optional[bool]
892
+
893
+ migrate_deployed_agents : typing.Optional[bool]
894
+
895
+ request_options : typing.Optional[RequestOptions]
896
+ Request-specific configuration.
897
+
898
+ Returns
899
+ -------
900
+ AgentsCreateVersionResponse
901
+ 201
902
+
903
+ Examples
904
+ --------
905
+ from letta import Letta
906
+
907
+ client = Letta(
908
+ token="YOUR_TOKEN",
909
+ )
910
+ client.agents.create_version(
911
+ agent_id="agent_id",
912
+ )
913
+ """
914
+ _response = self._client_wrapper.httpx_client.request(
915
+ f"v1/agents/{jsonable_encoder(agent_id)}/version-template",
916
+ method="POST",
917
+ params={
918
+ "returnAgentId": return_agent_id,
919
+ },
920
+ json={
921
+ "migrate_deployed_agents": migrate_deployed_agents,
922
+ },
923
+ headers={
924
+ "content-type": "application/json",
925
+ },
926
+ request_options=request_options,
927
+ omit=OMIT,
928
+ )
929
+ try:
930
+ if 200 <= _response.status_code < 300:
931
+ return typing.cast(
932
+ AgentsCreateVersionResponse,
933
+ parse_obj_as(
934
+ type_=AgentsCreateVersionResponse, # type: ignore
935
+ object_=_response.json(),
936
+ ),
937
+ )
938
+ if _response.status_code == 404:
939
+ raise NotFoundError(
940
+ typing.cast(
941
+ typing.Optional[typing.Any],
942
+ parse_obj_as(
943
+ type_=typing.Optional[typing.Any], # type: ignore
944
+ object_=_response.json(),
945
+ ),
946
+ )
947
+ )
948
+ if _response.status_code == 500:
949
+ raise InternalServerError(
950
+ typing.cast(
951
+ typing.Optional[typing.Any],
952
+ parse_obj_as(
953
+ type_=typing.Optional[typing.Any], # type: ignore
954
+ object_=_response.json(),
955
+ ),
956
+ )
957
+ )
958
+ _response_json = _response.json()
959
+ except JSONDecodeError:
960
+ raise ApiError(status_code=_response.status_code, body=_response.text)
961
+ raise ApiError(status_code=_response.status_code, body=_response_json)
962
+
963
+ def migrate(
964
+ self,
965
+ agent_id: str,
966
+ *,
967
+ to_template: str,
968
+ preserve_core_memories: bool,
969
+ variables: typing.Optional[typing.Dict[str, str]] = OMIT,
970
+ request_options: typing.Optional[RequestOptions] = None,
971
+ ) -> AgentsMigrateResponse:
972
+ """
973
+ Migrate an agent to a new versioned agent template
974
+
975
+ Parameters
976
+ ----------
977
+ agent_id : str
978
+
979
+ to_template : str
980
+
981
+ preserve_core_memories : bool
982
+
983
+ variables : typing.Optional[typing.Dict[str, str]]
984
+ If you chose to not preserve core memories, you should provide the new variables for the core memories
985
+
986
+ request_options : typing.Optional[RequestOptions]
987
+ Request-specific configuration.
988
+
989
+ Returns
990
+ -------
991
+ AgentsMigrateResponse
992
+ 200
993
+
994
+ Examples
995
+ --------
996
+ from letta import Letta
997
+
998
+ client = Letta(
999
+ token="YOUR_TOKEN",
1000
+ )
1001
+ client.agents.migrate(
1002
+ agent_id="agent_id",
1003
+ to_template="to_template",
1004
+ preserve_core_memories=True,
1005
+ )
1006
+ """
1007
+ _response = self._client_wrapper.httpx_client.request(
1008
+ f"v1/agents/{jsonable_encoder(agent_id)}/migrate",
1009
+ method="POST",
1010
+ json={
1011
+ "to_template": to_template,
1012
+ "variables": variables,
1013
+ "preserve_core_memories": preserve_core_memories,
1014
+ },
1015
+ headers={
1016
+ "content-type": "application/json",
1017
+ },
1018
+ request_options=request_options,
1019
+ omit=OMIT,
1020
+ )
1021
+ try:
1022
+ if 200 <= _response.status_code < 300:
1023
+ return typing.cast(
1024
+ AgentsMigrateResponse,
1025
+ parse_obj_as(
1026
+ type_=AgentsMigrateResponse, # type: ignore
1027
+ object_=_response.json(),
1028
+ ),
1029
+ )
1030
+ if _response.status_code == 404:
1031
+ raise NotFoundError(
1032
+ typing.cast(
1033
+ typing.Optional[typing.Any],
1034
+ parse_obj_as(
1035
+ type_=typing.Optional[typing.Any], # type: ignore
1036
+ object_=_response.json(),
1037
+ ),
1038
+ )
1039
+ )
1040
+ if _response.status_code == 409:
1041
+ raise ConflictError(
1042
+ typing.cast(
1043
+ ConflictErrorBody,
1044
+ parse_obj_as(
1045
+ type_=ConflictErrorBody, # type: ignore
1046
+ object_=_response.json(),
1047
+ ),
1048
+ )
1049
+ )
1050
+ if _response.status_code == 500:
1051
+ raise InternalServerError(
1052
+ typing.cast(
1053
+ typing.Optional[typing.Any],
1054
+ parse_obj_as(
1055
+ type_=typing.Optional[typing.Any], # type: ignore
1056
+ object_=_response.json(),
1057
+ ),
1058
+ )
1059
+ )
1060
+ _response_json = _response.json()
1061
+ except JSONDecodeError:
1062
+ raise ApiError(status_code=_response.status_code, body=_response.text)
1063
+ raise ApiError(status_code=_response.status_code, body=_response_json)
1064
+
1065
+
1066
+ class AsyncAgentsClient:
1067
+ def __init__(self, *, client_wrapper: AsyncClientWrapper):
1068
+ self._client_wrapper = client_wrapper
1069
+ self.context = AsyncContextClient(client_wrapper=self._client_wrapper)
1070
+ self.tools = AsyncToolsClient(client_wrapper=self._client_wrapper)
1071
+ self.sources = AsyncSourcesClient(client_wrapper=self._client_wrapper)
1072
+ self.memory = AsyncMemoryClient(client_wrapper=self._client_wrapper)
1073
+ self.memory_blocks = AsyncMemoryBlocksClient(client_wrapper=self._client_wrapper)
1074
+ self.recall_memory = AsyncRecallMemoryClient(client_wrapper=self._client_wrapper)
1075
+ self.archival_memory = AsyncArchivalMemoryClient(client_wrapper=self._client_wrapper)
1076
+ self.messages = AsyncMessagesClient(client_wrapper=self._client_wrapper)
1077
+
1078
+ async def list(
1079
+ self,
1080
+ *,
1081
+ name: typing.Optional[str] = None,
1082
+ tags: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
1083
+ match_all_tags: typing.Optional[bool] = None,
1084
+ request_options: typing.Optional[RequestOptions] = None,
1085
+ ) -> typing.List[AgentState]:
1086
+ """
1087
+ List all agents associated with a given user.
1088
+ This endpoint retrieves a list of all agents and their configurations associated with the specified user ID.
1089
+
1090
+ Parameters
1091
+ ----------
1092
+ name : typing.Optional[str]
1093
+ Name of the agent
1094
+
1095
+ tags : typing.Optional[typing.Union[str, typing.Sequence[str]]]
1096
+ List of tags to filter agents by
1097
+
1098
+ match_all_tags : typing.Optional[bool]
1099
+ If True, only returns agents that match ALL given tags. Otherwise, return agents that have ANY of the passed in tags.
1100
+
1101
+ request_options : typing.Optional[RequestOptions]
1102
+ Request-specific configuration.
1103
+
1104
+ Returns
1105
+ -------
1106
+ typing.List[AgentState]
1107
+ Successful Response
1108
+
1109
+ Examples
1110
+ --------
1111
+ import asyncio
1112
+
1113
+ from letta import AsyncLetta
1114
+
1115
+ client = AsyncLetta(
1116
+ token="YOUR_TOKEN",
1117
+ )
1118
+
1119
+
1120
+ async def main() -> None:
1121
+ await client.agents.list()
1122
+
1123
+
1124
+ asyncio.run(main())
1125
+ """
1126
+ _response = await self._client_wrapper.httpx_client.request(
1127
+ "v1/agents/",
1128
+ method="GET",
1129
+ params={
1130
+ "name": name,
1131
+ "tags": tags,
1132
+ "match_all_tags": match_all_tags,
1133
+ },
1134
+ request_options=request_options,
1135
+ )
1136
+ try:
1137
+ if 200 <= _response.status_code < 300:
1138
+ return typing.cast(
1139
+ typing.List[AgentState],
1140
+ parse_obj_as(
1141
+ type_=typing.List[AgentState], # type: ignore
1142
+ object_=_response.json(),
1143
+ ),
1144
+ )
1145
+ if _response.status_code == 422:
1146
+ raise UnprocessableEntityError(
1147
+ typing.cast(
1148
+ HttpValidationError,
1149
+ parse_obj_as(
1150
+ type_=HttpValidationError, # type: ignore
1151
+ object_=_response.json(),
1152
+ ),
1153
+ )
1154
+ )
1155
+ _response_json = _response.json()
1156
+ except JSONDecodeError:
1157
+ raise ApiError(status_code=_response.status_code, body=_response.text)
1158
+ raise ApiError(status_code=_response.status_code, body=_response_json)
1159
+
1160
+ async def create(
1161
+ self,
1162
+ *,
1163
+ memory_blocks: typing.Sequence[CreateBlock],
1164
+ name: typing.Optional[str] = OMIT,
1165
+ tools: typing.Optional[typing.Sequence[str]] = OMIT,
1166
+ tool_ids: typing.Optional[typing.Sequence[str]] = OMIT,
1167
+ source_ids: typing.Optional[typing.Sequence[str]] = OMIT,
1168
+ block_ids: typing.Optional[typing.Sequence[str]] = OMIT,
1169
+ tool_rules: typing.Optional[typing.Sequence[CreateAgentRequestToolRulesItem]] = OMIT,
1170
+ tags: typing.Optional[typing.Sequence[str]] = OMIT,
1171
+ system: typing.Optional[str] = OMIT,
1172
+ agent_type: typing.Optional[AgentType] = OMIT,
1173
+ llm_config: typing.Optional[LlmConfig] = OMIT,
1174
+ embedding_config: typing.Optional[EmbeddingConfig] = OMIT,
1175
+ initial_message_sequence: typing.Optional[typing.Sequence[MessageCreate]] = OMIT,
1176
+ include_base_tools: typing.Optional[bool] = OMIT,
1177
+ description: typing.Optional[str] = OMIT,
1178
+ metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
1179
+ llm: typing.Optional[str] = OMIT,
1180
+ embedding: typing.Optional[str] = OMIT,
1181
+ context_window_limit: typing.Optional[int] = OMIT,
1182
+ embedding_chunk_size: typing.Optional[int] = OMIT,
1183
+ user_id: typing.Optional[str] = OMIT,
1184
+ request_options: typing.Optional[RequestOptions] = None,
1185
+ ) -> AgentState:
1186
+ """
1187
+ Create a new agent with the specified configuration.
1188
+
1189
+ Parameters
1190
+ ----------
1191
+ memory_blocks : typing.Sequence[CreateBlock]
1192
+ The blocks to create in the agent's in-context memory.
1193
+
1194
+ name : typing.Optional[str]
1195
+ The name of the agent.
1196
+
1197
+ tools : typing.Optional[typing.Sequence[str]]
1198
+ The tools used by the agent.
1199
+
1200
+ tool_ids : typing.Optional[typing.Sequence[str]]
1201
+ The ids of the tools used by the agent.
1202
+
1203
+ source_ids : typing.Optional[typing.Sequence[str]]
1204
+ The ids of the sources used by the agent.
1205
+
1206
+ block_ids : typing.Optional[typing.Sequence[str]]
1207
+ The ids of the blocks used by the agent.
1208
+
1209
+ tool_rules : typing.Optional[typing.Sequence[CreateAgentRequestToolRulesItem]]
1210
+ The tool rules governing the agent.
1211
+
1212
+ tags : typing.Optional[typing.Sequence[str]]
1213
+ The tags associated with the agent.
1214
+
1215
+ system : typing.Optional[str]
1216
+ The system prompt used by the agent.
1217
+
1218
+ agent_type : typing.Optional[AgentType]
1219
+ The type of agent.
1220
+
1221
+ llm_config : typing.Optional[LlmConfig]
1222
+ The LLM configuration used by the agent.
1223
+
1224
+ embedding_config : typing.Optional[EmbeddingConfig]
1225
+ The embedding configuration used by the agent.
1226
+
1227
+ initial_message_sequence : typing.Optional[typing.Sequence[MessageCreate]]
1228
+ The initial set of messages to put in the agent's in-context memory.
1229
+
1230
+ include_base_tools : typing.Optional[bool]
1231
+ The LLM configuration used by the agent.
1232
+
1233
+ description : typing.Optional[str]
1234
+ The description of the agent.
1235
+
1236
+ metadata : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
1237
+ The metadata of the agent.
1238
+
1239
+ llm : typing.Optional[str]
1240
+ The LLM configuration handle used by the agent, specified in the format provider/model-name, as an alternative to specifying llm_config.
1241
+
1242
+ embedding : typing.Optional[str]
1243
+ The embedding configuration handle used by the agent, specified in the format provider/model-name.
1244
+
1245
+ context_window_limit : typing.Optional[int]
1246
+ The context window limit used by the agent.
1247
+
1248
+ embedding_chunk_size : typing.Optional[int]
1249
+ The embedding chunk size used by the agent.
1250
+
1251
+ user_id : typing.Optional[str]
1252
+
1253
+ request_options : typing.Optional[RequestOptions]
1254
+ Request-specific configuration.
1255
+
1256
+ Returns
1257
+ -------
1258
+ AgentState
1259
+ Successful Response
1260
+
1261
+ Examples
1262
+ --------
1263
+ import asyncio
1264
+
1265
+ from letta import AsyncLetta, CreateBlock
1266
+
1267
+ client = AsyncLetta(
1268
+ token="YOUR_TOKEN",
1269
+ )
1270
+
1271
+
1272
+ async def main() -> None:
1273
+ await client.agents.create(
1274
+ memory_blocks=[
1275
+ CreateBlock(
1276
+ value="value",
1277
+ label="label",
1278
+ )
1279
+ ],
1280
+ )
1281
+
1282
+
1283
+ asyncio.run(main())
1284
+ """
1285
+ _response = await self._client_wrapper.httpx_client.request(
1286
+ "v1/agents/",
1287
+ method="POST",
1288
+ json={
1289
+ "name": name,
1290
+ "memory_blocks": convert_and_respect_annotation_metadata(
1291
+ object_=memory_blocks, annotation=typing.Sequence[CreateBlock], direction="write"
1292
+ ),
1293
+ "tools": tools,
1294
+ "tool_ids": tool_ids,
1295
+ "source_ids": source_ids,
1296
+ "block_ids": block_ids,
1297
+ "tool_rules": convert_and_respect_annotation_metadata(
1298
+ object_=tool_rules, annotation=typing.Sequence[CreateAgentRequestToolRulesItem], direction="write"
1299
+ ),
1300
+ "tags": tags,
1301
+ "system": system,
1302
+ "agent_type": agent_type,
1303
+ "llm_config": convert_and_respect_annotation_metadata(
1304
+ object_=llm_config, annotation=LlmConfig, direction="write"
1305
+ ),
1306
+ "embedding_config": convert_and_respect_annotation_metadata(
1307
+ object_=embedding_config, annotation=EmbeddingConfig, direction="write"
1308
+ ),
1309
+ "initial_message_sequence": convert_and_respect_annotation_metadata(
1310
+ object_=initial_message_sequence, annotation=typing.Sequence[MessageCreate], direction="write"
1311
+ ),
1312
+ "include_base_tools": include_base_tools,
1313
+ "description": description,
1314
+ "metadata_": metadata,
1315
+ "llm": llm,
1316
+ "embedding": embedding,
1317
+ "context_window_limit": context_window_limit,
1318
+ "embedding_chunk_size": embedding_chunk_size,
1319
+ "user_id": user_id,
1320
+ },
1321
+ headers={
1322
+ "content-type": "application/json",
1323
+ },
1324
+ request_options=request_options,
1325
+ omit=OMIT,
1326
+ )
1327
+ try:
1328
+ if 200 <= _response.status_code < 300:
1329
+ return typing.cast(
1330
+ AgentState,
1331
+ parse_obj_as(
1332
+ type_=AgentState, # type: ignore
1333
+ object_=_response.json(),
1334
+ ),
1335
+ )
1336
+ if _response.status_code == 422:
1337
+ raise UnprocessableEntityError(
1338
+ typing.cast(
1339
+ HttpValidationError,
1340
+ parse_obj_as(
1341
+ type_=HttpValidationError, # type: ignore
1342
+ object_=_response.json(),
1343
+ ),
1344
+ )
1345
+ )
1346
+ _response_json = _response.json()
1347
+ except JSONDecodeError:
1348
+ raise ApiError(status_code=_response.status_code, body=_response.text)
1349
+ raise ApiError(status_code=_response.status_code, body=_response_json)
1350
+
1351
+ async def get(self, agent_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> AgentState:
1352
+ """
1353
+ Get the state of the agent.
1354
+
1355
+ Parameters
1356
+ ----------
1357
+ agent_id : str
1358
+
1359
+ request_options : typing.Optional[RequestOptions]
1360
+ Request-specific configuration.
1361
+
1362
+ Returns
1363
+ -------
1364
+ AgentState
1365
+ Successful Response
1366
+
1367
+ Examples
1368
+ --------
1369
+ import asyncio
1370
+
1371
+ from letta import AsyncLetta
1372
+
1373
+ client = AsyncLetta(
1374
+ token="YOUR_TOKEN",
1375
+ )
1376
+
1377
+
1378
+ async def main() -> None:
1379
+ await client.agents.get(
1380
+ agent_id="agent_id",
1381
+ )
1382
+
1383
+
1384
+ asyncio.run(main())
1385
+ """
1386
+ _response = await self._client_wrapper.httpx_client.request(
1387
+ f"v1/agents/{jsonable_encoder(agent_id)}",
1388
+ method="GET",
1389
+ request_options=request_options,
1390
+ )
1391
+ try:
1392
+ if 200 <= _response.status_code < 300:
1393
+ return typing.cast(
1394
+ AgentState,
1395
+ parse_obj_as(
1396
+ type_=AgentState, # type: ignore
1397
+ object_=_response.json(),
1398
+ ),
1399
+ )
1400
+ if _response.status_code == 422:
1401
+ raise UnprocessableEntityError(
1402
+ typing.cast(
1403
+ HttpValidationError,
1404
+ parse_obj_as(
1405
+ type_=HttpValidationError, # type: ignore
1406
+ object_=_response.json(),
1407
+ ),
1408
+ )
1409
+ )
1410
+ _response_json = _response.json()
1411
+ except JSONDecodeError:
1412
+ raise ApiError(status_code=_response.status_code, body=_response.text)
1413
+ raise ApiError(status_code=_response.status_code, body=_response_json)
1414
+
1415
+ async def delete(self, agent_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> AgentState:
1416
+ """
1417
+ Delete an agent.
1418
+
1419
+ Parameters
1420
+ ----------
1421
+ agent_id : str
1422
+
1423
+ request_options : typing.Optional[RequestOptions]
1424
+ Request-specific configuration.
1425
+
1426
+ Returns
1427
+ -------
1428
+ AgentState
1429
+ Successful Response
1430
+
1431
+ Examples
1432
+ --------
1433
+ import asyncio
1434
+
1435
+ from letta import AsyncLetta
1436
+
1437
+ client = AsyncLetta(
1438
+ token="YOUR_TOKEN",
1439
+ )
1440
+
1441
+
1442
+ async def main() -> None:
1443
+ await client.agents.delete(
1444
+ agent_id="agent_id",
1445
+ )
1446
+
1447
+
1448
+ asyncio.run(main())
1449
+ """
1450
+ _response = await self._client_wrapper.httpx_client.request(
1451
+ f"v1/agents/{jsonable_encoder(agent_id)}",
1452
+ method="DELETE",
1453
+ request_options=request_options,
1454
+ )
1455
+ try:
1456
+ if 200 <= _response.status_code < 300:
1457
+ return typing.cast(
1458
+ AgentState,
1459
+ parse_obj_as(
1460
+ type_=AgentState, # type: ignore
1461
+ object_=_response.json(),
1462
+ ),
1463
+ )
1464
+ if _response.status_code == 422:
1465
+ raise UnprocessableEntityError(
1466
+ typing.cast(
1467
+ HttpValidationError,
1468
+ parse_obj_as(
1469
+ type_=HttpValidationError, # type: ignore
1470
+ object_=_response.json(),
1471
+ ),
1472
+ )
1473
+ )
1474
+ _response_json = _response.json()
1475
+ except JSONDecodeError:
1476
+ raise ApiError(status_code=_response.status_code, body=_response.text)
1477
+ raise ApiError(status_code=_response.status_code, body=_response_json)
1478
+
1479
+ async def update(
1480
+ self,
1481
+ agent_id: str,
1482
+ *,
1483
+ name: typing.Optional[str] = OMIT,
1484
+ tool_ids: typing.Optional[typing.Sequence[str]] = OMIT,
1485
+ source_ids: typing.Optional[typing.Sequence[str]] = OMIT,
1486
+ block_ids: typing.Optional[typing.Sequence[str]] = OMIT,
1487
+ tags: typing.Optional[typing.Sequence[str]] = OMIT,
1488
+ system: typing.Optional[str] = OMIT,
1489
+ tool_rules: typing.Optional[typing.Sequence[UpdateAgentToolRulesItem]] = OMIT,
1490
+ llm_config: typing.Optional[LlmConfig] = OMIT,
1491
+ embedding_config: typing.Optional[EmbeddingConfig] = OMIT,
1492
+ message_ids: typing.Optional[typing.Sequence[str]] = OMIT,
1493
+ description: typing.Optional[str] = OMIT,
1494
+ metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
1495
+ request_options: typing.Optional[RequestOptions] = None,
1496
+ ) -> AgentState:
1497
+ """
1498
+ Update an exsiting agent
1499
+
1500
+ Parameters
1501
+ ----------
1502
+ agent_id : str
1503
+
1504
+ name : typing.Optional[str]
1505
+ The name of the agent.
1506
+
1507
+ tool_ids : typing.Optional[typing.Sequence[str]]
1508
+ The ids of the tools used by the agent.
1509
+
1510
+ source_ids : typing.Optional[typing.Sequence[str]]
1511
+ The ids of the sources used by the agent.
1512
+
1513
+ block_ids : typing.Optional[typing.Sequence[str]]
1514
+ The ids of the blocks used by the agent.
1515
+
1516
+ tags : typing.Optional[typing.Sequence[str]]
1517
+ The tags associated with the agent.
1518
+
1519
+ system : typing.Optional[str]
1520
+ The system prompt used by the agent.
1521
+
1522
+ tool_rules : typing.Optional[typing.Sequence[UpdateAgentToolRulesItem]]
1523
+ The tool rules governing the agent.
1524
+
1525
+ llm_config : typing.Optional[LlmConfig]
1526
+ The LLM configuration used by the agent.
1527
+
1528
+ embedding_config : typing.Optional[EmbeddingConfig]
1529
+ The embedding configuration used by the agent.
1530
+
1531
+ message_ids : typing.Optional[typing.Sequence[str]]
1532
+ The ids of the messages in the agent's in-context memory.
1533
+
1534
+ description : typing.Optional[str]
1535
+ The description of the agent.
1536
+
1537
+ metadata : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
1538
+ The metadata of the agent.
1539
+
1540
+ request_options : typing.Optional[RequestOptions]
1541
+ Request-specific configuration.
1542
+
1543
+ Returns
1544
+ -------
1545
+ AgentState
1546
+ Successful Response
1547
+
1548
+ Examples
1549
+ --------
1550
+ import asyncio
1551
+
1552
+ from letta import AsyncLetta
1553
+
1554
+ client = AsyncLetta(
1555
+ token="YOUR_TOKEN",
1556
+ )
1557
+
1558
+
1559
+ async def main() -> None:
1560
+ await client.agents.update(
1561
+ agent_id="agent_id",
1562
+ )
1563
+
1564
+
1565
+ asyncio.run(main())
1566
+ """
1567
+ _response = await self._client_wrapper.httpx_client.request(
1568
+ f"v1/agents/{jsonable_encoder(agent_id)}",
1569
+ method="PATCH",
1570
+ json={
1571
+ "name": name,
1572
+ "tool_ids": tool_ids,
1573
+ "source_ids": source_ids,
1574
+ "block_ids": block_ids,
1575
+ "tags": tags,
1576
+ "system": system,
1577
+ "tool_rules": convert_and_respect_annotation_metadata(
1578
+ object_=tool_rules, annotation=typing.Sequence[UpdateAgentToolRulesItem], direction="write"
1579
+ ),
1580
+ "llm_config": convert_and_respect_annotation_metadata(
1581
+ object_=llm_config, annotation=LlmConfig, direction="write"
1582
+ ),
1583
+ "embedding_config": convert_and_respect_annotation_metadata(
1584
+ object_=embedding_config, annotation=EmbeddingConfig, direction="write"
1585
+ ),
1586
+ "message_ids": message_ids,
1587
+ "description": description,
1588
+ "metadata_": metadata,
1589
+ },
1590
+ headers={
1591
+ "content-type": "application/json",
1592
+ },
1593
+ request_options=request_options,
1594
+ omit=OMIT,
1595
+ )
1596
+ try:
1597
+ if 200 <= _response.status_code < 300:
1598
+ return typing.cast(
1599
+ AgentState,
1600
+ parse_obj_as(
1601
+ type_=AgentState, # type: ignore
1602
+ object_=_response.json(),
1603
+ ),
1604
+ )
1605
+ if _response.status_code == 422:
1606
+ raise UnprocessableEntityError(
1607
+ typing.cast(
1608
+ HttpValidationError,
1609
+ parse_obj_as(
1610
+ type_=HttpValidationError, # type: ignore
1611
+ object_=_response.json(),
1612
+ ),
1613
+ )
1614
+ )
1615
+ _response_json = _response.json()
1616
+ except JSONDecodeError:
1617
+ raise ApiError(status_code=_response.status_code, body=_response.text)
1618
+ raise ApiError(status_code=_response.status_code, body=_response_json)
1619
+
1620
+ async def get_agent_memory_block(
1621
+ self, agent_id: str, block_label: str, *, request_options: typing.Optional[RequestOptions] = None
1622
+ ) -> Block:
1623
+ """
1624
+ Retrieve a memory block from an agent.
1625
+
1626
+ Parameters
1627
+ ----------
1628
+ agent_id : str
1629
+
1630
+ block_label : str
1631
+
1632
+ request_options : typing.Optional[RequestOptions]
1633
+ Request-specific configuration.
1634
+
1635
+ Returns
1636
+ -------
1637
+ Block
1638
+ Successful Response
1639
+
1640
+ Examples
1641
+ --------
1642
+ import asyncio
1643
+
1644
+ from letta import AsyncLetta
1645
+
1646
+ client = AsyncLetta(
1647
+ token="YOUR_TOKEN",
1648
+ )
1649
+
1650
+
1651
+ async def main() -> None:
1652
+ await client.agents.get_agent_memory_block(
1653
+ agent_id="agent_id",
1654
+ block_label="block_label",
1655
+ )
1656
+
1657
+
1658
+ asyncio.run(main())
1659
+ """
1660
+ _response = await self._client_wrapper.httpx_client.request(
1661
+ f"v1/agents/{jsonable_encoder(agent_id)}/memory/block/{jsonable_encoder(block_label)}",
1662
+ method="GET",
1663
+ request_options=request_options,
1664
+ )
1665
+ try:
1666
+ if 200 <= _response.status_code < 300:
1667
+ return typing.cast(
1668
+ Block,
1669
+ parse_obj_as(
1670
+ type_=Block, # type: ignore
1671
+ object_=_response.json(),
1672
+ ),
1673
+ )
1674
+ if _response.status_code == 422:
1675
+ raise UnprocessableEntityError(
1676
+ typing.cast(
1677
+ HttpValidationError,
1678
+ parse_obj_as(
1679
+ type_=HttpValidationError, # type: ignore
1680
+ object_=_response.json(),
1681
+ ),
1682
+ )
1683
+ )
1684
+ _response_json = _response.json()
1685
+ except JSONDecodeError:
1686
+ raise ApiError(status_code=_response.status_code, body=_response.text)
1687
+ raise ApiError(status_code=_response.status_code, body=_response_json)
1688
+
1689
+ async def update_agent_memory_block_by_label(
1690
+ self,
1691
+ agent_id: str,
1692
+ block_label: str,
1693
+ *,
1694
+ value: typing.Optional[str] = OMIT,
1695
+ limit: typing.Optional[int] = OMIT,
1696
+ name: typing.Optional[str] = OMIT,
1697
+ is_template: typing.Optional[bool] = OMIT,
1698
+ label: typing.Optional[str] = OMIT,
1699
+ description: typing.Optional[str] = OMIT,
1700
+ metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
1701
+ request_options: typing.Optional[RequestOptions] = None,
1702
+ ) -> Block:
1703
+ """
1704
+ Removes a memory block from an agent by unlnking it. If the block is not linked to any other agent, it is deleted.
1705
+
1706
+ Parameters
1707
+ ----------
1708
+ agent_id : str
1709
+
1710
+ block_label : str
1711
+
1712
+ value : typing.Optional[str]
1713
+ Value of the block.
1714
+
1715
+ limit : typing.Optional[int]
1716
+ Character limit of the block.
1717
+
1718
+ name : typing.Optional[str]
1719
+ Name of the block if it is a template.
1720
+
1721
+ is_template : typing.Optional[bool]
1722
+ Whether the block is a template (e.g. saved human/persona options).
1723
+
1724
+ label : typing.Optional[str]
1725
+ Label of the block (e.g. 'human', 'persona') in the context window.
1726
+
1727
+ description : typing.Optional[str]
1728
+ Description of the block.
1729
+
1730
+ metadata : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
1731
+ Metadata of the block.
1732
+
1733
+ request_options : typing.Optional[RequestOptions]
1734
+ Request-specific configuration.
1735
+
1736
+ Returns
1737
+ -------
1738
+ Block
1739
+ Successful Response
1740
+
1741
+ Examples
1742
+ --------
1743
+ import asyncio
1744
+
1745
+ from letta import AsyncLetta
1746
+
1747
+ client = AsyncLetta(
1748
+ token="YOUR_TOKEN",
1749
+ )
1750
+
1751
+
1752
+ async def main() -> None:
1753
+ await client.agents.update_agent_memory_block_by_label(
1754
+ agent_id="agent_id",
1755
+ block_label="block_label",
1756
+ )
1757
+
1758
+
1759
+ asyncio.run(main())
1760
+ """
1761
+ _response = await self._client_wrapper.httpx_client.request(
1762
+ f"v1/agents/{jsonable_encoder(agent_id)}/memory/block/{jsonable_encoder(block_label)}",
1763
+ method="PATCH",
1764
+ json={
1765
+ "value": value,
1766
+ "limit": limit,
1767
+ "name": name,
1768
+ "is_template": is_template,
1769
+ "label": label,
1770
+ "description": description,
1771
+ "metadata_": metadata,
1772
+ },
1773
+ request_options=request_options,
1774
+ omit=OMIT,
1775
+ )
1776
+ try:
1777
+ if 200 <= _response.status_code < 300:
1778
+ return typing.cast(
1779
+ Block,
1780
+ parse_obj_as(
1781
+ type_=Block, # type: ignore
1782
+ object_=_response.json(),
1783
+ ),
1784
+ )
1785
+ if _response.status_code == 422:
1786
+ raise UnprocessableEntityError(
1787
+ typing.cast(
1788
+ HttpValidationError,
1789
+ parse_obj_as(
1790
+ type_=HttpValidationError, # type: ignore
1791
+ object_=_response.json(),
1792
+ ),
1793
+ )
1794
+ )
1795
+ _response_json = _response.json()
1796
+ except JSONDecodeError:
1797
+ raise ApiError(status_code=_response.status_code, body=_response.text)
1798
+ raise ApiError(status_code=_response.status_code, body=_response_json)
1799
+
1800
+ async def get_agent_memory_blocks(
1801
+ self, agent_id: str, *, request_options: typing.Optional[RequestOptions] = None
1802
+ ) -> typing.List[Block]:
1803
+ """
1804
+ Retrieve the memory blocks of a specific agent.
1805
+
1806
+ Parameters
1807
+ ----------
1808
+ agent_id : str
1809
+
1810
+ request_options : typing.Optional[RequestOptions]
1811
+ Request-specific configuration.
1812
+
1813
+ Returns
1814
+ -------
1815
+ typing.List[Block]
1816
+ Successful Response
1817
+
1818
+ Examples
1819
+ --------
1820
+ import asyncio
1821
+
1822
+ from letta import AsyncLetta
1823
+
1824
+ client = AsyncLetta(
1825
+ token="YOUR_TOKEN",
1826
+ )
1827
+
1828
+
1829
+ async def main() -> None:
1830
+ await client.agents.get_agent_memory_blocks(
1831
+ agent_id="agent_id",
1832
+ )
1833
+
1834
+
1835
+ asyncio.run(main())
1836
+ """
1837
+ _response = await self._client_wrapper.httpx_client.request(
1838
+ f"v1/agents/{jsonable_encoder(agent_id)}/memory/block",
1839
+ method="GET",
1840
+ request_options=request_options,
1841
+ )
1842
+ try:
1843
+ if 200 <= _response.status_code < 300:
1844
+ return typing.cast(
1845
+ typing.List[Block],
1846
+ parse_obj_as(
1847
+ type_=typing.List[Block], # type: ignore
1848
+ object_=_response.json(),
1849
+ ),
1850
+ )
1851
+ if _response.status_code == 422:
1852
+ raise UnprocessableEntityError(
1853
+ typing.cast(
1854
+ HttpValidationError,
1855
+ parse_obj_as(
1856
+ type_=HttpValidationError, # type: ignore
1857
+ object_=_response.json(),
1858
+ ),
1859
+ )
1860
+ )
1861
+ _response_json = _response.json()
1862
+ except JSONDecodeError:
1863
+ raise ApiError(status_code=_response.status_code, body=_response.text)
1864
+ raise ApiError(status_code=_response.status_code, body=_response_json)
1865
+
1866
+ async def create_agent_message_async(
1867
+ self,
1868
+ agent_id: str,
1869
+ *,
1870
+ messages: typing.Sequence[MessageCreate],
1871
+ assistant_message_tool_name: typing.Optional[str] = OMIT,
1872
+ assistant_message_tool_kwarg: typing.Optional[str] = OMIT,
1873
+ request_options: typing.Optional[RequestOptions] = None,
1874
+ ) -> Job:
1875
+ """
1876
+ Asynchronously process a user message and return a job ID.
1877
+ The actual processing happens in the background, and the status can be checked using the job ID.
1878
+
1879
+ Parameters
1880
+ ----------
1881
+ agent_id : str
1882
+
1883
+ messages : typing.Sequence[MessageCreate]
1884
+ The messages to be sent to the agent.
1885
+
1886
+ assistant_message_tool_name : typing.Optional[str]
1887
+ The name of the designated message tool.
1888
+
1889
+ assistant_message_tool_kwarg : typing.Optional[str]
1890
+ The name of the message argument in the designated message tool.
1891
+
1892
+ request_options : typing.Optional[RequestOptions]
1893
+ Request-specific configuration.
1894
+
1895
+ Returns
1896
+ -------
1897
+ Job
1898
+ Successful Response
1899
+
1900
+ Examples
1901
+ --------
1902
+ import asyncio
1903
+
1904
+ from letta import AsyncLetta, MessageCreate
1905
+
1906
+ client = AsyncLetta(
1907
+ token="YOUR_TOKEN",
1908
+ )
1909
+
1910
+
1911
+ async def main() -> None:
1912
+ await client.agents.create_agent_message_async(
1913
+ agent_id="agent_id",
1914
+ messages=[
1915
+ MessageCreate(
1916
+ role="user",
1917
+ text="text",
1918
+ )
1919
+ ],
1920
+ )
1921
+
1922
+
1923
+ asyncio.run(main())
1924
+ """
1925
+ _response = await self._client_wrapper.httpx_client.request(
1926
+ f"v1/agents/{jsonable_encoder(agent_id)}/messages/async",
1927
+ method="POST",
1928
+ json={
1929
+ "messages": convert_and_respect_annotation_metadata(
1930
+ object_=messages, annotation=typing.Sequence[MessageCreate], direction="write"
1931
+ ),
1932
+ "assistant_message_tool_name": assistant_message_tool_name,
1933
+ "assistant_message_tool_kwarg": assistant_message_tool_kwarg,
1934
+ },
1935
+ request_options=request_options,
1936
+ omit=OMIT,
1937
+ )
1938
+ try:
1939
+ if 200 <= _response.status_code < 300:
1940
+ return typing.cast(
1941
+ Job,
1942
+ parse_obj_as(
1943
+ type_=Job, # type: ignore
1944
+ object_=_response.json(),
1945
+ ),
1946
+ )
1947
+ if _response.status_code == 422:
1948
+ raise UnprocessableEntityError(
1949
+ typing.cast(
1950
+ HttpValidationError,
1951
+ parse_obj_as(
1952
+ type_=HttpValidationError, # type: ignore
1953
+ object_=_response.json(),
1954
+ ),
1955
+ )
1956
+ )
1957
+ _response_json = _response.json()
1958
+ except JSONDecodeError:
1959
+ raise ApiError(status_code=_response.status_code, body=_response.text)
1960
+ raise ApiError(status_code=_response.status_code, body=_response_json)
1961
+
1962
+ async def create_version(
1963
+ self,
1964
+ agent_id: str,
1965
+ *,
1966
+ return_agent_id: typing.Optional[bool] = None,
1967
+ migrate_deployed_agents: typing.Optional[bool] = OMIT,
1968
+ request_options: typing.Optional[RequestOptions] = None,
1969
+ ) -> AgentsCreateVersionResponse:
1970
+ """
1971
+ Creates a versioned version of an agent
1972
+
1973
+ Parameters
1974
+ ----------
1975
+ agent_id : str
1976
+ The agent ID of the agent to migrate, if this agent is not a template, it will create a agent template from the agent provided as well
1977
+
1978
+ return_agent_id : typing.Optional[bool]
1979
+
1980
+ migrate_deployed_agents : typing.Optional[bool]
1981
+
1982
+ request_options : typing.Optional[RequestOptions]
1983
+ Request-specific configuration.
1984
+
1985
+ Returns
1986
+ -------
1987
+ AgentsCreateVersionResponse
1988
+ 201
1989
+
1990
+ Examples
1991
+ --------
1992
+ import asyncio
1993
+
1994
+ from letta import AsyncLetta
1995
+
1996
+ client = AsyncLetta(
1997
+ token="YOUR_TOKEN",
1998
+ )
1999
+
2000
+
2001
+ async def main() -> None:
2002
+ await client.agents.create_version(
2003
+ agent_id="agent_id",
2004
+ )
2005
+
2006
+
2007
+ asyncio.run(main())
2008
+ """
2009
+ _response = await self._client_wrapper.httpx_client.request(
2010
+ f"v1/agents/{jsonable_encoder(agent_id)}/version-template",
2011
+ method="POST",
2012
+ params={
2013
+ "returnAgentId": return_agent_id,
2014
+ },
2015
+ json={
2016
+ "migrate_deployed_agents": migrate_deployed_agents,
2017
+ },
2018
+ headers={
2019
+ "content-type": "application/json",
2020
+ },
2021
+ request_options=request_options,
2022
+ omit=OMIT,
2023
+ )
2024
+ try:
2025
+ if 200 <= _response.status_code < 300:
2026
+ return typing.cast(
2027
+ AgentsCreateVersionResponse,
2028
+ parse_obj_as(
2029
+ type_=AgentsCreateVersionResponse, # type: ignore
2030
+ object_=_response.json(),
2031
+ ),
2032
+ )
2033
+ if _response.status_code == 404:
2034
+ raise NotFoundError(
2035
+ typing.cast(
2036
+ typing.Optional[typing.Any],
2037
+ parse_obj_as(
2038
+ type_=typing.Optional[typing.Any], # type: ignore
2039
+ object_=_response.json(),
2040
+ ),
2041
+ )
2042
+ )
2043
+ if _response.status_code == 500:
2044
+ raise InternalServerError(
2045
+ typing.cast(
2046
+ typing.Optional[typing.Any],
2047
+ parse_obj_as(
2048
+ type_=typing.Optional[typing.Any], # type: ignore
2049
+ object_=_response.json(),
2050
+ ),
2051
+ )
2052
+ )
2053
+ _response_json = _response.json()
2054
+ except JSONDecodeError:
2055
+ raise ApiError(status_code=_response.status_code, body=_response.text)
2056
+ raise ApiError(status_code=_response.status_code, body=_response_json)
2057
+
2058
+ async def migrate(
2059
+ self,
2060
+ agent_id: str,
2061
+ *,
2062
+ to_template: str,
2063
+ preserve_core_memories: bool,
2064
+ variables: typing.Optional[typing.Dict[str, str]] = OMIT,
2065
+ request_options: typing.Optional[RequestOptions] = None,
2066
+ ) -> AgentsMigrateResponse:
2067
+ """
2068
+ Migrate an agent to a new versioned agent template
2069
+
2070
+ Parameters
2071
+ ----------
2072
+ agent_id : str
2073
+
2074
+ to_template : str
2075
+
2076
+ preserve_core_memories : bool
2077
+
2078
+ variables : typing.Optional[typing.Dict[str, str]]
2079
+ If you chose to not preserve core memories, you should provide the new variables for the core memories
2080
+
2081
+ request_options : typing.Optional[RequestOptions]
2082
+ Request-specific configuration.
2083
+
2084
+ Returns
2085
+ -------
2086
+ AgentsMigrateResponse
2087
+ 200
2088
+
2089
+ Examples
2090
+ --------
2091
+ import asyncio
2092
+
2093
+ from letta import AsyncLetta
2094
+
2095
+ client = AsyncLetta(
2096
+ token="YOUR_TOKEN",
2097
+ )
2098
+
2099
+
2100
+ async def main() -> None:
2101
+ await client.agents.migrate(
2102
+ agent_id="agent_id",
2103
+ to_template="to_template",
2104
+ preserve_core_memories=True,
2105
+ )
2106
+
2107
+
2108
+ asyncio.run(main())
2109
+ """
2110
+ _response = await self._client_wrapper.httpx_client.request(
2111
+ f"v1/agents/{jsonable_encoder(agent_id)}/migrate",
2112
+ method="POST",
2113
+ json={
2114
+ "to_template": to_template,
2115
+ "variables": variables,
2116
+ "preserve_core_memories": preserve_core_memories,
2117
+ },
2118
+ headers={
2119
+ "content-type": "application/json",
2120
+ },
2121
+ request_options=request_options,
2122
+ omit=OMIT,
2123
+ )
2124
+ try:
2125
+ if 200 <= _response.status_code < 300:
2126
+ return typing.cast(
2127
+ AgentsMigrateResponse,
2128
+ parse_obj_as(
2129
+ type_=AgentsMigrateResponse, # type: ignore
2130
+ object_=_response.json(),
2131
+ ),
2132
+ )
2133
+ if _response.status_code == 404:
2134
+ raise NotFoundError(
2135
+ typing.cast(
2136
+ typing.Optional[typing.Any],
2137
+ parse_obj_as(
2138
+ type_=typing.Optional[typing.Any], # type: ignore
2139
+ object_=_response.json(),
2140
+ ),
2141
+ )
2142
+ )
2143
+ if _response.status_code == 409:
2144
+ raise ConflictError(
2145
+ typing.cast(
2146
+ ConflictErrorBody,
2147
+ parse_obj_as(
2148
+ type_=ConflictErrorBody, # type: ignore
2149
+ object_=_response.json(),
2150
+ ),
2151
+ )
2152
+ )
2153
+ if _response.status_code == 500:
2154
+ raise InternalServerError(
2155
+ typing.cast(
2156
+ typing.Optional[typing.Any],
2157
+ parse_obj_as(
2158
+ type_=typing.Optional[typing.Any], # type: ignore
2159
+ object_=_response.json(),
2160
+ ),
2161
+ )
2162
+ )
2163
+ _response_json = _response.json()
2164
+ except JSONDecodeError:
2165
+ raise ApiError(status_code=_response.status_code, body=_response.text)
2166
+ raise ApiError(status_code=_response.status_code, body=_response_json)