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