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/tools/client.py
ADDED
|
@@ -0,0 +1,1823 @@
|
|
|
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.letta_schemas_tool_tool import LettaSchemasToolTool
|
|
7
|
+
from ..core.jsonable_encoder import jsonable_encoder
|
|
8
|
+
from ..core.pydantic_utilities import parse_obj_as
|
|
9
|
+
from ..errors.unprocessable_entity_error import UnprocessableEntityError
|
|
10
|
+
from ..types.http_validation_error import HttpValidationError
|
|
11
|
+
from json.decoder import JSONDecodeError
|
|
12
|
+
from ..core.api_error import ApiError
|
|
13
|
+
from ..types.tool_return_message import ToolReturnMessage
|
|
14
|
+
from ..types.app_model import AppModel
|
|
15
|
+
from ..types.action_model import ActionModel
|
|
16
|
+
from ..core.client_wrapper import AsyncClientWrapper
|
|
17
|
+
|
|
18
|
+
# this is used as the default value for optional parameters
|
|
19
|
+
OMIT = typing.cast(typing.Any, ...)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class ToolsClient:
|
|
23
|
+
def __init__(self, *, client_wrapper: SyncClientWrapper):
|
|
24
|
+
self._client_wrapper = client_wrapper
|
|
25
|
+
|
|
26
|
+
def get(self, tool_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> LettaSchemasToolTool:
|
|
27
|
+
"""
|
|
28
|
+
Get a tool by ID
|
|
29
|
+
|
|
30
|
+
Parameters
|
|
31
|
+
----------
|
|
32
|
+
tool_id : str
|
|
33
|
+
|
|
34
|
+
request_options : typing.Optional[RequestOptions]
|
|
35
|
+
Request-specific configuration.
|
|
36
|
+
|
|
37
|
+
Returns
|
|
38
|
+
-------
|
|
39
|
+
LettaSchemasToolTool
|
|
40
|
+
Successful Response
|
|
41
|
+
|
|
42
|
+
Examples
|
|
43
|
+
--------
|
|
44
|
+
from letta import Letta
|
|
45
|
+
|
|
46
|
+
client = Letta(
|
|
47
|
+
token="YOUR_TOKEN",
|
|
48
|
+
)
|
|
49
|
+
client.tools.get(
|
|
50
|
+
tool_id="tool_id",
|
|
51
|
+
)
|
|
52
|
+
"""
|
|
53
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
54
|
+
f"v1/tools/{jsonable_encoder(tool_id)}",
|
|
55
|
+
method="GET",
|
|
56
|
+
request_options=request_options,
|
|
57
|
+
)
|
|
58
|
+
try:
|
|
59
|
+
if 200 <= _response.status_code < 300:
|
|
60
|
+
return typing.cast(
|
|
61
|
+
LettaSchemasToolTool,
|
|
62
|
+
parse_obj_as(
|
|
63
|
+
type_=LettaSchemasToolTool, # type: ignore
|
|
64
|
+
object_=_response.json(),
|
|
65
|
+
),
|
|
66
|
+
)
|
|
67
|
+
if _response.status_code == 422:
|
|
68
|
+
raise UnprocessableEntityError(
|
|
69
|
+
typing.cast(
|
|
70
|
+
HttpValidationError,
|
|
71
|
+
parse_obj_as(
|
|
72
|
+
type_=HttpValidationError, # type: ignore
|
|
73
|
+
object_=_response.json(),
|
|
74
|
+
),
|
|
75
|
+
)
|
|
76
|
+
)
|
|
77
|
+
_response_json = _response.json()
|
|
78
|
+
except JSONDecodeError:
|
|
79
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
80
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
81
|
+
|
|
82
|
+
def delete(
|
|
83
|
+
self, tool_id: str, *, request_options: typing.Optional[RequestOptions] = None
|
|
84
|
+
) -> typing.Optional[typing.Any]:
|
|
85
|
+
"""
|
|
86
|
+
Delete a tool by name
|
|
87
|
+
|
|
88
|
+
Parameters
|
|
89
|
+
----------
|
|
90
|
+
tool_id : str
|
|
91
|
+
|
|
92
|
+
request_options : typing.Optional[RequestOptions]
|
|
93
|
+
Request-specific configuration.
|
|
94
|
+
|
|
95
|
+
Returns
|
|
96
|
+
-------
|
|
97
|
+
typing.Optional[typing.Any]
|
|
98
|
+
Successful Response
|
|
99
|
+
|
|
100
|
+
Examples
|
|
101
|
+
--------
|
|
102
|
+
from letta import Letta
|
|
103
|
+
|
|
104
|
+
client = Letta(
|
|
105
|
+
token="YOUR_TOKEN",
|
|
106
|
+
)
|
|
107
|
+
client.tools.delete(
|
|
108
|
+
tool_id="tool_id",
|
|
109
|
+
)
|
|
110
|
+
"""
|
|
111
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
112
|
+
f"v1/tools/{jsonable_encoder(tool_id)}",
|
|
113
|
+
method="DELETE",
|
|
114
|
+
request_options=request_options,
|
|
115
|
+
)
|
|
116
|
+
try:
|
|
117
|
+
if 200 <= _response.status_code < 300:
|
|
118
|
+
return typing.cast(
|
|
119
|
+
typing.Optional[typing.Any],
|
|
120
|
+
parse_obj_as(
|
|
121
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
122
|
+
object_=_response.json(),
|
|
123
|
+
),
|
|
124
|
+
)
|
|
125
|
+
if _response.status_code == 422:
|
|
126
|
+
raise UnprocessableEntityError(
|
|
127
|
+
typing.cast(
|
|
128
|
+
HttpValidationError,
|
|
129
|
+
parse_obj_as(
|
|
130
|
+
type_=HttpValidationError, # type: ignore
|
|
131
|
+
object_=_response.json(),
|
|
132
|
+
),
|
|
133
|
+
)
|
|
134
|
+
)
|
|
135
|
+
_response_json = _response.json()
|
|
136
|
+
except JSONDecodeError:
|
|
137
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
138
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
139
|
+
|
|
140
|
+
def update(
|
|
141
|
+
self,
|
|
142
|
+
tool_id: str,
|
|
143
|
+
*,
|
|
144
|
+
description: typing.Optional[str] = OMIT,
|
|
145
|
+
name: typing.Optional[str] = OMIT,
|
|
146
|
+
tags: typing.Optional[typing.Sequence[str]] = OMIT,
|
|
147
|
+
module: typing.Optional[str] = OMIT,
|
|
148
|
+
source_code: typing.Optional[str] = OMIT,
|
|
149
|
+
source_type: typing.Optional[str] = OMIT,
|
|
150
|
+
json_schema: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
|
|
151
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
152
|
+
) -> LettaSchemasToolTool:
|
|
153
|
+
"""
|
|
154
|
+
Update an existing tool
|
|
155
|
+
|
|
156
|
+
Parameters
|
|
157
|
+
----------
|
|
158
|
+
tool_id : str
|
|
159
|
+
|
|
160
|
+
description : typing.Optional[str]
|
|
161
|
+
The description of the tool.
|
|
162
|
+
|
|
163
|
+
name : typing.Optional[str]
|
|
164
|
+
The name of the function.
|
|
165
|
+
|
|
166
|
+
tags : typing.Optional[typing.Sequence[str]]
|
|
167
|
+
Metadata tags.
|
|
168
|
+
|
|
169
|
+
module : typing.Optional[str]
|
|
170
|
+
The source code of the function.
|
|
171
|
+
|
|
172
|
+
source_code : typing.Optional[str]
|
|
173
|
+
The source code of the function.
|
|
174
|
+
|
|
175
|
+
source_type : typing.Optional[str]
|
|
176
|
+
The type of the source code.
|
|
177
|
+
|
|
178
|
+
json_schema : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
|
|
179
|
+
The JSON schema of the function (auto-generated from source_code if not provided)
|
|
180
|
+
|
|
181
|
+
request_options : typing.Optional[RequestOptions]
|
|
182
|
+
Request-specific configuration.
|
|
183
|
+
|
|
184
|
+
Returns
|
|
185
|
+
-------
|
|
186
|
+
LettaSchemasToolTool
|
|
187
|
+
Successful Response
|
|
188
|
+
|
|
189
|
+
Examples
|
|
190
|
+
--------
|
|
191
|
+
from letta import Letta
|
|
192
|
+
|
|
193
|
+
client = Letta(
|
|
194
|
+
token="YOUR_TOKEN",
|
|
195
|
+
)
|
|
196
|
+
client.tools.update(
|
|
197
|
+
tool_id="tool_id",
|
|
198
|
+
)
|
|
199
|
+
"""
|
|
200
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
201
|
+
f"v1/tools/{jsonable_encoder(tool_id)}",
|
|
202
|
+
method="PATCH",
|
|
203
|
+
json={
|
|
204
|
+
"description": description,
|
|
205
|
+
"name": name,
|
|
206
|
+
"tags": tags,
|
|
207
|
+
"module": module,
|
|
208
|
+
"source_code": source_code,
|
|
209
|
+
"source_type": source_type,
|
|
210
|
+
"json_schema": json_schema,
|
|
211
|
+
},
|
|
212
|
+
headers={
|
|
213
|
+
"content-type": "application/json",
|
|
214
|
+
},
|
|
215
|
+
request_options=request_options,
|
|
216
|
+
omit=OMIT,
|
|
217
|
+
)
|
|
218
|
+
try:
|
|
219
|
+
if 200 <= _response.status_code < 300:
|
|
220
|
+
return typing.cast(
|
|
221
|
+
LettaSchemasToolTool,
|
|
222
|
+
parse_obj_as(
|
|
223
|
+
type_=LettaSchemasToolTool, # 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 get_by_name(self, tool_name: str, *, request_options: typing.Optional[RequestOptions] = None) -> str:
|
|
243
|
+
"""
|
|
244
|
+
Get a tool ID by name
|
|
245
|
+
|
|
246
|
+
Parameters
|
|
247
|
+
----------
|
|
248
|
+
tool_name : str
|
|
249
|
+
|
|
250
|
+
request_options : typing.Optional[RequestOptions]
|
|
251
|
+
Request-specific configuration.
|
|
252
|
+
|
|
253
|
+
Returns
|
|
254
|
+
-------
|
|
255
|
+
str
|
|
256
|
+
Successful Response
|
|
257
|
+
|
|
258
|
+
Examples
|
|
259
|
+
--------
|
|
260
|
+
from letta import Letta
|
|
261
|
+
|
|
262
|
+
client = Letta(
|
|
263
|
+
token="YOUR_TOKEN",
|
|
264
|
+
)
|
|
265
|
+
client.tools.get_by_name(
|
|
266
|
+
tool_name="tool_name",
|
|
267
|
+
)
|
|
268
|
+
"""
|
|
269
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
270
|
+
f"v1/tools/name/{jsonable_encoder(tool_name)}",
|
|
271
|
+
method="GET",
|
|
272
|
+
request_options=request_options,
|
|
273
|
+
)
|
|
274
|
+
try:
|
|
275
|
+
if 200 <= _response.status_code < 300:
|
|
276
|
+
return typing.cast(
|
|
277
|
+
str,
|
|
278
|
+
parse_obj_as(
|
|
279
|
+
type_=str, # type: ignore
|
|
280
|
+
object_=_response.json(),
|
|
281
|
+
),
|
|
282
|
+
)
|
|
283
|
+
if _response.status_code == 422:
|
|
284
|
+
raise UnprocessableEntityError(
|
|
285
|
+
typing.cast(
|
|
286
|
+
HttpValidationError,
|
|
287
|
+
parse_obj_as(
|
|
288
|
+
type_=HttpValidationError, # type: ignore
|
|
289
|
+
object_=_response.json(),
|
|
290
|
+
),
|
|
291
|
+
)
|
|
292
|
+
)
|
|
293
|
+
_response_json = _response.json()
|
|
294
|
+
except JSONDecodeError:
|
|
295
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
296
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
297
|
+
|
|
298
|
+
def list(
|
|
299
|
+
self,
|
|
300
|
+
*,
|
|
301
|
+
cursor: typing.Optional[str] = None,
|
|
302
|
+
limit: typing.Optional[int] = None,
|
|
303
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
304
|
+
) -> typing.List[LettaSchemasToolTool]:
|
|
305
|
+
"""
|
|
306
|
+
Get a list of all tools available to agents belonging to the org of the user
|
|
307
|
+
|
|
308
|
+
Parameters
|
|
309
|
+
----------
|
|
310
|
+
cursor : typing.Optional[str]
|
|
311
|
+
|
|
312
|
+
limit : typing.Optional[int]
|
|
313
|
+
|
|
314
|
+
request_options : typing.Optional[RequestOptions]
|
|
315
|
+
Request-specific configuration.
|
|
316
|
+
|
|
317
|
+
Returns
|
|
318
|
+
-------
|
|
319
|
+
typing.List[LettaSchemasToolTool]
|
|
320
|
+
Successful Response
|
|
321
|
+
|
|
322
|
+
Examples
|
|
323
|
+
--------
|
|
324
|
+
from letta import Letta
|
|
325
|
+
|
|
326
|
+
client = Letta(
|
|
327
|
+
token="YOUR_TOKEN",
|
|
328
|
+
)
|
|
329
|
+
client.tools.list()
|
|
330
|
+
"""
|
|
331
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
332
|
+
"v1/tools/",
|
|
333
|
+
method="GET",
|
|
334
|
+
params={
|
|
335
|
+
"cursor": cursor,
|
|
336
|
+
"limit": limit,
|
|
337
|
+
},
|
|
338
|
+
request_options=request_options,
|
|
339
|
+
)
|
|
340
|
+
try:
|
|
341
|
+
if 200 <= _response.status_code < 300:
|
|
342
|
+
return typing.cast(
|
|
343
|
+
typing.List[LettaSchemasToolTool],
|
|
344
|
+
parse_obj_as(
|
|
345
|
+
type_=typing.List[LettaSchemasToolTool], # type: ignore
|
|
346
|
+
object_=_response.json(),
|
|
347
|
+
),
|
|
348
|
+
)
|
|
349
|
+
if _response.status_code == 422:
|
|
350
|
+
raise UnprocessableEntityError(
|
|
351
|
+
typing.cast(
|
|
352
|
+
HttpValidationError,
|
|
353
|
+
parse_obj_as(
|
|
354
|
+
type_=HttpValidationError, # type: ignore
|
|
355
|
+
object_=_response.json(),
|
|
356
|
+
),
|
|
357
|
+
)
|
|
358
|
+
)
|
|
359
|
+
_response_json = _response.json()
|
|
360
|
+
except JSONDecodeError:
|
|
361
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
362
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
363
|
+
|
|
364
|
+
def create(
|
|
365
|
+
self,
|
|
366
|
+
*,
|
|
367
|
+
source_code: str,
|
|
368
|
+
name: typing.Optional[str] = OMIT,
|
|
369
|
+
description: typing.Optional[str] = OMIT,
|
|
370
|
+
tags: typing.Optional[typing.Sequence[str]] = OMIT,
|
|
371
|
+
module: typing.Optional[str] = OMIT,
|
|
372
|
+
source_type: typing.Optional[str] = OMIT,
|
|
373
|
+
json_schema: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
|
|
374
|
+
return_char_limit: typing.Optional[int] = OMIT,
|
|
375
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
376
|
+
) -> LettaSchemasToolTool:
|
|
377
|
+
"""
|
|
378
|
+
Create a new tool
|
|
379
|
+
|
|
380
|
+
Parameters
|
|
381
|
+
----------
|
|
382
|
+
source_code : str
|
|
383
|
+
The source code of the function.
|
|
384
|
+
|
|
385
|
+
name : typing.Optional[str]
|
|
386
|
+
The name of the function (auto-generated from source_code if not provided).
|
|
387
|
+
|
|
388
|
+
description : typing.Optional[str]
|
|
389
|
+
The description of the tool.
|
|
390
|
+
|
|
391
|
+
tags : typing.Optional[typing.Sequence[str]]
|
|
392
|
+
Metadata tags.
|
|
393
|
+
|
|
394
|
+
module : typing.Optional[str]
|
|
395
|
+
The source code of the function.
|
|
396
|
+
|
|
397
|
+
source_type : typing.Optional[str]
|
|
398
|
+
The source type of the function.
|
|
399
|
+
|
|
400
|
+
json_schema : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
|
|
401
|
+
The JSON schema of the function (auto-generated from source_code if not provided)
|
|
402
|
+
|
|
403
|
+
return_char_limit : typing.Optional[int]
|
|
404
|
+
The maximum number of characters in the response.
|
|
405
|
+
|
|
406
|
+
request_options : typing.Optional[RequestOptions]
|
|
407
|
+
Request-specific configuration.
|
|
408
|
+
|
|
409
|
+
Returns
|
|
410
|
+
-------
|
|
411
|
+
LettaSchemasToolTool
|
|
412
|
+
Successful Response
|
|
413
|
+
|
|
414
|
+
Examples
|
|
415
|
+
--------
|
|
416
|
+
from letta import Letta
|
|
417
|
+
|
|
418
|
+
client = Letta(
|
|
419
|
+
token="YOUR_TOKEN",
|
|
420
|
+
)
|
|
421
|
+
client.tools.create(
|
|
422
|
+
source_code="source_code",
|
|
423
|
+
)
|
|
424
|
+
"""
|
|
425
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
426
|
+
"v1/tools/",
|
|
427
|
+
method="POST",
|
|
428
|
+
json={
|
|
429
|
+
"name": name,
|
|
430
|
+
"description": description,
|
|
431
|
+
"tags": tags,
|
|
432
|
+
"module": module,
|
|
433
|
+
"source_code": source_code,
|
|
434
|
+
"source_type": source_type,
|
|
435
|
+
"json_schema": json_schema,
|
|
436
|
+
"return_char_limit": return_char_limit,
|
|
437
|
+
},
|
|
438
|
+
request_options=request_options,
|
|
439
|
+
omit=OMIT,
|
|
440
|
+
)
|
|
441
|
+
try:
|
|
442
|
+
if 200 <= _response.status_code < 300:
|
|
443
|
+
return typing.cast(
|
|
444
|
+
LettaSchemasToolTool,
|
|
445
|
+
parse_obj_as(
|
|
446
|
+
type_=LettaSchemasToolTool, # type: ignore
|
|
447
|
+
object_=_response.json(),
|
|
448
|
+
),
|
|
449
|
+
)
|
|
450
|
+
if _response.status_code == 422:
|
|
451
|
+
raise UnprocessableEntityError(
|
|
452
|
+
typing.cast(
|
|
453
|
+
HttpValidationError,
|
|
454
|
+
parse_obj_as(
|
|
455
|
+
type_=HttpValidationError, # type: ignore
|
|
456
|
+
object_=_response.json(),
|
|
457
|
+
),
|
|
458
|
+
)
|
|
459
|
+
)
|
|
460
|
+
_response_json = _response.json()
|
|
461
|
+
except JSONDecodeError:
|
|
462
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
463
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
464
|
+
|
|
465
|
+
def upsert(
|
|
466
|
+
self,
|
|
467
|
+
*,
|
|
468
|
+
source_code: str,
|
|
469
|
+
name: typing.Optional[str] = OMIT,
|
|
470
|
+
description: typing.Optional[str] = OMIT,
|
|
471
|
+
tags: typing.Optional[typing.Sequence[str]] = OMIT,
|
|
472
|
+
module: typing.Optional[str] = OMIT,
|
|
473
|
+
source_type: typing.Optional[str] = OMIT,
|
|
474
|
+
json_schema: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
|
|
475
|
+
return_char_limit: typing.Optional[int] = OMIT,
|
|
476
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
477
|
+
) -> LettaSchemasToolTool:
|
|
478
|
+
"""
|
|
479
|
+
Create or update a tool
|
|
480
|
+
|
|
481
|
+
Parameters
|
|
482
|
+
----------
|
|
483
|
+
source_code : str
|
|
484
|
+
The source code of the function.
|
|
485
|
+
|
|
486
|
+
name : typing.Optional[str]
|
|
487
|
+
The name of the function (auto-generated from source_code if not provided).
|
|
488
|
+
|
|
489
|
+
description : typing.Optional[str]
|
|
490
|
+
The description of the tool.
|
|
491
|
+
|
|
492
|
+
tags : typing.Optional[typing.Sequence[str]]
|
|
493
|
+
Metadata tags.
|
|
494
|
+
|
|
495
|
+
module : typing.Optional[str]
|
|
496
|
+
The source code of the function.
|
|
497
|
+
|
|
498
|
+
source_type : typing.Optional[str]
|
|
499
|
+
The source type of the function.
|
|
500
|
+
|
|
501
|
+
json_schema : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
|
|
502
|
+
The JSON schema of the function (auto-generated from source_code if not provided)
|
|
503
|
+
|
|
504
|
+
return_char_limit : typing.Optional[int]
|
|
505
|
+
The maximum number of characters in the response.
|
|
506
|
+
|
|
507
|
+
request_options : typing.Optional[RequestOptions]
|
|
508
|
+
Request-specific configuration.
|
|
509
|
+
|
|
510
|
+
Returns
|
|
511
|
+
-------
|
|
512
|
+
LettaSchemasToolTool
|
|
513
|
+
Successful Response
|
|
514
|
+
|
|
515
|
+
Examples
|
|
516
|
+
--------
|
|
517
|
+
from letta import Letta
|
|
518
|
+
|
|
519
|
+
client = Letta(
|
|
520
|
+
token="YOUR_TOKEN",
|
|
521
|
+
)
|
|
522
|
+
client.tools.upsert(
|
|
523
|
+
source_code="source_code",
|
|
524
|
+
)
|
|
525
|
+
"""
|
|
526
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
527
|
+
"v1/tools/",
|
|
528
|
+
method="PUT",
|
|
529
|
+
json={
|
|
530
|
+
"name": name,
|
|
531
|
+
"description": description,
|
|
532
|
+
"tags": tags,
|
|
533
|
+
"module": module,
|
|
534
|
+
"source_code": source_code,
|
|
535
|
+
"source_type": source_type,
|
|
536
|
+
"json_schema": json_schema,
|
|
537
|
+
"return_char_limit": return_char_limit,
|
|
538
|
+
},
|
|
539
|
+
request_options=request_options,
|
|
540
|
+
omit=OMIT,
|
|
541
|
+
)
|
|
542
|
+
try:
|
|
543
|
+
if 200 <= _response.status_code < 300:
|
|
544
|
+
return typing.cast(
|
|
545
|
+
LettaSchemasToolTool,
|
|
546
|
+
parse_obj_as(
|
|
547
|
+
type_=LettaSchemasToolTool, # type: ignore
|
|
548
|
+
object_=_response.json(),
|
|
549
|
+
),
|
|
550
|
+
)
|
|
551
|
+
if _response.status_code == 422:
|
|
552
|
+
raise UnprocessableEntityError(
|
|
553
|
+
typing.cast(
|
|
554
|
+
HttpValidationError,
|
|
555
|
+
parse_obj_as(
|
|
556
|
+
type_=HttpValidationError, # type: ignore
|
|
557
|
+
object_=_response.json(),
|
|
558
|
+
),
|
|
559
|
+
)
|
|
560
|
+
)
|
|
561
|
+
_response_json = _response.json()
|
|
562
|
+
except JSONDecodeError:
|
|
563
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
564
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
565
|
+
|
|
566
|
+
def add_base_tool(
|
|
567
|
+
self, *, request_options: typing.Optional[RequestOptions] = None
|
|
568
|
+
) -> typing.List[LettaSchemasToolTool]:
|
|
569
|
+
"""
|
|
570
|
+
Upsert base tools
|
|
571
|
+
|
|
572
|
+
Parameters
|
|
573
|
+
----------
|
|
574
|
+
request_options : typing.Optional[RequestOptions]
|
|
575
|
+
Request-specific configuration.
|
|
576
|
+
|
|
577
|
+
Returns
|
|
578
|
+
-------
|
|
579
|
+
typing.List[LettaSchemasToolTool]
|
|
580
|
+
Successful Response
|
|
581
|
+
|
|
582
|
+
Examples
|
|
583
|
+
--------
|
|
584
|
+
from letta import Letta
|
|
585
|
+
|
|
586
|
+
client = Letta(
|
|
587
|
+
token="YOUR_TOKEN",
|
|
588
|
+
)
|
|
589
|
+
client.tools.add_base_tool()
|
|
590
|
+
"""
|
|
591
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
592
|
+
"v1/tools/add-base-tools",
|
|
593
|
+
method="POST",
|
|
594
|
+
request_options=request_options,
|
|
595
|
+
)
|
|
596
|
+
try:
|
|
597
|
+
if 200 <= _response.status_code < 300:
|
|
598
|
+
return typing.cast(
|
|
599
|
+
typing.List[LettaSchemasToolTool],
|
|
600
|
+
parse_obj_as(
|
|
601
|
+
type_=typing.List[LettaSchemasToolTool], # type: ignore
|
|
602
|
+
object_=_response.json(),
|
|
603
|
+
),
|
|
604
|
+
)
|
|
605
|
+
if _response.status_code == 422:
|
|
606
|
+
raise UnprocessableEntityError(
|
|
607
|
+
typing.cast(
|
|
608
|
+
HttpValidationError,
|
|
609
|
+
parse_obj_as(
|
|
610
|
+
type_=HttpValidationError, # type: ignore
|
|
611
|
+
object_=_response.json(),
|
|
612
|
+
),
|
|
613
|
+
)
|
|
614
|
+
)
|
|
615
|
+
_response_json = _response.json()
|
|
616
|
+
except JSONDecodeError:
|
|
617
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
618
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
619
|
+
|
|
620
|
+
def run_tool_from_source(
|
|
621
|
+
self,
|
|
622
|
+
*,
|
|
623
|
+
source_code: str,
|
|
624
|
+
args: str,
|
|
625
|
+
name: typing.Optional[str] = OMIT,
|
|
626
|
+
source_type: typing.Optional[str] = OMIT,
|
|
627
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
628
|
+
) -> ToolReturnMessage:
|
|
629
|
+
"""
|
|
630
|
+
Attempt to build a tool from source, then run it on the provided arguments
|
|
631
|
+
|
|
632
|
+
Parameters
|
|
633
|
+
----------
|
|
634
|
+
source_code : str
|
|
635
|
+
The source code of the function.
|
|
636
|
+
|
|
637
|
+
args : str
|
|
638
|
+
The arguments to pass to the tool (as stringified JSON).
|
|
639
|
+
|
|
640
|
+
name : typing.Optional[str]
|
|
641
|
+
The name of the tool to run.
|
|
642
|
+
|
|
643
|
+
source_type : typing.Optional[str]
|
|
644
|
+
The type of the source code.
|
|
645
|
+
|
|
646
|
+
request_options : typing.Optional[RequestOptions]
|
|
647
|
+
Request-specific configuration.
|
|
648
|
+
|
|
649
|
+
Returns
|
|
650
|
+
-------
|
|
651
|
+
ToolReturnMessage
|
|
652
|
+
Successful Response
|
|
653
|
+
|
|
654
|
+
Examples
|
|
655
|
+
--------
|
|
656
|
+
from letta import Letta
|
|
657
|
+
|
|
658
|
+
client = Letta(
|
|
659
|
+
token="YOUR_TOKEN",
|
|
660
|
+
)
|
|
661
|
+
client.tools.run_tool_from_source(
|
|
662
|
+
source_code="source_code",
|
|
663
|
+
args="args",
|
|
664
|
+
)
|
|
665
|
+
"""
|
|
666
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
667
|
+
"v1/tools/run",
|
|
668
|
+
method="POST",
|
|
669
|
+
json={
|
|
670
|
+
"source_code": source_code,
|
|
671
|
+
"args": args,
|
|
672
|
+
"name": name,
|
|
673
|
+
"source_type": source_type,
|
|
674
|
+
},
|
|
675
|
+
headers={
|
|
676
|
+
"content-type": "application/json",
|
|
677
|
+
},
|
|
678
|
+
request_options=request_options,
|
|
679
|
+
omit=OMIT,
|
|
680
|
+
)
|
|
681
|
+
try:
|
|
682
|
+
if 200 <= _response.status_code < 300:
|
|
683
|
+
return typing.cast(
|
|
684
|
+
ToolReturnMessage,
|
|
685
|
+
parse_obj_as(
|
|
686
|
+
type_=ToolReturnMessage, # type: ignore
|
|
687
|
+
object_=_response.json(),
|
|
688
|
+
),
|
|
689
|
+
)
|
|
690
|
+
if _response.status_code == 422:
|
|
691
|
+
raise UnprocessableEntityError(
|
|
692
|
+
typing.cast(
|
|
693
|
+
HttpValidationError,
|
|
694
|
+
parse_obj_as(
|
|
695
|
+
type_=HttpValidationError, # type: ignore
|
|
696
|
+
object_=_response.json(),
|
|
697
|
+
),
|
|
698
|
+
)
|
|
699
|
+
)
|
|
700
|
+
_response_json = _response.json()
|
|
701
|
+
except JSONDecodeError:
|
|
702
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
703
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
704
|
+
|
|
705
|
+
def list_composio_apps(self, *, request_options: typing.Optional[RequestOptions] = None) -> typing.List[AppModel]:
|
|
706
|
+
"""
|
|
707
|
+
Get a list of all Composio apps
|
|
708
|
+
|
|
709
|
+
Parameters
|
|
710
|
+
----------
|
|
711
|
+
request_options : typing.Optional[RequestOptions]
|
|
712
|
+
Request-specific configuration.
|
|
713
|
+
|
|
714
|
+
Returns
|
|
715
|
+
-------
|
|
716
|
+
typing.List[AppModel]
|
|
717
|
+
Successful Response
|
|
718
|
+
|
|
719
|
+
Examples
|
|
720
|
+
--------
|
|
721
|
+
from letta import Letta
|
|
722
|
+
|
|
723
|
+
client = Letta(
|
|
724
|
+
token="YOUR_TOKEN",
|
|
725
|
+
)
|
|
726
|
+
client.tools.list_composio_apps()
|
|
727
|
+
"""
|
|
728
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
729
|
+
"v1/tools/composio/apps",
|
|
730
|
+
method="GET",
|
|
731
|
+
request_options=request_options,
|
|
732
|
+
)
|
|
733
|
+
try:
|
|
734
|
+
if 200 <= _response.status_code < 300:
|
|
735
|
+
return typing.cast(
|
|
736
|
+
typing.List[AppModel],
|
|
737
|
+
parse_obj_as(
|
|
738
|
+
type_=typing.List[AppModel], # 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
|
+
def list_composio_actions_by_app(
|
|
758
|
+
self, composio_app_name: str, *, request_options: typing.Optional[RequestOptions] = None
|
|
759
|
+
) -> typing.List[ActionModel]:
|
|
760
|
+
"""
|
|
761
|
+
Get a list of all Composio actions for a specific app
|
|
762
|
+
|
|
763
|
+
Parameters
|
|
764
|
+
----------
|
|
765
|
+
composio_app_name : str
|
|
766
|
+
|
|
767
|
+
request_options : typing.Optional[RequestOptions]
|
|
768
|
+
Request-specific configuration.
|
|
769
|
+
|
|
770
|
+
Returns
|
|
771
|
+
-------
|
|
772
|
+
typing.List[ActionModel]
|
|
773
|
+
Successful Response
|
|
774
|
+
|
|
775
|
+
Examples
|
|
776
|
+
--------
|
|
777
|
+
from letta import Letta
|
|
778
|
+
|
|
779
|
+
client = Letta(
|
|
780
|
+
token="YOUR_TOKEN",
|
|
781
|
+
)
|
|
782
|
+
client.tools.list_composio_actions_by_app(
|
|
783
|
+
composio_app_name="composio_app_name",
|
|
784
|
+
)
|
|
785
|
+
"""
|
|
786
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
787
|
+
f"v1/tools/composio/apps/{jsonable_encoder(composio_app_name)}/actions",
|
|
788
|
+
method="GET",
|
|
789
|
+
request_options=request_options,
|
|
790
|
+
)
|
|
791
|
+
try:
|
|
792
|
+
if 200 <= _response.status_code < 300:
|
|
793
|
+
return typing.cast(
|
|
794
|
+
typing.List[ActionModel],
|
|
795
|
+
parse_obj_as(
|
|
796
|
+
type_=typing.List[ActionModel], # type: ignore
|
|
797
|
+
object_=_response.json(),
|
|
798
|
+
),
|
|
799
|
+
)
|
|
800
|
+
if _response.status_code == 422:
|
|
801
|
+
raise UnprocessableEntityError(
|
|
802
|
+
typing.cast(
|
|
803
|
+
HttpValidationError,
|
|
804
|
+
parse_obj_as(
|
|
805
|
+
type_=HttpValidationError, # type: ignore
|
|
806
|
+
object_=_response.json(),
|
|
807
|
+
),
|
|
808
|
+
)
|
|
809
|
+
)
|
|
810
|
+
_response_json = _response.json()
|
|
811
|
+
except JSONDecodeError:
|
|
812
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
813
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
814
|
+
|
|
815
|
+
def add_composio_tool(
|
|
816
|
+
self, composio_action_name: str, *, request_options: typing.Optional[RequestOptions] = None
|
|
817
|
+
) -> LettaSchemasToolTool:
|
|
818
|
+
"""
|
|
819
|
+
Add a new Composio tool by action name (Composio refers to each tool as an `Action`)
|
|
820
|
+
|
|
821
|
+
Parameters
|
|
822
|
+
----------
|
|
823
|
+
composio_action_name : str
|
|
824
|
+
|
|
825
|
+
request_options : typing.Optional[RequestOptions]
|
|
826
|
+
Request-specific configuration.
|
|
827
|
+
|
|
828
|
+
Returns
|
|
829
|
+
-------
|
|
830
|
+
LettaSchemasToolTool
|
|
831
|
+
Successful Response
|
|
832
|
+
|
|
833
|
+
Examples
|
|
834
|
+
--------
|
|
835
|
+
from letta import Letta
|
|
836
|
+
|
|
837
|
+
client = Letta(
|
|
838
|
+
token="YOUR_TOKEN",
|
|
839
|
+
)
|
|
840
|
+
client.tools.add_composio_tool(
|
|
841
|
+
composio_action_name="composio_action_name",
|
|
842
|
+
)
|
|
843
|
+
"""
|
|
844
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
845
|
+
f"v1/tools/composio/{jsonable_encoder(composio_action_name)}",
|
|
846
|
+
method="POST",
|
|
847
|
+
request_options=request_options,
|
|
848
|
+
)
|
|
849
|
+
try:
|
|
850
|
+
if 200 <= _response.status_code < 300:
|
|
851
|
+
return typing.cast(
|
|
852
|
+
LettaSchemasToolTool,
|
|
853
|
+
parse_obj_as(
|
|
854
|
+
type_=LettaSchemasToolTool, # type: ignore
|
|
855
|
+
object_=_response.json(),
|
|
856
|
+
),
|
|
857
|
+
)
|
|
858
|
+
if _response.status_code == 422:
|
|
859
|
+
raise UnprocessableEntityError(
|
|
860
|
+
typing.cast(
|
|
861
|
+
HttpValidationError,
|
|
862
|
+
parse_obj_as(
|
|
863
|
+
type_=HttpValidationError, # type: ignore
|
|
864
|
+
object_=_response.json(),
|
|
865
|
+
),
|
|
866
|
+
)
|
|
867
|
+
)
|
|
868
|
+
_response_json = _response.json()
|
|
869
|
+
except JSONDecodeError:
|
|
870
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
871
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
872
|
+
|
|
873
|
+
|
|
874
|
+
class AsyncToolsClient:
|
|
875
|
+
def __init__(self, *, client_wrapper: AsyncClientWrapper):
|
|
876
|
+
self._client_wrapper = client_wrapper
|
|
877
|
+
|
|
878
|
+
async def get(
|
|
879
|
+
self, tool_id: str, *, request_options: typing.Optional[RequestOptions] = None
|
|
880
|
+
) -> LettaSchemasToolTool:
|
|
881
|
+
"""
|
|
882
|
+
Get a tool by ID
|
|
883
|
+
|
|
884
|
+
Parameters
|
|
885
|
+
----------
|
|
886
|
+
tool_id : str
|
|
887
|
+
|
|
888
|
+
request_options : typing.Optional[RequestOptions]
|
|
889
|
+
Request-specific configuration.
|
|
890
|
+
|
|
891
|
+
Returns
|
|
892
|
+
-------
|
|
893
|
+
LettaSchemasToolTool
|
|
894
|
+
Successful Response
|
|
895
|
+
|
|
896
|
+
Examples
|
|
897
|
+
--------
|
|
898
|
+
import asyncio
|
|
899
|
+
|
|
900
|
+
from letta import AsyncLetta
|
|
901
|
+
|
|
902
|
+
client = AsyncLetta(
|
|
903
|
+
token="YOUR_TOKEN",
|
|
904
|
+
)
|
|
905
|
+
|
|
906
|
+
|
|
907
|
+
async def main() -> None:
|
|
908
|
+
await client.tools.get(
|
|
909
|
+
tool_id="tool_id",
|
|
910
|
+
)
|
|
911
|
+
|
|
912
|
+
|
|
913
|
+
asyncio.run(main())
|
|
914
|
+
"""
|
|
915
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
916
|
+
f"v1/tools/{jsonable_encoder(tool_id)}",
|
|
917
|
+
method="GET",
|
|
918
|
+
request_options=request_options,
|
|
919
|
+
)
|
|
920
|
+
try:
|
|
921
|
+
if 200 <= _response.status_code < 300:
|
|
922
|
+
return typing.cast(
|
|
923
|
+
LettaSchemasToolTool,
|
|
924
|
+
parse_obj_as(
|
|
925
|
+
type_=LettaSchemasToolTool, # type: ignore
|
|
926
|
+
object_=_response.json(),
|
|
927
|
+
),
|
|
928
|
+
)
|
|
929
|
+
if _response.status_code == 422:
|
|
930
|
+
raise UnprocessableEntityError(
|
|
931
|
+
typing.cast(
|
|
932
|
+
HttpValidationError,
|
|
933
|
+
parse_obj_as(
|
|
934
|
+
type_=HttpValidationError, # type: ignore
|
|
935
|
+
object_=_response.json(),
|
|
936
|
+
),
|
|
937
|
+
)
|
|
938
|
+
)
|
|
939
|
+
_response_json = _response.json()
|
|
940
|
+
except JSONDecodeError:
|
|
941
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
942
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
943
|
+
|
|
944
|
+
async def delete(
|
|
945
|
+
self, tool_id: str, *, request_options: typing.Optional[RequestOptions] = None
|
|
946
|
+
) -> typing.Optional[typing.Any]:
|
|
947
|
+
"""
|
|
948
|
+
Delete a tool by name
|
|
949
|
+
|
|
950
|
+
Parameters
|
|
951
|
+
----------
|
|
952
|
+
tool_id : str
|
|
953
|
+
|
|
954
|
+
request_options : typing.Optional[RequestOptions]
|
|
955
|
+
Request-specific configuration.
|
|
956
|
+
|
|
957
|
+
Returns
|
|
958
|
+
-------
|
|
959
|
+
typing.Optional[typing.Any]
|
|
960
|
+
Successful Response
|
|
961
|
+
|
|
962
|
+
Examples
|
|
963
|
+
--------
|
|
964
|
+
import asyncio
|
|
965
|
+
|
|
966
|
+
from letta import AsyncLetta
|
|
967
|
+
|
|
968
|
+
client = AsyncLetta(
|
|
969
|
+
token="YOUR_TOKEN",
|
|
970
|
+
)
|
|
971
|
+
|
|
972
|
+
|
|
973
|
+
async def main() -> None:
|
|
974
|
+
await client.tools.delete(
|
|
975
|
+
tool_id="tool_id",
|
|
976
|
+
)
|
|
977
|
+
|
|
978
|
+
|
|
979
|
+
asyncio.run(main())
|
|
980
|
+
"""
|
|
981
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
982
|
+
f"v1/tools/{jsonable_encoder(tool_id)}",
|
|
983
|
+
method="DELETE",
|
|
984
|
+
request_options=request_options,
|
|
985
|
+
)
|
|
986
|
+
try:
|
|
987
|
+
if 200 <= _response.status_code < 300:
|
|
988
|
+
return typing.cast(
|
|
989
|
+
typing.Optional[typing.Any],
|
|
990
|
+
parse_obj_as(
|
|
991
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
992
|
+
object_=_response.json(),
|
|
993
|
+
),
|
|
994
|
+
)
|
|
995
|
+
if _response.status_code == 422:
|
|
996
|
+
raise UnprocessableEntityError(
|
|
997
|
+
typing.cast(
|
|
998
|
+
HttpValidationError,
|
|
999
|
+
parse_obj_as(
|
|
1000
|
+
type_=HttpValidationError, # type: ignore
|
|
1001
|
+
object_=_response.json(),
|
|
1002
|
+
),
|
|
1003
|
+
)
|
|
1004
|
+
)
|
|
1005
|
+
_response_json = _response.json()
|
|
1006
|
+
except JSONDecodeError:
|
|
1007
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
1008
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
1009
|
+
|
|
1010
|
+
async def update(
|
|
1011
|
+
self,
|
|
1012
|
+
tool_id: str,
|
|
1013
|
+
*,
|
|
1014
|
+
description: typing.Optional[str] = OMIT,
|
|
1015
|
+
name: typing.Optional[str] = OMIT,
|
|
1016
|
+
tags: typing.Optional[typing.Sequence[str]] = OMIT,
|
|
1017
|
+
module: typing.Optional[str] = OMIT,
|
|
1018
|
+
source_code: typing.Optional[str] = OMIT,
|
|
1019
|
+
source_type: typing.Optional[str] = OMIT,
|
|
1020
|
+
json_schema: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
|
|
1021
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
1022
|
+
) -> LettaSchemasToolTool:
|
|
1023
|
+
"""
|
|
1024
|
+
Update an existing tool
|
|
1025
|
+
|
|
1026
|
+
Parameters
|
|
1027
|
+
----------
|
|
1028
|
+
tool_id : str
|
|
1029
|
+
|
|
1030
|
+
description : typing.Optional[str]
|
|
1031
|
+
The description of the tool.
|
|
1032
|
+
|
|
1033
|
+
name : typing.Optional[str]
|
|
1034
|
+
The name of the function.
|
|
1035
|
+
|
|
1036
|
+
tags : typing.Optional[typing.Sequence[str]]
|
|
1037
|
+
Metadata tags.
|
|
1038
|
+
|
|
1039
|
+
module : typing.Optional[str]
|
|
1040
|
+
The source code of the function.
|
|
1041
|
+
|
|
1042
|
+
source_code : typing.Optional[str]
|
|
1043
|
+
The source code of the function.
|
|
1044
|
+
|
|
1045
|
+
source_type : typing.Optional[str]
|
|
1046
|
+
The type of the source code.
|
|
1047
|
+
|
|
1048
|
+
json_schema : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
|
|
1049
|
+
The JSON schema of the function (auto-generated from source_code if not provided)
|
|
1050
|
+
|
|
1051
|
+
request_options : typing.Optional[RequestOptions]
|
|
1052
|
+
Request-specific configuration.
|
|
1053
|
+
|
|
1054
|
+
Returns
|
|
1055
|
+
-------
|
|
1056
|
+
LettaSchemasToolTool
|
|
1057
|
+
Successful Response
|
|
1058
|
+
|
|
1059
|
+
Examples
|
|
1060
|
+
--------
|
|
1061
|
+
import asyncio
|
|
1062
|
+
|
|
1063
|
+
from letta import AsyncLetta
|
|
1064
|
+
|
|
1065
|
+
client = AsyncLetta(
|
|
1066
|
+
token="YOUR_TOKEN",
|
|
1067
|
+
)
|
|
1068
|
+
|
|
1069
|
+
|
|
1070
|
+
async def main() -> None:
|
|
1071
|
+
await client.tools.update(
|
|
1072
|
+
tool_id="tool_id",
|
|
1073
|
+
)
|
|
1074
|
+
|
|
1075
|
+
|
|
1076
|
+
asyncio.run(main())
|
|
1077
|
+
"""
|
|
1078
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
1079
|
+
f"v1/tools/{jsonable_encoder(tool_id)}",
|
|
1080
|
+
method="PATCH",
|
|
1081
|
+
json={
|
|
1082
|
+
"description": description,
|
|
1083
|
+
"name": name,
|
|
1084
|
+
"tags": tags,
|
|
1085
|
+
"module": module,
|
|
1086
|
+
"source_code": source_code,
|
|
1087
|
+
"source_type": source_type,
|
|
1088
|
+
"json_schema": json_schema,
|
|
1089
|
+
},
|
|
1090
|
+
headers={
|
|
1091
|
+
"content-type": "application/json",
|
|
1092
|
+
},
|
|
1093
|
+
request_options=request_options,
|
|
1094
|
+
omit=OMIT,
|
|
1095
|
+
)
|
|
1096
|
+
try:
|
|
1097
|
+
if 200 <= _response.status_code < 300:
|
|
1098
|
+
return typing.cast(
|
|
1099
|
+
LettaSchemasToolTool,
|
|
1100
|
+
parse_obj_as(
|
|
1101
|
+
type_=LettaSchemasToolTool, # type: ignore
|
|
1102
|
+
object_=_response.json(),
|
|
1103
|
+
),
|
|
1104
|
+
)
|
|
1105
|
+
if _response.status_code == 422:
|
|
1106
|
+
raise UnprocessableEntityError(
|
|
1107
|
+
typing.cast(
|
|
1108
|
+
HttpValidationError,
|
|
1109
|
+
parse_obj_as(
|
|
1110
|
+
type_=HttpValidationError, # type: ignore
|
|
1111
|
+
object_=_response.json(),
|
|
1112
|
+
),
|
|
1113
|
+
)
|
|
1114
|
+
)
|
|
1115
|
+
_response_json = _response.json()
|
|
1116
|
+
except JSONDecodeError:
|
|
1117
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
1118
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
1119
|
+
|
|
1120
|
+
async def get_by_name(self, tool_name: str, *, request_options: typing.Optional[RequestOptions] = None) -> str:
|
|
1121
|
+
"""
|
|
1122
|
+
Get a tool ID by name
|
|
1123
|
+
|
|
1124
|
+
Parameters
|
|
1125
|
+
----------
|
|
1126
|
+
tool_name : str
|
|
1127
|
+
|
|
1128
|
+
request_options : typing.Optional[RequestOptions]
|
|
1129
|
+
Request-specific configuration.
|
|
1130
|
+
|
|
1131
|
+
Returns
|
|
1132
|
+
-------
|
|
1133
|
+
str
|
|
1134
|
+
Successful Response
|
|
1135
|
+
|
|
1136
|
+
Examples
|
|
1137
|
+
--------
|
|
1138
|
+
import asyncio
|
|
1139
|
+
|
|
1140
|
+
from letta import AsyncLetta
|
|
1141
|
+
|
|
1142
|
+
client = AsyncLetta(
|
|
1143
|
+
token="YOUR_TOKEN",
|
|
1144
|
+
)
|
|
1145
|
+
|
|
1146
|
+
|
|
1147
|
+
async def main() -> None:
|
|
1148
|
+
await client.tools.get_by_name(
|
|
1149
|
+
tool_name="tool_name",
|
|
1150
|
+
)
|
|
1151
|
+
|
|
1152
|
+
|
|
1153
|
+
asyncio.run(main())
|
|
1154
|
+
"""
|
|
1155
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
1156
|
+
f"v1/tools/name/{jsonable_encoder(tool_name)}",
|
|
1157
|
+
method="GET",
|
|
1158
|
+
request_options=request_options,
|
|
1159
|
+
)
|
|
1160
|
+
try:
|
|
1161
|
+
if 200 <= _response.status_code < 300:
|
|
1162
|
+
return typing.cast(
|
|
1163
|
+
str,
|
|
1164
|
+
parse_obj_as(
|
|
1165
|
+
type_=str, # type: ignore
|
|
1166
|
+
object_=_response.json(),
|
|
1167
|
+
),
|
|
1168
|
+
)
|
|
1169
|
+
if _response.status_code == 422:
|
|
1170
|
+
raise UnprocessableEntityError(
|
|
1171
|
+
typing.cast(
|
|
1172
|
+
HttpValidationError,
|
|
1173
|
+
parse_obj_as(
|
|
1174
|
+
type_=HttpValidationError, # type: ignore
|
|
1175
|
+
object_=_response.json(),
|
|
1176
|
+
),
|
|
1177
|
+
)
|
|
1178
|
+
)
|
|
1179
|
+
_response_json = _response.json()
|
|
1180
|
+
except JSONDecodeError:
|
|
1181
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
1182
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
1183
|
+
|
|
1184
|
+
async def list(
|
|
1185
|
+
self,
|
|
1186
|
+
*,
|
|
1187
|
+
cursor: typing.Optional[str] = None,
|
|
1188
|
+
limit: typing.Optional[int] = None,
|
|
1189
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
1190
|
+
) -> typing.List[LettaSchemasToolTool]:
|
|
1191
|
+
"""
|
|
1192
|
+
Get a list of all tools available to agents belonging to the org of the user
|
|
1193
|
+
|
|
1194
|
+
Parameters
|
|
1195
|
+
----------
|
|
1196
|
+
cursor : typing.Optional[str]
|
|
1197
|
+
|
|
1198
|
+
limit : typing.Optional[int]
|
|
1199
|
+
|
|
1200
|
+
request_options : typing.Optional[RequestOptions]
|
|
1201
|
+
Request-specific configuration.
|
|
1202
|
+
|
|
1203
|
+
Returns
|
|
1204
|
+
-------
|
|
1205
|
+
typing.List[LettaSchemasToolTool]
|
|
1206
|
+
Successful Response
|
|
1207
|
+
|
|
1208
|
+
Examples
|
|
1209
|
+
--------
|
|
1210
|
+
import asyncio
|
|
1211
|
+
|
|
1212
|
+
from letta import AsyncLetta
|
|
1213
|
+
|
|
1214
|
+
client = AsyncLetta(
|
|
1215
|
+
token="YOUR_TOKEN",
|
|
1216
|
+
)
|
|
1217
|
+
|
|
1218
|
+
|
|
1219
|
+
async def main() -> None:
|
|
1220
|
+
await client.tools.list()
|
|
1221
|
+
|
|
1222
|
+
|
|
1223
|
+
asyncio.run(main())
|
|
1224
|
+
"""
|
|
1225
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
1226
|
+
"v1/tools/",
|
|
1227
|
+
method="GET",
|
|
1228
|
+
params={
|
|
1229
|
+
"cursor": cursor,
|
|
1230
|
+
"limit": limit,
|
|
1231
|
+
},
|
|
1232
|
+
request_options=request_options,
|
|
1233
|
+
)
|
|
1234
|
+
try:
|
|
1235
|
+
if 200 <= _response.status_code < 300:
|
|
1236
|
+
return typing.cast(
|
|
1237
|
+
typing.List[LettaSchemasToolTool],
|
|
1238
|
+
parse_obj_as(
|
|
1239
|
+
type_=typing.List[LettaSchemasToolTool], # type: ignore
|
|
1240
|
+
object_=_response.json(),
|
|
1241
|
+
),
|
|
1242
|
+
)
|
|
1243
|
+
if _response.status_code == 422:
|
|
1244
|
+
raise UnprocessableEntityError(
|
|
1245
|
+
typing.cast(
|
|
1246
|
+
HttpValidationError,
|
|
1247
|
+
parse_obj_as(
|
|
1248
|
+
type_=HttpValidationError, # type: ignore
|
|
1249
|
+
object_=_response.json(),
|
|
1250
|
+
),
|
|
1251
|
+
)
|
|
1252
|
+
)
|
|
1253
|
+
_response_json = _response.json()
|
|
1254
|
+
except JSONDecodeError:
|
|
1255
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
1256
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
1257
|
+
|
|
1258
|
+
async def create(
|
|
1259
|
+
self,
|
|
1260
|
+
*,
|
|
1261
|
+
source_code: str,
|
|
1262
|
+
name: typing.Optional[str] = OMIT,
|
|
1263
|
+
description: typing.Optional[str] = OMIT,
|
|
1264
|
+
tags: typing.Optional[typing.Sequence[str]] = OMIT,
|
|
1265
|
+
module: typing.Optional[str] = OMIT,
|
|
1266
|
+
source_type: typing.Optional[str] = OMIT,
|
|
1267
|
+
json_schema: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
|
|
1268
|
+
return_char_limit: typing.Optional[int] = OMIT,
|
|
1269
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
1270
|
+
) -> LettaSchemasToolTool:
|
|
1271
|
+
"""
|
|
1272
|
+
Create a new tool
|
|
1273
|
+
|
|
1274
|
+
Parameters
|
|
1275
|
+
----------
|
|
1276
|
+
source_code : str
|
|
1277
|
+
The source code of the function.
|
|
1278
|
+
|
|
1279
|
+
name : typing.Optional[str]
|
|
1280
|
+
The name of the function (auto-generated from source_code if not provided).
|
|
1281
|
+
|
|
1282
|
+
description : typing.Optional[str]
|
|
1283
|
+
The description of the tool.
|
|
1284
|
+
|
|
1285
|
+
tags : typing.Optional[typing.Sequence[str]]
|
|
1286
|
+
Metadata tags.
|
|
1287
|
+
|
|
1288
|
+
module : typing.Optional[str]
|
|
1289
|
+
The source code of the function.
|
|
1290
|
+
|
|
1291
|
+
source_type : typing.Optional[str]
|
|
1292
|
+
The source type of the function.
|
|
1293
|
+
|
|
1294
|
+
json_schema : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
|
|
1295
|
+
The JSON schema of the function (auto-generated from source_code if not provided)
|
|
1296
|
+
|
|
1297
|
+
return_char_limit : typing.Optional[int]
|
|
1298
|
+
The maximum number of characters in the response.
|
|
1299
|
+
|
|
1300
|
+
request_options : typing.Optional[RequestOptions]
|
|
1301
|
+
Request-specific configuration.
|
|
1302
|
+
|
|
1303
|
+
Returns
|
|
1304
|
+
-------
|
|
1305
|
+
LettaSchemasToolTool
|
|
1306
|
+
Successful Response
|
|
1307
|
+
|
|
1308
|
+
Examples
|
|
1309
|
+
--------
|
|
1310
|
+
import asyncio
|
|
1311
|
+
|
|
1312
|
+
from letta import AsyncLetta
|
|
1313
|
+
|
|
1314
|
+
client = AsyncLetta(
|
|
1315
|
+
token="YOUR_TOKEN",
|
|
1316
|
+
)
|
|
1317
|
+
|
|
1318
|
+
|
|
1319
|
+
async def main() -> None:
|
|
1320
|
+
await client.tools.create(
|
|
1321
|
+
source_code="source_code",
|
|
1322
|
+
)
|
|
1323
|
+
|
|
1324
|
+
|
|
1325
|
+
asyncio.run(main())
|
|
1326
|
+
"""
|
|
1327
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
1328
|
+
"v1/tools/",
|
|
1329
|
+
method="POST",
|
|
1330
|
+
json={
|
|
1331
|
+
"name": name,
|
|
1332
|
+
"description": description,
|
|
1333
|
+
"tags": tags,
|
|
1334
|
+
"module": module,
|
|
1335
|
+
"source_code": source_code,
|
|
1336
|
+
"source_type": source_type,
|
|
1337
|
+
"json_schema": json_schema,
|
|
1338
|
+
"return_char_limit": return_char_limit,
|
|
1339
|
+
},
|
|
1340
|
+
request_options=request_options,
|
|
1341
|
+
omit=OMIT,
|
|
1342
|
+
)
|
|
1343
|
+
try:
|
|
1344
|
+
if 200 <= _response.status_code < 300:
|
|
1345
|
+
return typing.cast(
|
|
1346
|
+
LettaSchemasToolTool,
|
|
1347
|
+
parse_obj_as(
|
|
1348
|
+
type_=LettaSchemasToolTool, # type: ignore
|
|
1349
|
+
object_=_response.json(),
|
|
1350
|
+
),
|
|
1351
|
+
)
|
|
1352
|
+
if _response.status_code == 422:
|
|
1353
|
+
raise UnprocessableEntityError(
|
|
1354
|
+
typing.cast(
|
|
1355
|
+
HttpValidationError,
|
|
1356
|
+
parse_obj_as(
|
|
1357
|
+
type_=HttpValidationError, # type: ignore
|
|
1358
|
+
object_=_response.json(),
|
|
1359
|
+
),
|
|
1360
|
+
)
|
|
1361
|
+
)
|
|
1362
|
+
_response_json = _response.json()
|
|
1363
|
+
except JSONDecodeError:
|
|
1364
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
1365
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
1366
|
+
|
|
1367
|
+
async def upsert(
|
|
1368
|
+
self,
|
|
1369
|
+
*,
|
|
1370
|
+
source_code: str,
|
|
1371
|
+
name: typing.Optional[str] = OMIT,
|
|
1372
|
+
description: typing.Optional[str] = OMIT,
|
|
1373
|
+
tags: typing.Optional[typing.Sequence[str]] = OMIT,
|
|
1374
|
+
module: typing.Optional[str] = OMIT,
|
|
1375
|
+
source_type: typing.Optional[str] = OMIT,
|
|
1376
|
+
json_schema: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
|
|
1377
|
+
return_char_limit: typing.Optional[int] = OMIT,
|
|
1378
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
1379
|
+
) -> LettaSchemasToolTool:
|
|
1380
|
+
"""
|
|
1381
|
+
Create or update a tool
|
|
1382
|
+
|
|
1383
|
+
Parameters
|
|
1384
|
+
----------
|
|
1385
|
+
source_code : str
|
|
1386
|
+
The source code of the function.
|
|
1387
|
+
|
|
1388
|
+
name : typing.Optional[str]
|
|
1389
|
+
The name of the function (auto-generated from source_code if not provided).
|
|
1390
|
+
|
|
1391
|
+
description : typing.Optional[str]
|
|
1392
|
+
The description of the tool.
|
|
1393
|
+
|
|
1394
|
+
tags : typing.Optional[typing.Sequence[str]]
|
|
1395
|
+
Metadata tags.
|
|
1396
|
+
|
|
1397
|
+
module : typing.Optional[str]
|
|
1398
|
+
The source code of the function.
|
|
1399
|
+
|
|
1400
|
+
source_type : typing.Optional[str]
|
|
1401
|
+
The source type of the function.
|
|
1402
|
+
|
|
1403
|
+
json_schema : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
|
|
1404
|
+
The JSON schema of the function (auto-generated from source_code if not provided)
|
|
1405
|
+
|
|
1406
|
+
return_char_limit : typing.Optional[int]
|
|
1407
|
+
The maximum number of characters in the response.
|
|
1408
|
+
|
|
1409
|
+
request_options : typing.Optional[RequestOptions]
|
|
1410
|
+
Request-specific configuration.
|
|
1411
|
+
|
|
1412
|
+
Returns
|
|
1413
|
+
-------
|
|
1414
|
+
LettaSchemasToolTool
|
|
1415
|
+
Successful Response
|
|
1416
|
+
|
|
1417
|
+
Examples
|
|
1418
|
+
--------
|
|
1419
|
+
import asyncio
|
|
1420
|
+
|
|
1421
|
+
from letta import AsyncLetta
|
|
1422
|
+
|
|
1423
|
+
client = AsyncLetta(
|
|
1424
|
+
token="YOUR_TOKEN",
|
|
1425
|
+
)
|
|
1426
|
+
|
|
1427
|
+
|
|
1428
|
+
async def main() -> None:
|
|
1429
|
+
await client.tools.upsert(
|
|
1430
|
+
source_code="source_code",
|
|
1431
|
+
)
|
|
1432
|
+
|
|
1433
|
+
|
|
1434
|
+
asyncio.run(main())
|
|
1435
|
+
"""
|
|
1436
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
1437
|
+
"v1/tools/",
|
|
1438
|
+
method="PUT",
|
|
1439
|
+
json={
|
|
1440
|
+
"name": name,
|
|
1441
|
+
"description": description,
|
|
1442
|
+
"tags": tags,
|
|
1443
|
+
"module": module,
|
|
1444
|
+
"source_code": source_code,
|
|
1445
|
+
"source_type": source_type,
|
|
1446
|
+
"json_schema": json_schema,
|
|
1447
|
+
"return_char_limit": return_char_limit,
|
|
1448
|
+
},
|
|
1449
|
+
request_options=request_options,
|
|
1450
|
+
omit=OMIT,
|
|
1451
|
+
)
|
|
1452
|
+
try:
|
|
1453
|
+
if 200 <= _response.status_code < 300:
|
|
1454
|
+
return typing.cast(
|
|
1455
|
+
LettaSchemasToolTool,
|
|
1456
|
+
parse_obj_as(
|
|
1457
|
+
type_=LettaSchemasToolTool, # type: ignore
|
|
1458
|
+
object_=_response.json(),
|
|
1459
|
+
),
|
|
1460
|
+
)
|
|
1461
|
+
if _response.status_code == 422:
|
|
1462
|
+
raise UnprocessableEntityError(
|
|
1463
|
+
typing.cast(
|
|
1464
|
+
HttpValidationError,
|
|
1465
|
+
parse_obj_as(
|
|
1466
|
+
type_=HttpValidationError, # type: ignore
|
|
1467
|
+
object_=_response.json(),
|
|
1468
|
+
),
|
|
1469
|
+
)
|
|
1470
|
+
)
|
|
1471
|
+
_response_json = _response.json()
|
|
1472
|
+
except JSONDecodeError:
|
|
1473
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
1474
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
1475
|
+
|
|
1476
|
+
async def add_base_tool(
|
|
1477
|
+
self, *, request_options: typing.Optional[RequestOptions] = None
|
|
1478
|
+
) -> typing.List[LettaSchemasToolTool]:
|
|
1479
|
+
"""
|
|
1480
|
+
Upsert base tools
|
|
1481
|
+
|
|
1482
|
+
Parameters
|
|
1483
|
+
----------
|
|
1484
|
+
request_options : typing.Optional[RequestOptions]
|
|
1485
|
+
Request-specific configuration.
|
|
1486
|
+
|
|
1487
|
+
Returns
|
|
1488
|
+
-------
|
|
1489
|
+
typing.List[LettaSchemasToolTool]
|
|
1490
|
+
Successful Response
|
|
1491
|
+
|
|
1492
|
+
Examples
|
|
1493
|
+
--------
|
|
1494
|
+
import asyncio
|
|
1495
|
+
|
|
1496
|
+
from letta import AsyncLetta
|
|
1497
|
+
|
|
1498
|
+
client = AsyncLetta(
|
|
1499
|
+
token="YOUR_TOKEN",
|
|
1500
|
+
)
|
|
1501
|
+
|
|
1502
|
+
|
|
1503
|
+
async def main() -> None:
|
|
1504
|
+
await client.tools.add_base_tool()
|
|
1505
|
+
|
|
1506
|
+
|
|
1507
|
+
asyncio.run(main())
|
|
1508
|
+
"""
|
|
1509
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
1510
|
+
"v1/tools/add-base-tools",
|
|
1511
|
+
method="POST",
|
|
1512
|
+
request_options=request_options,
|
|
1513
|
+
)
|
|
1514
|
+
try:
|
|
1515
|
+
if 200 <= _response.status_code < 300:
|
|
1516
|
+
return typing.cast(
|
|
1517
|
+
typing.List[LettaSchemasToolTool],
|
|
1518
|
+
parse_obj_as(
|
|
1519
|
+
type_=typing.List[LettaSchemasToolTool], # type: ignore
|
|
1520
|
+
object_=_response.json(),
|
|
1521
|
+
),
|
|
1522
|
+
)
|
|
1523
|
+
if _response.status_code == 422:
|
|
1524
|
+
raise UnprocessableEntityError(
|
|
1525
|
+
typing.cast(
|
|
1526
|
+
HttpValidationError,
|
|
1527
|
+
parse_obj_as(
|
|
1528
|
+
type_=HttpValidationError, # type: ignore
|
|
1529
|
+
object_=_response.json(),
|
|
1530
|
+
),
|
|
1531
|
+
)
|
|
1532
|
+
)
|
|
1533
|
+
_response_json = _response.json()
|
|
1534
|
+
except JSONDecodeError:
|
|
1535
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
1536
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
1537
|
+
|
|
1538
|
+
async def run_tool_from_source(
|
|
1539
|
+
self,
|
|
1540
|
+
*,
|
|
1541
|
+
source_code: str,
|
|
1542
|
+
args: str,
|
|
1543
|
+
name: typing.Optional[str] = OMIT,
|
|
1544
|
+
source_type: typing.Optional[str] = OMIT,
|
|
1545
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
1546
|
+
) -> ToolReturnMessage:
|
|
1547
|
+
"""
|
|
1548
|
+
Attempt to build a tool from source, then run it on the provided arguments
|
|
1549
|
+
|
|
1550
|
+
Parameters
|
|
1551
|
+
----------
|
|
1552
|
+
source_code : str
|
|
1553
|
+
The source code of the function.
|
|
1554
|
+
|
|
1555
|
+
args : str
|
|
1556
|
+
The arguments to pass to the tool (as stringified JSON).
|
|
1557
|
+
|
|
1558
|
+
name : typing.Optional[str]
|
|
1559
|
+
The name of the tool to run.
|
|
1560
|
+
|
|
1561
|
+
source_type : typing.Optional[str]
|
|
1562
|
+
The type of the source code.
|
|
1563
|
+
|
|
1564
|
+
request_options : typing.Optional[RequestOptions]
|
|
1565
|
+
Request-specific configuration.
|
|
1566
|
+
|
|
1567
|
+
Returns
|
|
1568
|
+
-------
|
|
1569
|
+
ToolReturnMessage
|
|
1570
|
+
Successful Response
|
|
1571
|
+
|
|
1572
|
+
Examples
|
|
1573
|
+
--------
|
|
1574
|
+
import asyncio
|
|
1575
|
+
|
|
1576
|
+
from letta import AsyncLetta
|
|
1577
|
+
|
|
1578
|
+
client = AsyncLetta(
|
|
1579
|
+
token="YOUR_TOKEN",
|
|
1580
|
+
)
|
|
1581
|
+
|
|
1582
|
+
|
|
1583
|
+
async def main() -> None:
|
|
1584
|
+
await client.tools.run_tool_from_source(
|
|
1585
|
+
source_code="source_code",
|
|
1586
|
+
args="args",
|
|
1587
|
+
)
|
|
1588
|
+
|
|
1589
|
+
|
|
1590
|
+
asyncio.run(main())
|
|
1591
|
+
"""
|
|
1592
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
1593
|
+
"v1/tools/run",
|
|
1594
|
+
method="POST",
|
|
1595
|
+
json={
|
|
1596
|
+
"source_code": source_code,
|
|
1597
|
+
"args": args,
|
|
1598
|
+
"name": name,
|
|
1599
|
+
"source_type": source_type,
|
|
1600
|
+
},
|
|
1601
|
+
headers={
|
|
1602
|
+
"content-type": "application/json",
|
|
1603
|
+
},
|
|
1604
|
+
request_options=request_options,
|
|
1605
|
+
omit=OMIT,
|
|
1606
|
+
)
|
|
1607
|
+
try:
|
|
1608
|
+
if 200 <= _response.status_code < 300:
|
|
1609
|
+
return typing.cast(
|
|
1610
|
+
ToolReturnMessage,
|
|
1611
|
+
parse_obj_as(
|
|
1612
|
+
type_=ToolReturnMessage, # type: ignore
|
|
1613
|
+
object_=_response.json(),
|
|
1614
|
+
),
|
|
1615
|
+
)
|
|
1616
|
+
if _response.status_code == 422:
|
|
1617
|
+
raise UnprocessableEntityError(
|
|
1618
|
+
typing.cast(
|
|
1619
|
+
HttpValidationError,
|
|
1620
|
+
parse_obj_as(
|
|
1621
|
+
type_=HttpValidationError, # type: ignore
|
|
1622
|
+
object_=_response.json(),
|
|
1623
|
+
),
|
|
1624
|
+
)
|
|
1625
|
+
)
|
|
1626
|
+
_response_json = _response.json()
|
|
1627
|
+
except JSONDecodeError:
|
|
1628
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
1629
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
1630
|
+
|
|
1631
|
+
async def list_composio_apps(
|
|
1632
|
+
self, *, request_options: typing.Optional[RequestOptions] = None
|
|
1633
|
+
) -> typing.List[AppModel]:
|
|
1634
|
+
"""
|
|
1635
|
+
Get a list of all Composio apps
|
|
1636
|
+
|
|
1637
|
+
Parameters
|
|
1638
|
+
----------
|
|
1639
|
+
request_options : typing.Optional[RequestOptions]
|
|
1640
|
+
Request-specific configuration.
|
|
1641
|
+
|
|
1642
|
+
Returns
|
|
1643
|
+
-------
|
|
1644
|
+
typing.List[AppModel]
|
|
1645
|
+
Successful Response
|
|
1646
|
+
|
|
1647
|
+
Examples
|
|
1648
|
+
--------
|
|
1649
|
+
import asyncio
|
|
1650
|
+
|
|
1651
|
+
from letta import AsyncLetta
|
|
1652
|
+
|
|
1653
|
+
client = AsyncLetta(
|
|
1654
|
+
token="YOUR_TOKEN",
|
|
1655
|
+
)
|
|
1656
|
+
|
|
1657
|
+
|
|
1658
|
+
async def main() -> None:
|
|
1659
|
+
await client.tools.list_composio_apps()
|
|
1660
|
+
|
|
1661
|
+
|
|
1662
|
+
asyncio.run(main())
|
|
1663
|
+
"""
|
|
1664
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
1665
|
+
"v1/tools/composio/apps",
|
|
1666
|
+
method="GET",
|
|
1667
|
+
request_options=request_options,
|
|
1668
|
+
)
|
|
1669
|
+
try:
|
|
1670
|
+
if 200 <= _response.status_code < 300:
|
|
1671
|
+
return typing.cast(
|
|
1672
|
+
typing.List[AppModel],
|
|
1673
|
+
parse_obj_as(
|
|
1674
|
+
type_=typing.List[AppModel], # type: ignore
|
|
1675
|
+
object_=_response.json(),
|
|
1676
|
+
),
|
|
1677
|
+
)
|
|
1678
|
+
if _response.status_code == 422:
|
|
1679
|
+
raise UnprocessableEntityError(
|
|
1680
|
+
typing.cast(
|
|
1681
|
+
HttpValidationError,
|
|
1682
|
+
parse_obj_as(
|
|
1683
|
+
type_=HttpValidationError, # type: ignore
|
|
1684
|
+
object_=_response.json(),
|
|
1685
|
+
),
|
|
1686
|
+
)
|
|
1687
|
+
)
|
|
1688
|
+
_response_json = _response.json()
|
|
1689
|
+
except JSONDecodeError:
|
|
1690
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
1691
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
1692
|
+
|
|
1693
|
+
async def list_composio_actions_by_app(
|
|
1694
|
+
self, composio_app_name: str, *, request_options: typing.Optional[RequestOptions] = None
|
|
1695
|
+
) -> typing.List[ActionModel]:
|
|
1696
|
+
"""
|
|
1697
|
+
Get a list of all Composio actions for a specific app
|
|
1698
|
+
|
|
1699
|
+
Parameters
|
|
1700
|
+
----------
|
|
1701
|
+
composio_app_name : str
|
|
1702
|
+
|
|
1703
|
+
request_options : typing.Optional[RequestOptions]
|
|
1704
|
+
Request-specific configuration.
|
|
1705
|
+
|
|
1706
|
+
Returns
|
|
1707
|
+
-------
|
|
1708
|
+
typing.List[ActionModel]
|
|
1709
|
+
Successful Response
|
|
1710
|
+
|
|
1711
|
+
Examples
|
|
1712
|
+
--------
|
|
1713
|
+
import asyncio
|
|
1714
|
+
|
|
1715
|
+
from letta import AsyncLetta
|
|
1716
|
+
|
|
1717
|
+
client = AsyncLetta(
|
|
1718
|
+
token="YOUR_TOKEN",
|
|
1719
|
+
)
|
|
1720
|
+
|
|
1721
|
+
|
|
1722
|
+
async def main() -> None:
|
|
1723
|
+
await client.tools.list_composio_actions_by_app(
|
|
1724
|
+
composio_app_name="composio_app_name",
|
|
1725
|
+
)
|
|
1726
|
+
|
|
1727
|
+
|
|
1728
|
+
asyncio.run(main())
|
|
1729
|
+
"""
|
|
1730
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
1731
|
+
f"v1/tools/composio/apps/{jsonable_encoder(composio_app_name)}/actions",
|
|
1732
|
+
method="GET",
|
|
1733
|
+
request_options=request_options,
|
|
1734
|
+
)
|
|
1735
|
+
try:
|
|
1736
|
+
if 200 <= _response.status_code < 300:
|
|
1737
|
+
return typing.cast(
|
|
1738
|
+
typing.List[ActionModel],
|
|
1739
|
+
parse_obj_as(
|
|
1740
|
+
type_=typing.List[ActionModel], # type: ignore
|
|
1741
|
+
object_=_response.json(),
|
|
1742
|
+
),
|
|
1743
|
+
)
|
|
1744
|
+
if _response.status_code == 422:
|
|
1745
|
+
raise UnprocessableEntityError(
|
|
1746
|
+
typing.cast(
|
|
1747
|
+
HttpValidationError,
|
|
1748
|
+
parse_obj_as(
|
|
1749
|
+
type_=HttpValidationError, # type: ignore
|
|
1750
|
+
object_=_response.json(),
|
|
1751
|
+
),
|
|
1752
|
+
)
|
|
1753
|
+
)
|
|
1754
|
+
_response_json = _response.json()
|
|
1755
|
+
except JSONDecodeError:
|
|
1756
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
1757
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
1758
|
+
|
|
1759
|
+
async def add_composio_tool(
|
|
1760
|
+
self, composio_action_name: str, *, request_options: typing.Optional[RequestOptions] = None
|
|
1761
|
+
) -> LettaSchemasToolTool:
|
|
1762
|
+
"""
|
|
1763
|
+
Add a new Composio tool by action name (Composio refers to each tool as an `Action`)
|
|
1764
|
+
|
|
1765
|
+
Parameters
|
|
1766
|
+
----------
|
|
1767
|
+
composio_action_name : str
|
|
1768
|
+
|
|
1769
|
+
request_options : typing.Optional[RequestOptions]
|
|
1770
|
+
Request-specific configuration.
|
|
1771
|
+
|
|
1772
|
+
Returns
|
|
1773
|
+
-------
|
|
1774
|
+
LettaSchemasToolTool
|
|
1775
|
+
Successful Response
|
|
1776
|
+
|
|
1777
|
+
Examples
|
|
1778
|
+
--------
|
|
1779
|
+
import asyncio
|
|
1780
|
+
|
|
1781
|
+
from letta import AsyncLetta
|
|
1782
|
+
|
|
1783
|
+
client = AsyncLetta(
|
|
1784
|
+
token="YOUR_TOKEN",
|
|
1785
|
+
)
|
|
1786
|
+
|
|
1787
|
+
|
|
1788
|
+
async def main() -> None:
|
|
1789
|
+
await client.tools.add_composio_tool(
|
|
1790
|
+
composio_action_name="composio_action_name",
|
|
1791
|
+
)
|
|
1792
|
+
|
|
1793
|
+
|
|
1794
|
+
asyncio.run(main())
|
|
1795
|
+
"""
|
|
1796
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
1797
|
+
f"v1/tools/composio/{jsonable_encoder(composio_action_name)}",
|
|
1798
|
+
method="POST",
|
|
1799
|
+
request_options=request_options,
|
|
1800
|
+
)
|
|
1801
|
+
try:
|
|
1802
|
+
if 200 <= _response.status_code < 300:
|
|
1803
|
+
return typing.cast(
|
|
1804
|
+
LettaSchemasToolTool,
|
|
1805
|
+
parse_obj_as(
|
|
1806
|
+
type_=LettaSchemasToolTool, # type: ignore
|
|
1807
|
+
object_=_response.json(),
|
|
1808
|
+
),
|
|
1809
|
+
)
|
|
1810
|
+
if _response.status_code == 422:
|
|
1811
|
+
raise UnprocessableEntityError(
|
|
1812
|
+
typing.cast(
|
|
1813
|
+
HttpValidationError,
|
|
1814
|
+
parse_obj_as(
|
|
1815
|
+
type_=HttpValidationError, # type: ignore
|
|
1816
|
+
object_=_response.json(),
|
|
1817
|
+
),
|
|
1818
|
+
)
|
|
1819
|
+
)
|
|
1820
|
+
_response_json = _response.json()
|
|
1821
|
+
except JSONDecodeError:
|
|
1822
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
1823
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|