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.
- letta/__init__.py +277 -0
- letta/agents/__init__.py +44 -0
- letta/agents/archival_memory/__init__.py +2 -0
- letta/agents/archival_memory/client.py +591 -0
- letta/agents/client.py +2604 -0
- letta/agents/context/__init__.py +2 -0
- letta/agents/context/client.py +145 -0
- letta/agents/memory/__init__.py +5 -0
- letta/agents/memory/client.py +149 -0
- letta/agents/memory/messages/__init__.py +2 -0
- letta/agents/memory/messages/client.py +147 -0
- letta/agents/memory_blocks/__init__.py +2 -0
- letta/agents/memory_blocks/client.py +364 -0
- letta/agents/messages/__init__.py +5 -0
- letta/agents/messages/client.py +787 -0
- letta/agents/messages/types/__init__.py +7 -0
- letta/agents/messages/types/letta_streaming_response.py +20 -0
- letta/agents/messages/types/messages_list_response.py +7 -0
- letta/agents/messages/types/messages_list_response_item.py +13 -0
- letta/agents/recall_memory/__init__.py +2 -0
- letta/agents/recall_memory/client.py +147 -0
- letta/agents/sources/__init__.py +2 -0
- letta/agents/sources/client.py +145 -0
- letta/agents/tools/__init__.py +2 -0
- letta/agents/tools/client.py +408 -0
- letta/agents/types/__init__.py +39 -0
- letta/agents/types/agents_get_agent_variables_response.py +19 -0
- letta/agents/types/agents_migrate_response.py +19 -0
- letta/agents/types/agents_search_deployed_agents_request_combinator.py +5 -0
- letta/agents/types/agents_search_deployed_agents_request_search_item.py +16 -0
- letta/agents/types/agents_search_deployed_agents_request_search_item_direction.py +27 -0
- letta/agents/types/agents_search_deployed_agents_request_search_item_direction_direction.py +5 -0
- letta/agents/types/agents_search_deployed_agents_request_search_item_direction_value.py +7 -0
- letta/agents/types/agents_search_deployed_agents_request_search_item_operator.py +24 -0
- letta/agents/types/agents_search_deployed_agents_request_search_item_operator_operator.py +7 -0
- letta/agents/types/agents_search_deployed_agents_request_search_item_zero.py +20 -0
- letta/agents/types/create_agent_request_tool_rules_item.py +9 -0
- letta/agents/types/update_agent_tool_rules_item.py +9 -0
- letta/blocks/__init__.py +2 -0
- letta/blocks/client.py +1054 -0
- letta/client.py +164 -0
- letta/core/__init__.py +47 -0
- letta/core/api_error.py +15 -0
- letta/core/client_wrapper.py +76 -0
- letta/core/datetime_utils.py +28 -0
- letta/core/file.py +67 -0
- letta/core/http_client.py +499 -0
- letta/core/jsonable_encoder.py +101 -0
- letta/core/pydantic_utilities.py +296 -0
- letta/core/query_encoder.py +58 -0
- letta/core/remove_none_from_dict.py +11 -0
- letta/core/request_options.py +35 -0
- letta/core/serialization.py +272 -0
- letta/environment.py +8 -0
- letta/errors/__init__.py +8 -0
- letta/errors/conflict_error.py +9 -0
- letta/errors/internal_server_error.py +9 -0
- letta/errors/not_found_error.py +9 -0
- letta/errors/unprocessable_entity_error.py +9 -0
- letta/health/__init__.py +2 -0
- letta/health/client.py +108 -0
- letta/jobs/__init__.py +2 -0
- letta/jobs/client.py +503 -0
- letta/models/__init__.py +2 -0
- letta/models/client.py +201 -0
- letta/sources/__init__.py +5 -0
- letta/sources/client.py +1154 -0
- letta/sources/files/__init__.py +2 -0
- letta/sources/files/client.py +436 -0
- letta/sources/passages/__init__.py +2 -0
- letta/sources/passages/client.py +145 -0
- letta/tools/__init__.py +2 -0
- letta/tools/client.py +1823 -0
- letta/types/__init__.py +231 -0
- letta/types/action_model.py +36 -0
- letta/types/action_parameters_model.py +26 -0
- letta/types/action_response_model.py +26 -0
- letta/types/agent_state.py +139 -0
- letta/types/agent_state_tool_rules_item.py +9 -0
- letta/types/agent_type.py +8 -0
- letta/types/app_auth_scheme.py +34 -0
- letta/types/app_auth_scheme_auth_mode.py +7 -0
- letta/types/app_model.py +44 -0
- letta/types/archival_memory_summary.py +22 -0
- letta/types/assistant_file.py +33 -0
- letta/types/assistant_message_input.py +23 -0
- letta/types/assistant_message_output.py +23 -0
- letta/types/auth_request.py +22 -0
- letta/types/auth_response.py +29 -0
- letta/types/auth_scheme_field.py +30 -0
- letta/types/block.py +91 -0
- letta/types/block_update.py +60 -0
- letta/types/chat_completion_request.py +49 -0
- letta/types/chat_completion_request_function_call.py +6 -0
- letta/types/chat_completion_request_messages_item.py +11 -0
- letta/types/chat_completion_request_stop.py +5 -0
- letta/types/chat_completion_request_tool_choice.py +8 -0
- letta/types/chat_completion_response.py +32 -0
- letta/types/child_tool_rule.py +33 -0
- letta/types/choice.py +25 -0
- letta/types/conditional_tool_rule.py +43 -0
- letta/types/conflict_error_body.py +21 -0
- letta/types/context_window_overview.py +105 -0
- letta/types/create_assistant_file_request.py +22 -0
- letta/types/create_assistant_request.py +57 -0
- letta/types/create_block.py +56 -0
- letta/types/delete_assistant_file_response.py +28 -0
- letta/types/delete_assistant_response.py +28 -0
- letta/types/e_2_b_sandbox_config.py +32 -0
- letta/types/embedding_config.py +77 -0
- letta/types/embedding_config_embedding_endpoint_type.py +26 -0
- letta/types/file_metadata.py +82 -0
- letta/types/function_call_input.py +19 -0
- letta/types/function_call_output.py +20 -0
- letta/types/function_schema.py +21 -0
- letta/types/health.py +24 -0
- letta/types/http_validation_error.py +20 -0
- letta/types/init_tool_rule.py +29 -0
- letta/types/internal_server_error_body.py +19 -0
- letta/types/job.py +79 -0
- letta/types/job_status.py +5 -0
- letta/types/letta_request.py +33 -0
- letta/types/letta_response.py +37 -0
- letta/types/letta_schemas_letta_message_tool_call.py +21 -0
- letta/types/letta_schemas_message_message.py +103 -0
- letta/types/letta_schemas_openai_chat_completion_request_tool.py +21 -0
- letta/types/letta_schemas_openai_chat_completion_request_tool_call.py +24 -0
- letta/types/letta_schemas_openai_chat_completion_request_tool_call_function.py +20 -0
- letta/types/letta_schemas_openai_chat_completion_response_message.py +24 -0
- letta/types/letta_schemas_openai_chat_completion_response_tool_call.py +22 -0
- letta/types/letta_schemas_openai_chat_completions_tool_call_function.py +27 -0
- letta/types/letta_schemas_openai_chat_completions_tool_call_input.py +29 -0
- letta/types/letta_schemas_openai_chat_completions_tool_call_output.py +29 -0
- letta/types/letta_schemas_tool_tool.py +88 -0
- letta/types/letta_usage_statistics.py +48 -0
- letta/types/llm_config.py +65 -0
- letta/types/llm_config_model_endpoint_type.py +26 -0
- letta/types/local_sandbox_config.py +32 -0
- letta/types/log_prob_token.py +21 -0
- letta/types/memory.py +32 -0
- letta/types/message_content_log_prob.py +23 -0
- letta/types/message_create.py +37 -0
- letta/types/message_create_role.py +5 -0
- letta/types/message_role.py +5 -0
- letta/types/not_found_error_body.py +19 -0
- letta/types/not_found_error_body_message.py +11 -0
- letta/types/open_ai_assistant.py +67 -0
- letta/types/organization.py +33 -0
- letta/types/organization_create.py +22 -0
- letta/types/passage.py +107 -0
- letta/types/reasoning_message.py +32 -0
- letta/types/recall_memory_summary.py +22 -0
- letta/types/response_format.py +19 -0
- letta/types/sandbox_config.py +59 -0
- letta/types/sandbox_config_create.py +23 -0
- letta/types/sandbox_config_create_config.py +7 -0
- letta/types/sandbox_config_update.py +27 -0
- letta/types/sandbox_config_update_config.py +7 -0
- letta/types/sandbox_environment_variable.py +68 -0
- letta/types/sandbox_environment_variable_create.py +32 -0
- letta/types/sandbox_environment_variable_update.py +36 -0
- letta/types/sandbox_type.py +5 -0
- letta/types/source.py +85 -0
- letta/types/system_message_input.py +21 -0
- letta/types/system_message_output.py +32 -0
- letta/types/terminal_tool_rule.py +29 -0
- letta/types/tool_call_delta.py +21 -0
- letta/types/tool_call_function_output.py +27 -0
- letta/types/tool_call_message.py +33 -0
- letta/types/tool_call_message_tool_call.py +7 -0
- letta/types/tool_create.py +57 -0
- letta/types/tool_function_choice.py +21 -0
- letta/types/tool_input.py +21 -0
- letta/types/tool_message.py +21 -0
- letta/types/tool_return_message.py +41 -0
- letta/types/tool_return_message_status.py +5 -0
- letta/types/tool_rule_type.py +10 -0
- letta/types/usage_statistics.py +21 -0
- letta/types/user.py +57 -0
- letta/types/user_create.py +27 -0
- letta/types/user_message_input.py +22 -0
- letta/types/user_message_input_content.py +5 -0
- letta/types/user_message_output.py +32 -0
- letta/types/user_update.py +32 -0
- letta/types/validation_error.py +22 -0
- letta/types/validation_error_loc_item.py +5 -0
- letta/version.py +3 -0
- letta_client-0.1.4.dist-info/METADATA +189 -0
- letta_client-0.1.4.dist-info/RECORD +191 -0
- {letta_client-0.1.0.dist-info → letta_client-0.1.4.dist-info}/WHEEL +1 -1
- letta_client-0.1.0.dist-info/METADATA +0 -15
- letta_client-0.1.0.dist-info/RECORD +0 -4
- /letta_client/__init__.py → /letta/py.typed +0 -0
letta/blocks/client.py
ADDED
|
@@ -0,0 +1,1054 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
from ..core.client_wrapper import SyncClientWrapper
|
|
5
|
+
from ..core.request_options import RequestOptions
|
|
6
|
+
from ..types.block import Block
|
|
7
|
+
from ..core.pydantic_utilities import parse_obj_as
|
|
8
|
+
from ..errors.unprocessable_entity_error import UnprocessableEntityError
|
|
9
|
+
from ..types.http_validation_error import HttpValidationError
|
|
10
|
+
from json.decoder import JSONDecodeError
|
|
11
|
+
from ..core.api_error import ApiError
|
|
12
|
+
from ..core.jsonable_encoder import jsonable_encoder
|
|
13
|
+
from ..core.client_wrapper import AsyncClientWrapper
|
|
14
|
+
|
|
15
|
+
# this is used as the default value for optional parameters
|
|
16
|
+
OMIT = typing.cast(typing.Any, ...)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class BlocksClient:
|
|
20
|
+
def __init__(self, *, client_wrapper: SyncClientWrapper):
|
|
21
|
+
self._client_wrapper = client_wrapper
|
|
22
|
+
|
|
23
|
+
def list(
|
|
24
|
+
self,
|
|
25
|
+
*,
|
|
26
|
+
label: typing.Optional[str] = None,
|
|
27
|
+
templates_only: typing.Optional[bool] = None,
|
|
28
|
+
name: typing.Optional[str] = None,
|
|
29
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
30
|
+
) -> typing.List[Block]:
|
|
31
|
+
"""
|
|
32
|
+
Parameters
|
|
33
|
+
----------
|
|
34
|
+
label : typing.Optional[str]
|
|
35
|
+
Labels to include (e.g. human, persona)
|
|
36
|
+
|
|
37
|
+
templates_only : typing.Optional[bool]
|
|
38
|
+
Whether to include only templates
|
|
39
|
+
|
|
40
|
+
name : typing.Optional[str]
|
|
41
|
+
Name of the block
|
|
42
|
+
|
|
43
|
+
request_options : typing.Optional[RequestOptions]
|
|
44
|
+
Request-specific configuration.
|
|
45
|
+
|
|
46
|
+
Returns
|
|
47
|
+
-------
|
|
48
|
+
typing.List[Block]
|
|
49
|
+
Successful Response
|
|
50
|
+
|
|
51
|
+
Examples
|
|
52
|
+
--------
|
|
53
|
+
from letta import Letta
|
|
54
|
+
|
|
55
|
+
client = Letta(
|
|
56
|
+
token="YOUR_TOKEN",
|
|
57
|
+
)
|
|
58
|
+
client.blocks.list()
|
|
59
|
+
"""
|
|
60
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
61
|
+
"v1/blocks/",
|
|
62
|
+
method="GET",
|
|
63
|
+
params={
|
|
64
|
+
"label": label,
|
|
65
|
+
"templates_only": templates_only,
|
|
66
|
+
"name": name,
|
|
67
|
+
},
|
|
68
|
+
request_options=request_options,
|
|
69
|
+
)
|
|
70
|
+
try:
|
|
71
|
+
if 200 <= _response.status_code < 300:
|
|
72
|
+
return typing.cast(
|
|
73
|
+
typing.List[Block],
|
|
74
|
+
parse_obj_as(
|
|
75
|
+
type_=typing.List[Block], # type: ignore
|
|
76
|
+
object_=_response.json(),
|
|
77
|
+
),
|
|
78
|
+
)
|
|
79
|
+
if _response.status_code == 422:
|
|
80
|
+
raise UnprocessableEntityError(
|
|
81
|
+
typing.cast(
|
|
82
|
+
HttpValidationError,
|
|
83
|
+
parse_obj_as(
|
|
84
|
+
type_=HttpValidationError, # type: ignore
|
|
85
|
+
object_=_response.json(),
|
|
86
|
+
),
|
|
87
|
+
)
|
|
88
|
+
)
|
|
89
|
+
_response_json = _response.json()
|
|
90
|
+
except JSONDecodeError:
|
|
91
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
92
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
93
|
+
|
|
94
|
+
def create(
|
|
95
|
+
self,
|
|
96
|
+
*,
|
|
97
|
+
value: str,
|
|
98
|
+
label: str,
|
|
99
|
+
limit: typing.Optional[int] = OMIT,
|
|
100
|
+
name: typing.Optional[str] = OMIT,
|
|
101
|
+
is_template: typing.Optional[bool] = OMIT,
|
|
102
|
+
description: typing.Optional[str] = OMIT,
|
|
103
|
+
metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
|
|
104
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
105
|
+
) -> Block:
|
|
106
|
+
"""
|
|
107
|
+
Parameters
|
|
108
|
+
----------
|
|
109
|
+
value : str
|
|
110
|
+
Value of the block.
|
|
111
|
+
|
|
112
|
+
label : str
|
|
113
|
+
Label of the block.
|
|
114
|
+
|
|
115
|
+
limit : typing.Optional[int]
|
|
116
|
+
Character limit of the block.
|
|
117
|
+
|
|
118
|
+
name : typing.Optional[str]
|
|
119
|
+
Name of the block if it is a template.
|
|
120
|
+
|
|
121
|
+
is_template : typing.Optional[bool]
|
|
122
|
+
|
|
123
|
+
description : typing.Optional[str]
|
|
124
|
+
Description of the block.
|
|
125
|
+
|
|
126
|
+
metadata : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
|
|
127
|
+
Metadata of the block.
|
|
128
|
+
|
|
129
|
+
request_options : typing.Optional[RequestOptions]
|
|
130
|
+
Request-specific configuration.
|
|
131
|
+
|
|
132
|
+
Returns
|
|
133
|
+
-------
|
|
134
|
+
Block
|
|
135
|
+
Successful Response
|
|
136
|
+
|
|
137
|
+
Examples
|
|
138
|
+
--------
|
|
139
|
+
from letta import Letta
|
|
140
|
+
|
|
141
|
+
client = Letta(
|
|
142
|
+
token="YOUR_TOKEN",
|
|
143
|
+
)
|
|
144
|
+
client.blocks.create(
|
|
145
|
+
value="value",
|
|
146
|
+
label="label",
|
|
147
|
+
)
|
|
148
|
+
"""
|
|
149
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
150
|
+
"v1/blocks/",
|
|
151
|
+
method="POST",
|
|
152
|
+
json={
|
|
153
|
+
"value": value,
|
|
154
|
+
"limit": limit,
|
|
155
|
+
"name": name,
|
|
156
|
+
"is_template": is_template,
|
|
157
|
+
"label": label,
|
|
158
|
+
"description": description,
|
|
159
|
+
"metadata_": metadata,
|
|
160
|
+
},
|
|
161
|
+
request_options=request_options,
|
|
162
|
+
omit=OMIT,
|
|
163
|
+
)
|
|
164
|
+
try:
|
|
165
|
+
if 200 <= _response.status_code < 300:
|
|
166
|
+
return typing.cast(
|
|
167
|
+
Block,
|
|
168
|
+
parse_obj_as(
|
|
169
|
+
type_=Block, # type: ignore
|
|
170
|
+
object_=_response.json(),
|
|
171
|
+
),
|
|
172
|
+
)
|
|
173
|
+
if _response.status_code == 422:
|
|
174
|
+
raise UnprocessableEntityError(
|
|
175
|
+
typing.cast(
|
|
176
|
+
HttpValidationError,
|
|
177
|
+
parse_obj_as(
|
|
178
|
+
type_=HttpValidationError, # type: ignore
|
|
179
|
+
object_=_response.json(),
|
|
180
|
+
),
|
|
181
|
+
)
|
|
182
|
+
)
|
|
183
|
+
_response_json = _response.json()
|
|
184
|
+
except JSONDecodeError:
|
|
185
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
186
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
187
|
+
|
|
188
|
+
def get(self, block_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> Block:
|
|
189
|
+
"""
|
|
190
|
+
Parameters
|
|
191
|
+
----------
|
|
192
|
+
block_id : str
|
|
193
|
+
|
|
194
|
+
request_options : typing.Optional[RequestOptions]
|
|
195
|
+
Request-specific configuration.
|
|
196
|
+
|
|
197
|
+
Returns
|
|
198
|
+
-------
|
|
199
|
+
Block
|
|
200
|
+
Successful Response
|
|
201
|
+
|
|
202
|
+
Examples
|
|
203
|
+
--------
|
|
204
|
+
from letta import Letta
|
|
205
|
+
|
|
206
|
+
client = Letta(
|
|
207
|
+
token="YOUR_TOKEN",
|
|
208
|
+
)
|
|
209
|
+
client.blocks.get(
|
|
210
|
+
block_id="block_id",
|
|
211
|
+
)
|
|
212
|
+
"""
|
|
213
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
214
|
+
f"v1/blocks/{jsonable_encoder(block_id)}",
|
|
215
|
+
method="GET",
|
|
216
|
+
request_options=request_options,
|
|
217
|
+
)
|
|
218
|
+
try:
|
|
219
|
+
if 200 <= _response.status_code < 300:
|
|
220
|
+
return typing.cast(
|
|
221
|
+
Block,
|
|
222
|
+
parse_obj_as(
|
|
223
|
+
type_=Block, # type: ignore
|
|
224
|
+
object_=_response.json(),
|
|
225
|
+
),
|
|
226
|
+
)
|
|
227
|
+
if _response.status_code == 422:
|
|
228
|
+
raise UnprocessableEntityError(
|
|
229
|
+
typing.cast(
|
|
230
|
+
HttpValidationError,
|
|
231
|
+
parse_obj_as(
|
|
232
|
+
type_=HttpValidationError, # type: ignore
|
|
233
|
+
object_=_response.json(),
|
|
234
|
+
),
|
|
235
|
+
)
|
|
236
|
+
)
|
|
237
|
+
_response_json = _response.json()
|
|
238
|
+
except JSONDecodeError:
|
|
239
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
240
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
241
|
+
|
|
242
|
+
def delete(self, block_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> Block:
|
|
243
|
+
"""
|
|
244
|
+
Parameters
|
|
245
|
+
----------
|
|
246
|
+
block_id : str
|
|
247
|
+
|
|
248
|
+
request_options : typing.Optional[RequestOptions]
|
|
249
|
+
Request-specific configuration.
|
|
250
|
+
|
|
251
|
+
Returns
|
|
252
|
+
-------
|
|
253
|
+
Block
|
|
254
|
+
Successful Response
|
|
255
|
+
|
|
256
|
+
Examples
|
|
257
|
+
--------
|
|
258
|
+
from letta import Letta
|
|
259
|
+
|
|
260
|
+
client = Letta(
|
|
261
|
+
token="YOUR_TOKEN",
|
|
262
|
+
)
|
|
263
|
+
client.blocks.delete(
|
|
264
|
+
block_id="block_id",
|
|
265
|
+
)
|
|
266
|
+
"""
|
|
267
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
268
|
+
f"v1/blocks/{jsonable_encoder(block_id)}",
|
|
269
|
+
method="DELETE",
|
|
270
|
+
request_options=request_options,
|
|
271
|
+
)
|
|
272
|
+
try:
|
|
273
|
+
if 200 <= _response.status_code < 300:
|
|
274
|
+
return typing.cast(
|
|
275
|
+
Block,
|
|
276
|
+
parse_obj_as(
|
|
277
|
+
type_=Block, # type: ignore
|
|
278
|
+
object_=_response.json(),
|
|
279
|
+
),
|
|
280
|
+
)
|
|
281
|
+
if _response.status_code == 422:
|
|
282
|
+
raise UnprocessableEntityError(
|
|
283
|
+
typing.cast(
|
|
284
|
+
HttpValidationError,
|
|
285
|
+
parse_obj_as(
|
|
286
|
+
type_=HttpValidationError, # type: ignore
|
|
287
|
+
object_=_response.json(),
|
|
288
|
+
),
|
|
289
|
+
)
|
|
290
|
+
)
|
|
291
|
+
_response_json = _response.json()
|
|
292
|
+
except JSONDecodeError:
|
|
293
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
294
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
295
|
+
|
|
296
|
+
def update(
|
|
297
|
+
self,
|
|
298
|
+
block_id: str,
|
|
299
|
+
*,
|
|
300
|
+
value: typing.Optional[str] = OMIT,
|
|
301
|
+
limit: typing.Optional[int] = OMIT,
|
|
302
|
+
name: typing.Optional[str] = OMIT,
|
|
303
|
+
is_template: typing.Optional[bool] = OMIT,
|
|
304
|
+
label: typing.Optional[str] = OMIT,
|
|
305
|
+
description: typing.Optional[str] = OMIT,
|
|
306
|
+
metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
|
|
307
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
308
|
+
) -> Block:
|
|
309
|
+
"""
|
|
310
|
+
Parameters
|
|
311
|
+
----------
|
|
312
|
+
block_id : str
|
|
313
|
+
|
|
314
|
+
value : typing.Optional[str]
|
|
315
|
+
Value of the block.
|
|
316
|
+
|
|
317
|
+
limit : typing.Optional[int]
|
|
318
|
+
Character limit of the block.
|
|
319
|
+
|
|
320
|
+
name : typing.Optional[str]
|
|
321
|
+
Name of the block if it is a template.
|
|
322
|
+
|
|
323
|
+
is_template : typing.Optional[bool]
|
|
324
|
+
Whether the block is a template (e.g. saved human/persona options).
|
|
325
|
+
|
|
326
|
+
label : typing.Optional[str]
|
|
327
|
+
Label of the block (e.g. 'human', 'persona') in the context window.
|
|
328
|
+
|
|
329
|
+
description : typing.Optional[str]
|
|
330
|
+
Description of the block.
|
|
331
|
+
|
|
332
|
+
metadata : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
|
|
333
|
+
Metadata of the block.
|
|
334
|
+
|
|
335
|
+
request_options : typing.Optional[RequestOptions]
|
|
336
|
+
Request-specific configuration.
|
|
337
|
+
|
|
338
|
+
Returns
|
|
339
|
+
-------
|
|
340
|
+
Block
|
|
341
|
+
Successful Response
|
|
342
|
+
|
|
343
|
+
Examples
|
|
344
|
+
--------
|
|
345
|
+
from letta import Letta
|
|
346
|
+
|
|
347
|
+
client = Letta(
|
|
348
|
+
token="YOUR_TOKEN",
|
|
349
|
+
)
|
|
350
|
+
client.blocks.update(
|
|
351
|
+
block_id="block_id",
|
|
352
|
+
)
|
|
353
|
+
"""
|
|
354
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
355
|
+
f"v1/blocks/{jsonable_encoder(block_id)}",
|
|
356
|
+
method="PATCH",
|
|
357
|
+
json={
|
|
358
|
+
"value": value,
|
|
359
|
+
"limit": limit,
|
|
360
|
+
"name": name,
|
|
361
|
+
"is_template": is_template,
|
|
362
|
+
"label": label,
|
|
363
|
+
"description": description,
|
|
364
|
+
"metadata_": metadata,
|
|
365
|
+
},
|
|
366
|
+
request_options=request_options,
|
|
367
|
+
omit=OMIT,
|
|
368
|
+
)
|
|
369
|
+
try:
|
|
370
|
+
if 200 <= _response.status_code < 300:
|
|
371
|
+
return typing.cast(
|
|
372
|
+
Block,
|
|
373
|
+
parse_obj_as(
|
|
374
|
+
type_=Block, # type: ignore
|
|
375
|
+
object_=_response.json(),
|
|
376
|
+
),
|
|
377
|
+
)
|
|
378
|
+
if _response.status_code == 422:
|
|
379
|
+
raise UnprocessableEntityError(
|
|
380
|
+
typing.cast(
|
|
381
|
+
HttpValidationError,
|
|
382
|
+
parse_obj_as(
|
|
383
|
+
type_=HttpValidationError, # type: ignore
|
|
384
|
+
object_=_response.json(),
|
|
385
|
+
),
|
|
386
|
+
)
|
|
387
|
+
)
|
|
388
|
+
_response_json = _response.json()
|
|
389
|
+
except JSONDecodeError:
|
|
390
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
391
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
392
|
+
|
|
393
|
+
def link_agent_memory_block(
|
|
394
|
+
self, block_id: str, *, agent_id: str, request_options: typing.Optional[RequestOptions] = None
|
|
395
|
+
) -> None:
|
|
396
|
+
"""
|
|
397
|
+
Link a memory block to an agent.
|
|
398
|
+
|
|
399
|
+
Parameters
|
|
400
|
+
----------
|
|
401
|
+
block_id : str
|
|
402
|
+
|
|
403
|
+
agent_id : str
|
|
404
|
+
The unique identifier of the agent to attach the source to.
|
|
405
|
+
|
|
406
|
+
request_options : typing.Optional[RequestOptions]
|
|
407
|
+
Request-specific configuration.
|
|
408
|
+
|
|
409
|
+
Returns
|
|
410
|
+
-------
|
|
411
|
+
None
|
|
412
|
+
|
|
413
|
+
Examples
|
|
414
|
+
--------
|
|
415
|
+
from letta import Letta
|
|
416
|
+
|
|
417
|
+
client = Letta(
|
|
418
|
+
token="YOUR_TOKEN",
|
|
419
|
+
)
|
|
420
|
+
client.blocks.link_agent_memory_block(
|
|
421
|
+
block_id="block_id",
|
|
422
|
+
agent_id="agent_id",
|
|
423
|
+
)
|
|
424
|
+
"""
|
|
425
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
426
|
+
f"v1/blocks/{jsonable_encoder(block_id)}/attach",
|
|
427
|
+
method="PATCH",
|
|
428
|
+
params={
|
|
429
|
+
"agent_id": agent_id,
|
|
430
|
+
},
|
|
431
|
+
request_options=request_options,
|
|
432
|
+
)
|
|
433
|
+
try:
|
|
434
|
+
if 200 <= _response.status_code < 300:
|
|
435
|
+
return
|
|
436
|
+
if _response.status_code == 422:
|
|
437
|
+
raise UnprocessableEntityError(
|
|
438
|
+
typing.cast(
|
|
439
|
+
HttpValidationError,
|
|
440
|
+
parse_obj_as(
|
|
441
|
+
type_=HttpValidationError, # type: ignore
|
|
442
|
+
object_=_response.json(),
|
|
443
|
+
),
|
|
444
|
+
)
|
|
445
|
+
)
|
|
446
|
+
_response_json = _response.json()
|
|
447
|
+
except JSONDecodeError:
|
|
448
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
449
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
450
|
+
|
|
451
|
+
def unlink_agent_memory_block(
|
|
452
|
+
self, block_id: str, *, agent_id: str, request_options: typing.Optional[RequestOptions] = None
|
|
453
|
+
) -> None:
|
|
454
|
+
"""
|
|
455
|
+
Unlink a memory block from an agent
|
|
456
|
+
|
|
457
|
+
Parameters
|
|
458
|
+
----------
|
|
459
|
+
block_id : str
|
|
460
|
+
|
|
461
|
+
agent_id : str
|
|
462
|
+
The unique identifier of the agent to attach the source to.
|
|
463
|
+
|
|
464
|
+
request_options : typing.Optional[RequestOptions]
|
|
465
|
+
Request-specific configuration.
|
|
466
|
+
|
|
467
|
+
Returns
|
|
468
|
+
-------
|
|
469
|
+
None
|
|
470
|
+
|
|
471
|
+
Examples
|
|
472
|
+
--------
|
|
473
|
+
from letta import Letta
|
|
474
|
+
|
|
475
|
+
client = Letta(
|
|
476
|
+
token="YOUR_TOKEN",
|
|
477
|
+
)
|
|
478
|
+
client.blocks.unlink_agent_memory_block(
|
|
479
|
+
block_id="block_id",
|
|
480
|
+
agent_id="agent_id",
|
|
481
|
+
)
|
|
482
|
+
"""
|
|
483
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
484
|
+
f"v1/blocks/{jsonable_encoder(block_id)}/detach",
|
|
485
|
+
method="PATCH",
|
|
486
|
+
params={
|
|
487
|
+
"agent_id": agent_id,
|
|
488
|
+
},
|
|
489
|
+
request_options=request_options,
|
|
490
|
+
)
|
|
491
|
+
try:
|
|
492
|
+
if 200 <= _response.status_code < 300:
|
|
493
|
+
return
|
|
494
|
+
if _response.status_code == 422:
|
|
495
|
+
raise UnprocessableEntityError(
|
|
496
|
+
typing.cast(
|
|
497
|
+
HttpValidationError,
|
|
498
|
+
parse_obj_as(
|
|
499
|
+
type_=HttpValidationError, # type: ignore
|
|
500
|
+
object_=_response.json(),
|
|
501
|
+
),
|
|
502
|
+
)
|
|
503
|
+
)
|
|
504
|
+
_response_json = _response.json()
|
|
505
|
+
except JSONDecodeError:
|
|
506
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
507
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
class AsyncBlocksClient:
|
|
511
|
+
def __init__(self, *, client_wrapper: AsyncClientWrapper):
|
|
512
|
+
self._client_wrapper = client_wrapper
|
|
513
|
+
|
|
514
|
+
async def list(
|
|
515
|
+
self,
|
|
516
|
+
*,
|
|
517
|
+
label: typing.Optional[str] = None,
|
|
518
|
+
templates_only: typing.Optional[bool] = None,
|
|
519
|
+
name: typing.Optional[str] = None,
|
|
520
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
521
|
+
) -> typing.List[Block]:
|
|
522
|
+
"""
|
|
523
|
+
Parameters
|
|
524
|
+
----------
|
|
525
|
+
label : typing.Optional[str]
|
|
526
|
+
Labels to include (e.g. human, persona)
|
|
527
|
+
|
|
528
|
+
templates_only : typing.Optional[bool]
|
|
529
|
+
Whether to include only templates
|
|
530
|
+
|
|
531
|
+
name : typing.Optional[str]
|
|
532
|
+
Name of the block
|
|
533
|
+
|
|
534
|
+
request_options : typing.Optional[RequestOptions]
|
|
535
|
+
Request-specific configuration.
|
|
536
|
+
|
|
537
|
+
Returns
|
|
538
|
+
-------
|
|
539
|
+
typing.List[Block]
|
|
540
|
+
Successful Response
|
|
541
|
+
|
|
542
|
+
Examples
|
|
543
|
+
--------
|
|
544
|
+
import asyncio
|
|
545
|
+
|
|
546
|
+
from letta import AsyncLetta
|
|
547
|
+
|
|
548
|
+
client = AsyncLetta(
|
|
549
|
+
token="YOUR_TOKEN",
|
|
550
|
+
)
|
|
551
|
+
|
|
552
|
+
|
|
553
|
+
async def main() -> None:
|
|
554
|
+
await client.blocks.list()
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
asyncio.run(main())
|
|
558
|
+
"""
|
|
559
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
560
|
+
"v1/blocks/",
|
|
561
|
+
method="GET",
|
|
562
|
+
params={
|
|
563
|
+
"label": label,
|
|
564
|
+
"templates_only": templates_only,
|
|
565
|
+
"name": name,
|
|
566
|
+
},
|
|
567
|
+
request_options=request_options,
|
|
568
|
+
)
|
|
569
|
+
try:
|
|
570
|
+
if 200 <= _response.status_code < 300:
|
|
571
|
+
return typing.cast(
|
|
572
|
+
typing.List[Block],
|
|
573
|
+
parse_obj_as(
|
|
574
|
+
type_=typing.List[Block], # type: ignore
|
|
575
|
+
object_=_response.json(),
|
|
576
|
+
),
|
|
577
|
+
)
|
|
578
|
+
if _response.status_code == 422:
|
|
579
|
+
raise UnprocessableEntityError(
|
|
580
|
+
typing.cast(
|
|
581
|
+
HttpValidationError,
|
|
582
|
+
parse_obj_as(
|
|
583
|
+
type_=HttpValidationError, # type: ignore
|
|
584
|
+
object_=_response.json(),
|
|
585
|
+
),
|
|
586
|
+
)
|
|
587
|
+
)
|
|
588
|
+
_response_json = _response.json()
|
|
589
|
+
except JSONDecodeError:
|
|
590
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
591
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
592
|
+
|
|
593
|
+
async def create(
|
|
594
|
+
self,
|
|
595
|
+
*,
|
|
596
|
+
value: str,
|
|
597
|
+
label: str,
|
|
598
|
+
limit: typing.Optional[int] = OMIT,
|
|
599
|
+
name: typing.Optional[str] = OMIT,
|
|
600
|
+
is_template: typing.Optional[bool] = OMIT,
|
|
601
|
+
description: typing.Optional[str] = OMIT,
|
|
602
|
+
metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
|
|
603
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
604
|
+
) -> Block:
|
|
605
|
+
"""
|
|
606
|
+
Parameters
|
|
607
|
+
----------
|
|
608
|
+
value : str
|
|
609
|
+
Value of the block.
|
|
610
|
+
|
|
611
|
+
label : str
|
|
612
|
+
Label of the block.
|
|
613
|
+
|
|
614
|
+
limit : typing.Optional[int]
|
|
615
|
+
Character limit of the block.
|
|
616
|
+
|
|
617
|
+
name : typing.Optional[str]
|
|
618
|
+
Name of the block if it is a template.
|
|
619
|
+
|
|
620
|
+
is_template : typing.Optional[bool]
|
|
621
|
+
|
|
622
|
+
description : typing.Optional[str]
|
|
623
|
+
Description of the block.
|
|
624
|
+
|
|
625
|
+
metadata : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
|
|
626
|
+
Metadata of the block.
|
|
627
|
+
|
|
628
|
+
request_options : typing.Optional[RequestOptions]
|
|
629
|
+
Request-specific configuration.
|
|
630
|
+
|
|
631
|
+
Returns
|
|
632
|
+
-------
|
|
633
|
+
Block
|
|
634
|
+
Successful Response
|
|
635
|
+
|
|
636
|
+
Examples
|
|
637
|
+
--------
|
|
638
|
+
import asyncio
|
|
639
|
+
|
|
640
|
+
from letta import AsyncLetta
|
|
641
|
+
|
|
642
|
+
client = AsyncLetta(
|
|
643
|
+
token="YOUR_TOKEN",
|
|
644
|
+
)
|
|
645
|
+
|
|
646
|
+
|
|
647
|
+
async def main() -> None:
|
|
648
|
+
await client.blocks.create(
|
|
649
|
+
value="value",
|
|
650
|
+
label="label",
|
|
651
|
+
)
|
|
652
|
+
|
|
653
|
+
|
|
654
|
+
asyncio.run(main())
|
|
655
|
+
"""
|
|
656
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
657
|
+
"v1/blocks/",
|
|
658
|
+
method="POST",
|
|
659
|
+
json={
|
|
660
|
+
"value": value,
|
|
661
|
+
"limit": limit,
|
|
662
|
+
"name": name,
|
|
663
|
+
"is_template": is_template,
|
|
664
|
+
"label": label,
|
|
665
|
+
"description": description,
|
|
666
|
+
"metadata_": metadata,
|
|
667
|
+
},
|
|
668
|
+
request_options=request_options,
|
|
669
|
+
omit=OMIT,
|
|
670
|
+
)
|
|
671
|
+
try:
|
|
672
|
+
if 200 <= _response.status_code < 300:
|
|
673
|
+
return typing.cast(
|
|
674
|
+
Block,
|
|
675
|
+
parse_obj_as(
|
|
676
|
+
type_=Block, # type: ignore
|
|
677
|
+
object_=_response.json(),
|
|
678
|
+
),
|
|
679
|
+
)
|
|
680
|
+
if _response.status_code == 422:
|
|
681
|
+
raise UnprocessableEntityError(
|
|
682
|
+
typing.cast(
|
|
683
|
+
HttpValidationError,
|
|
684
|
+
parse_obj_as(
|
|
685
|
+
type_=HttpValidationError, # type: ignore
|
|
686
|
+
object_=_response.json(),
|
|
687
|
+
),
|
|
688
|
+
)
|
|
689
|
+
)
|
|
690
|
+
_response_json = _response.json()
|
|
691
|
+
except JSONDecodeError:
|
|
692
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
693
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
694
|
+
|
|
695
|
+
async def get(self, block_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> Block:
|
|
696
|
+
"""
|
|
697
|
+
Parameters
|
|
698
|
+
----------
|
|
699
|
+
block_id : str
|
|
700
|
+
|
|
701
|
+
request_options : typing.Optional[RequestOptions]
|
|
702
|
+
Request-specific configuration.
|
|
703
|
+
|
|
704
|
+
Returns
|
|
705
|
+
-------
|
|
706
|
+
Block
|
|
707
|
+
Successful Response
|
|
708
|
+
|
|
709
|
+
Examples
|
|
710
|
+
--------
|
|
711
|
+
import asyncio
|
|
712
|
+
|
|
713
|
+
from letta import AsyncLetta
|
|
714
|
+
|
|
715
|
+
client = AsyncLetta(
|
|
716
|
+
token="YOUR_TOKEN",
|
|
717
|
+
)
|
|
718
|
+
|
|
719
|
+
|
|
720
|
+
async def main() -> None:
|
|
721
|
+
await client.blocks.get(
|
|
722
|
+
block_id="block_id",
|
|
723
|
+
)
|
|
724
|
+
|
|
725
|
+
|
|
726
|
+
asyncio.run(main())
|
|
727
|
+
"""
|
|
728
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
729
|
+
f"v1/blocks/{jsonable_encoder(block_id)}",
|
|
730
|
+
method="GET",
|
|
731
|
+
request_options=request_options,
|
|
732
|
+
)
|
|
733
|
+
try:
|
|
734
|
+
if 200 <= _response.status_code < 300:
|
|
735
|
+
return typing.cast(
|
|
736
|
+
Block,
|
|
737
|
+
parse_obj_as(
|
|
738
|
+
type_=Block, # type: ignore
|
|
739
|
+
object_=_response.json(),
|
|
740
|
+
),
|
|
741
|
+
)
|
|
742
|
+
if _response.status_code == 422:
|
|
743
|
+
raise UnprocessableEntityError(
|
|
744
|
+
typing.cast(
|
|
745
|
+
HttpValidationError,
|
|
746
|
+
parse_obj_as(
|
|
747
|
+
type_=HttpValidationError, # type: ignore
|
|
748
|
+
object_=_response.json(),
|
|
749
|
+
),
|
|
750
|
+
)
|
|
751
|
+
)
|
|
752
|
+
_response_json = _response.json()
|
|
753
|
+
except JSONDecodeError:
|
|
754
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
755
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
756
|
+
|
|
757
|
+
async def delete(self, block_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> Block:
|
|
758
|
+
"""
|
|
759
|
+
Parameters
|
|
760
|
+
----------
|
|
761
|
+
block_id : str
|
|
762
|
+
|
|
763
|
+
request_options : typing.Optional[RequestOptions]
|
|
764
|
+
Request-specific configuration.
|
|
765
|
+
|
|
766
|
+
Returns
|
|
767
|
+
-------
|
|
768
|
+
Block
|
|
769
|
+
Successful Response
|
|
770
|
+
|
|
771
|
+
Examples
|
|
772
|
+
--------
|
|
773
|
+
import asyncio
|
|
774
|
+
|
|
775
|
+
from letta import AsyncLetta
|
|
776
|
+
|
|
777
|
+
client = AsyncLetta(
|
|
778
|
+
token="YOUR_TOKEN",
|
|
779
|
+
)
|
|
780
|
+
|
|
781
|
+
|
|
782
|
+
async def main() -> None:
|
|
783
|
+
await client.blocks.delete(
|
|
784
|
+
block_id="block_id",
|
|
785
|
+
)
|
|
786
|
+
|
|
787
|
+
|
|
788
|
+
asyncio.run(main())
|
|
789
|
+
"""
|
|
790
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
791
|
+
f"v1/blocks/{jsonable_encoder(block_id)}",
|
|
792
|
+
method="DELETE",
|
|
793
|
+
request_options=request_options,
|
|
794
|
+
)
|
|
795
|
+
try:
|
|
796
|
+
if 200 <= _response.status_code < 300:
|
|
797
|
+
return typing.cast(
|
|
798
|
+
Block,
|
|
799
|
+
parse_obj_as(
|
|
800
|
+
type_=Block, # type: ignore
|
|
801
|
+
object_=_response.json(),
|
|
802
|
+
),
|
|
803
|
+
)
|
|
804
|
+
if _response.status_code == 422:
|
|
805
|
+
raise UnprocessableEntityError(
|
|
806
|
+
typing.cast(
|
|
807
|
+
HttpValidationError,
|
|
808
|
+
parse_obj_as(
|
|
809
|
+
type_=HttpValidationError, # type: ignore
|
|
810
|
+
object_=_response.json(),
|
|
811
|
+
),
|
|
812
|
+
)
|
|
813
|
+
)
|
|
814
|
+
_response_json = _response.json()
|
|
815
|
+
except JSONDecodeError:
|
|
816
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
817
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
818
|
+
|
|
819
|
+
async def update(
|
|
820
|
+
self,
|
|
821
|
+
block_id: str,
|
|
822
|
+
*,
|
|
823
|
+
value: typing.Optional[str] = OMIT,
|
|
824
|
+
limit: typing.Optional[int] = OMIT,
|
|
825
|
+
name: typing.Optional[str] = OMIT,
|
|
826
|
+
is_template: typing.Optional[bool] = OMIT,
|
|
827
|
+
label: typing.Optional[str] = OMIT,
|
|
828
|
+
description: typing.Optional[str] = OMIT,
|
|
829
|
+
metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
|
|
830
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
831
|
+
) -> Block:
|
|
832
|
+
"""
|
|
833
|
+
Parameters
|
|
834
|
+
----------
|
|
835
|
+
block_id : str
|
|
836
|
+
|
|
837
|
+
value : typing.Optional[str]
|
|
838
|
+
Value of the block.
|
|
839
|
+
|
|
840
|
+
limit : typing.Optional[int]
|
|
841
|
+
Character limit of the block.
|
|
842
|
+
|
|
843
|
+
name : typing.Optional[str]
|
|
844
|
+
Name of the block if it is a template.
|
|
845
|
+
|
|
846
|
+
is_template : typing.Optional[bool]
|
|
847
|
+
Whether the block is a template (e.g. saved human/persona options).
|
|
848
|
+
|
|
849
|
+
label : typing.Optional[str]
|
|
850
|
+
Label of the block (e.g. 'human', 'persona') in the context window.
|
|
851
|
+
|
|
852
|
+
description : typing.Optional[str]
|
|
853
|
+
Description of the block.
|
|
854
|
+
|
|
855
|
+
metadata : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
|
|
856
|
+
Metadata of the block.
|
|
857
|
+
|
|
858
|
+
request_options : typing.Optional[RequestOptions]
|
|
859
|
+
Request-specific configuration.
|
|
860
|
+
|
|
861
|
+
Returns
|
|
862
|
+
-------
|
|
863
|
+
Block
|
|
864
|
+
Successful Response
|
|
865
|
+
|
|
866
|
+
Examples
|
|
867
|
+
--------
|
|
868
|
+
import asyncio
|
|
869
|
+
|
|
870
|
+
from letta import AsyncLetta
|
|
871
|
+
|
|
872
|
+
client = AsyncLetta(
|
|
873
|
+
token="YOUR_TOKEN",
|
|
874
|
+
)
|
|
875
|
+
|
|
876
|
+
|
|
877
|
+
async def main() -> None:
|
|
878
|
+
await client.blocks.update(
|
|
879
|
+
block_id="block_id",
|
|
880
|
+
)
|
|
881
|
+
|
|
882
|
+
|
|
883
|
+
asyncio.run(main())
|
|
884
|
+
"""
|
|
885
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
886
|
+
f"v1/blocks/{jsonable_encoder(block_id)}",
|
|
887
|
+
method="PATCH",
|
|
888
|
+
json={
|
|
889
|
+
"value": value,
|
|
890
|
+
"limit": limit,
|
|
891
|
+
"name": name,
|
|
892
|
+
"is_template": is_template,
|
|
893
|
+
"label": label,
|
|
894
|
+
"description": description,
|
|
895
|
+
"metadata_": metadata,
|
|
896
|
+
},
|
|
897
|
+
request_options=request_options,
|
|
898
|
+
omit=OMIT,
|
|
899
|
+
)
|
|
900
|
+
try:
|
|
901
|
+
if 200 <= _response.status_code < 300:
|
|
902
|
+
return typing.cast(
|
|
903
|
+
Block,
|
|
904
|
+
parse_obj_as(
|
|
905
|
+
type_=Block, # type: ignore
|
|
906
|
+
object_=_response.json(),
|
|
907
|
+
),
|
|
908
|
+
)
|
|
909
|
+
if _response.status_code == 422:
|
|
910
|
+
raise UnprocessableEntityError(
|
|
911
|
+
typing.cast(
|
|
912
|
+
HttpValidationError,
|
|
913
|
+
parse_obj_as(
|
|
914
|
+
type_=HttpValidationError, # type: ignore
|
|
915
|
+
object_=_response.json(),
|
|
916
|
+
),
|
|
917
|
+
)
|
|
918
|
+
)
|
|
919
|
+
_response_json = _response.json()
|
|
920
|
+
except JSONDecodeError:
|
|
921
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
922
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
923
|
+
|
|
924
|
+
async def link_agent_memory_block(
|
|
925
|
+
self, block_id: str, *, agent_id: str, request_options: typing.Optional[RequestOptions] = None
|
|
926
|
+
) -> None:
|
|
927
|
+
"""
|
|
928
|
+
Link a memory block to an agent.
|
|
929
|
+
|
|
930
|
+
Parameters
|
|
931
|
+
----------
|
|
932
|
+
block_id : str
|
|
933
|
+
|
|
934
|
+
agent_id : str
|
|
935
|
+
The unique identifier of the agent to attach the source to.
|
|
936
|
+
|
|
937
|
+
request_options : typing.Optional[RequestOptions]
|
|
938
|
+
Request-specific configuration.
|
|
939
|
+
|
|
940
|
+
Returns
|
|
941
|
+
-------
|
|
942
|
+
None
|
|
943
|
+
|
|
944
|
+
Examples
|
|
945
|
+
--------
|
|
946
|
+
import asyncio
|
|
947
|
+
|
|
948
|
+
from letta import AsyncLetta
|
|
949
|
+
|
|
950
|
+
client = AsyncLetta(
|
|
951
|
+
token="YOUR_TOKEN",
|
|
952
|
+
)
|
|
953
|
+
|
|
954
|
+
|
|
955
|
+
async def main() -> None:
|
|
956
|
+
await client.blocks.link_agent_memory_block(
|
|
957
|
+
block_id="block_id",
|
|
958
|
+
agent_id="agent_id",
|
|
959
|
+
)
|
|
960
|
+
|
|
961
|
+
|
|
962
|
+
asyncio.run(main())
|
|
963
|
+
"""
|
|
964
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
965
|
+
f"v1/blocks/{jsonable_encoder(block_id)}/attach",
|
|
966
|
+
method="PATCH",
|
|
967
|
+
params={
|
|
968
|
+
"agent_id": agent_id,
|
|
969
|
+
},
|
|
970
|
+
request_options=request_options,
|
|
971
|
+
)
|
|
972
|
+
try:
|
|
973
|
+
if 200 <= _response.status_code < 300:
|
|
974
|
+
return
|
|
975
|
+
if _response.status_code == 422:
|
|
976
|
+
raise UnprocessableEntityError(
|
|
977
|
+
typing.cast(
|
|
978
|
+
HttpValidationError,
|
|
979
|
+
parse_obj_as(
|
|
980
|
+
type_=HttpValidationError, # type: ignore
|
|
981
|
+
object_=_response.json(),
|
|
982
|
+
),
|
|
983
|
+
)
|
|
984
|
+
)
|
|
985
|
+
_response_json = _response.json()
|
|
986
|
+
except JSONDecodeError:
|
|
987
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
988
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
989
|
+
|
|
990
|
+
async def unlink_agent_memory_block(
|
|
991
|
+
self, block_id: str, *, agent_id: str, request_options: typing.Optional[RequestOptions] = None
|
|
992
|
+
) -> None:
|
|
993
|
+
"""
|
|
994
|
+
Unlink a memory block from an agent
|
|
995
|
+
|
|
996
|
+
Parameters
|
|
997
|
+
----------
|
|
998
|
+
block_id : str
|
|
999
|
+
|
|
1000
|
+
agent_id : str
|
|
1001
|
+
The unique identifier of the agent to attach the source to.
|
|
1002
|
+
|
|
1003
|
+
request_options : typing.Optional[RequestOptions]
|
|
1004
|
+
Request-specific configuration.
|
|
1005
|
+
|
|
1006
|
+
Returns
|
|
1007
|
+
-------
|
|
1008
|
+
None
|
|
1009
|
+
|
|
1010
|
+
Examples
|
|
1011
|
+
--------
|
|
1012
|
+
import asyncio
|
|
1013
|
+
|
|
1014
|
+
from letta import AsyncLetta
|
|
1015
|
+
|
|
1016
|
+
client = AsyncLetta(
|
|
1017
|
+
token="YOUR_TOKEN",
|
|
1018
|
+
)
|
|
1019
|
+
|
|
1020
|
+
|
|
1021
|
+
async def main() -> None:
|
|
1022
|
+
await client.blocks.unlink_agent_memory_block(
|
|
1023
|
+
block_id="block_id",
|
|
1024
|
+
agent_id="agent_id",
|
|
1025
|
+
)
|
|
1026
|
+
|
|
1027
|
+
|
|
1028
|
+
asyncio.run(main())
|
|
1029
|
+
"""
|
|
1030
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
1031
|
+
f"v1/blocks/{jsonable_encoder(block_id)}/detach",
|
|
1032
|
+
method="PATCH",
|
|
1033
|
+
params={
|
|
1034
|
+
"agent_id": agent_id,
|
|
1035
|
+
},
|
|
1036
|
+
request_options=request_options,
|
|
1037
|
+
)
|
|
1038
|
+
try:
|
|
1039
|
+
if 200 <= _response.status_code < 300:
|
|
1040
|
+
return
|
|
1041
|
+
if _response.status_code == 422:
|
|
1042
|
+
raise UnprocessableEntityError(
|
|
1043
|
+
typing.cast(
|
|
1044
|
+
HttpValidationError,
|
|
1045
|
+
parse_obj_as(
|
|
1046
|
+
type_=HttpValidationError, # type: ignore
|
|
1047
|
+
object_=_response.json(),
|
|
1048
|
+
),
|
|
1049
|
+
)
|
|
1050
|
+
)
|
|
1051
|
+
_response_json = _response.json()
|
|
1052
|
+
except JSONDecodeError:
|
|
1053
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
1054
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|