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