letta-nightly 0.13.0.dev20251031104146__py3-none-any.whl → 0.13.1.dev20251101010313__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-nightly might be problematic. Click here for more details.
- letta/__init__.py +1 -1
- letta/adapters/simple_llm_stream_adapter.py +1 -0
- letta/agents/letta_agent_v2.py +8 -0
- letta/agents/letta_agent_v3.py +127 -27
- letta/agents/temporal/activities/__init__.py +25 -0
- letta/agents/temporal/activities/create_messages.py +26 -0
- letta/agents/temporal/activities/create_step.py +57 -0
- letta/agents/temporal/activities/example_activity.py +9 -0
- letta/agents/temporal/activities/execute_tool.py +130 -0
- letta/agents/temporal/activities/llm_request.py +114 -0
- letta/agents/temporal/activities/prepare_messages.py +27 -0
- letta/agents/temporal/activities/refresh_context.py +160 -0
- letta/agents/temporal/activities/summarize_conversation_history.py +77 -0
- letta/agents/temporal/activities/update_message_ids.py +25 -0
- letta/agents/temporal/activities/update_run.py +43 -0
- letta/agents/temporal/constants.py +59 -0
- letta/agents/temporal/temporal_agent_workflow.py +704 -0
- letta/agents/temporal/types.py +275 -0
- letta/constants.py +11 -0
- letta/errors.py +4 -0
- letta/functions/function_sets/base.py +0 -11
- letta/groups/helpers.py +7 -1
- letta/groups/sleeptime_multi_agent_v4.py +4 -3
- letta/interfaces/anthropic_streaming_interface.py +0 -1
- letta/interfaces/openai_streaming_interface.py +103 -100
- letta/llm_api/anthropic_client.py +57 -12
- letta/llm_api/bedrock_client.py +1 -0
- letta/llm_api/deepseek_client.py +3 -2
- letta/llm_api/google_vertex_client.py +5 -4
- letta/llm_api/groq_client.py +1 -0
- letta/llm_api/llm_client_base.py +15 -1
- letta/llm_api/openai.py +2 -2
- letta/llm_api/openai_client.py +17 -3
- letta/llm_api/xai_client.py +1 -0
- letta/orm/agent.py +3 -0
- letta/orm/organization.py +4 -0
- letta/orm/sqlalchemy_base.py +7 -0
- letta/otel/tracing.py +131 -4
- letta/schemas/agent.py +108 -40
- letta/schemas/agent_file.py +10 -10
- letta/schemas/block.py +22 -3
- letta/schemas/enums.py +21 -0
- letta/schemas/environment_variables.py +3 -2
- letta/schemas/group.py +3 -3
- letta/schemas/letta_response.py +36 -4
- letta/schemas/llm_batch_job.py +3 -3
- letta/schemas/llm_config.py +123 -4
- letta/schemas/mcp.py +3 -2
- letta/schemas/mcp_server.py +3 -2
- letta/schemas/message.py +167 -49
- letta/schemas/model.py +265 -0
- letta/schemas/organization.py +2 -1
- letta/schemas/passage.py +2 -1
- letta/schemas/provider_trace.py +2 -1
- letta/schemas/providers/openrouter.py +1 -2
- letta/schemas/run_metrics.py +2 -1
- letta/schemas/sandbox_config.py +3 -1
- letta/schemas/step_metrics.py +2 -1
- letta/schemas/tool_rule.py +2 -2
- letta/schemas/user.py +2 -1
- letta/server/rest_api/app.py +5 -1
- letta/server/rest_api/routers/v1/__init__.py +4 -0
- letta/server/rest_api/routers/v1/agents.py +71 -9
- letta/server/rest_api/routers/v1/blocks.py +7 -7
- letta/server/rest_api/routers/v1/groups.py +40 -0
- letta/server/rest_api/routers/v1/identities.py +2 -2
- letta/server/rest_api/routers/v1/internal_agents.py +31 -0
- letta/server/rest_api/routers/v1/internal_blocks.py +177 -0
- letta/server/rest_api/routers/v1/internal_runs.py +25 -1
- letta/server/rest_api/routers/v1/runs.py +2 -22
- letta/server/rest_api/routers/v1/tools.py +12 -1
- letta/server/server.py +20 -4
- letta/services/agent_manager.py +4 -4
- letta/services/archive_manager.py +16 -0
- letta/services/group_manager.py +44 -0
- letta/services/helpers/run_manager_helper.py +2 -2
- letta/services/lettuce/lettuce_client.py +148 -0
- letta/services/mcp/base_client.py +9 -3
- letta/services/run_manager.py +148 -37
- letta/services/source_manager.py +91 -3
- letta/services/step_manager.py +2 -3
- letta/services/streaming_service.py +52 -13
- letta/services/summarizer/summarizer.py +28 -2
- letta/services/tool_executor/builtin_tool_executor.py +1 -1
- letta/services/tool_executor/core_tool_executor.py +2 -117
- letta/services/tool_sandbox/e2b_sandbox.py +4 -1
- letta/services/tool_schema_generator.py +2 -2
- letta/validators.py +21 -0
- {letta_nightly-0.13.0.dev20251031104146.dist-info → letta_nightly-0.13.1.dev20251101010313.dist-info}/METADATA +1 -1
- {letta_nightly-0.13.0.dev20251031104146.dist-info → letta_nightly-0.13.1.dev20251101010313.dist-info}/RECORD +93 -87
- letta/agent.py +0 -1758
- letta/cli/cli_load.py +0 -16
- letta/client/__init__.py +0 -0
- letta/client/streaming.py +0 -95
- letta/client/utils.py +0 -78
- letta/functions/async_composio_toolset.py +0 -109
- letta/functions/composio_helpers.py +0 -96
- letta/helpers/composio_helpers.py +0 -38
- letta/orm/job_messages.py +0 -33
- letta/schemas/providers.py +0 -1617
- letta/server/rest_api/routers/openai/chat_completions/chat_completions.py +0 -132
- letta/services/tool_executor/composio_tool_executor.py +0 -57
- {letta_nightly-0.13.0.dev20251031104146.dist-info → letta_nightly-0.13.1.dev20251101010313.dist-info}/WHEEL +0 -0
- {letta_nightly-0.13.0.dev20251031104146.dist-info → letta_nightly-0.13.1.dev20251101010313.dist-info}/entry_points.txt +0 -0
- {letta_nightly-0.13.0.dev20251031104146.dist-info → letta_nightly-0.13.1.dev20251101010313.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import asyncio
|
|
2
|
-
from typing import TYPE_CHECKING, List, Optional, Union
|
|
3
|
-
|
|
4
|
-
from fastapi import APIRouter, Body, Depends, Header, HTTPException
|
|
5
|
-
from fastapi.responses import StreamingResponse
|
|
6
|
-
from openai.types.chat.completion_create_params import CompletionCreateParams
|
|
7
|
-
|
|
8
|
-
from letta.agent import Agent
|
|
9
|
-
from letta.constants import DEFAULT_MESSAGE_TOOL, DEFAULT_MESSAGE_TOOL_KWARG, LETTA_MODEL_ENDPOINT
|
|
10
|
-
from letta.log import get_logger
|
|
11
|
-
from letta.schemas.message import Message, MessageCreate
|
|
12
|
-
from letta.schemas.user import User
|
|
13
|
-
from letta.server.rest_api.chat_completions_interface import ChatCompletionsStreamingInterface
|
|
14
|
-
from letta.server.rest_api.dependencies import HeaderParams, get_headers, get_letta_server
|
|
15
|
-
|
|
16
|
-
# TODO this belongs in a controller!
|
|
17
|
-
from letta.server.rest_api.utils import get_user_message_from_chat_completions_request, sse_async_generator
|
|
18
|
-
from letta.utils import safe_create_task
|
|
19
|
-
|
|
20
|
-
if TYPE_CHECKING:
|
|
21
|
-
from letta.server.server import SyncServer
|
|
22
|
-
|
|
23
|
-
router = APIRouter(prefix="/v1", tags=["chat_completions"])
|
|
24
|
-
|
|
25
|
-
logger = get_logger(__name__)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
@router.post(
|
|
29
|
-
"/{agent_id}/chat/completions",
|
|
30
|
-
response_model=None,
|
|
31
|
-
operation_id="create_chat_completions",
|
|
32
|
-
responses={
|
|
33
|
-
200: {
|
|
34
|
-
"description": "Successful response",
|
|
35
|
-
"content": {"text/event-stream": {}},
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
)
|
|
39
|
-
async def create_chat_completions(
|
|
40
|
-
agent_id: str,
|
|
41
|
-
completion_request: CompletionCreateParams = Body(...),
|
|
42
|
-
server: "SyncServer" = Depends(get_letta_server),
|
|
43
|
-
headers: HeaderParams = Depends(get_headers),
|
|
44
|
-
):
|
|
45
|
-
# Validate and process fields
|
|
46
|
-
if not completion_request["stream"]:
|
|
47
|
-
raise HTTPException(status_code=400, detail="Must be streaming request: `stream` was set to `False` in the request.")
|
|
48
|
-
|
|
49
|
-
actor = server.user_manager.get_user_or_default(user_id=headers.actor_id)
|
|
50
|
-
|
|
51
|
-
letta_agent = server.load_agent(agent_id=agent_id, actor=actor)
|
|
52
|
-
llm_config = letta_agent.agent_state.llm_config
|
|
53
|
-
if llm_config.model_endpoint_type != "openai" or llm_config.model_endpoint == LETTA_MODEL_ENDPOINT:
|
|
54
|
-
error_msg = f"You can only use models with type 'openai' for chat completions. This agent {agent_id} has llm_config: \n{llm_config.model_dump_json(indent=4)}"
|
|
55
|
-
logger.error(error_msg)
|
|
56
|
-
raise HTTPException(status_code=400, detail=error_msg)
|
|
57
|
-
|
|
58
|
-
model = completion_request.get("model")
|
|
59
|
-
if model != llm_config.model:
|
|
60
|
-
warning_msg = f"The requested model {model} is different from the model specified in this agent's ({agent_id}) llm_config: \n{llm_config.model_dump_json(indent=4)}"
|
|
61
|
-
logger.warning(f"Defaulting to {llm_config.model}...")
|
|
62
|
-
logger.warning(warning_msg)
|
|
63
|
-
|
|
64
|
-
return await send_message_to_agent_chat_completions(
|
|
65
|
-
server=server,
|
|
66
|
-
letta_agent=letta_agent,
|
|
67
|
-
actor=actor,
|
|
68
|
-
messages=get_user_message_from_chat_completions_request(completion_request),
|
|
69
|
-
)
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
async def send_message_to_agent_chat_completions(
|
|
73
|
-
server: "SyncServer",
|
|
74
|
-
letta_agent: Agent,
|
|
75
|
-
actor: User,
|
|
76
|
-
messages: Union[List[Message], List[MessageCreate]],
|
|
77
|
-
assistant_message_tool_name: str = DEFAULT_MESSAGE_TOOL,
|
|
78
|
-
assistant_message_tool_kwarg: str = DEFAULT_MESSAGE_TOOL_KWARG,
|
|
79
|
-
) -> StreamingResponse:
|
|
80
|
-
"""Split off into a separate function so that it can be imported in the /chat/completion proxy."""
|
|
81
|
-
# For streaming response
|
|
82
|
-
try:
|
|
83
|
-
# TODO: cleanup this logic
|
|
84
|
-
llm_config = letta_agent.agent_state.llm_config
|
|
85
|
-
|
|
86
|
-
# Create a new interface per request
|
|
87
|
-
letta_agent.interface = ChatCompletionsStreamingInterface()
|
|
88
|
-
streaming_interface = letta_agent.interface
|
|
89
|
-
if not isinstance(streaming_interface, ChatCompletionsStreamingInterface):
|
|
90
|
-
raise ValueError(f"Agent has wrong type of interface: {type(streaming_interface)}")
|
|
91
|
-
|
|
92
|
-
# Allow AssistantMessage is desired by client
|
|
93
|
-
streaming_interface.assistant_message_tool_name = assistant_message_tool_name
|
|
94
|
-
streaming_interface.assistant_message_tool_kwarg = assistant_message_tool_kwarg
|
|
95
|
-
|
|
96
|
-
# Related to JSON buffer reader
|
|
97
|
-
streaming_interface.inner_thoughts_in_kwargs = (
|
|
98
|
-
llm_config.put_inner_thoughts_in_kwargs if llm_config.put_inner_thoughts_in_kwargs is not None else False
|
|
99
|
-
)
|
|
100
|
-
|
|
101
|
-
# Offload the synchronous message_func to a separate thread
|
|
102
|
-
streaming_interface.stream_start()
|
|
103
|
-
safe_create_task(
|
|
104
|
-
asyncio.to_thread(
|
|
105
|
-
server.send_messages,
|
|
106
|
-
actor=actor,
|
|
107
|
-
agent_id=letta_agent.agent_state.id,
|
|
108
|
-
input_messages=messages,
|
|
109
|
-
interface=streaming_interface,
|
|
110
|
-
put_inner_thoughts_first=False,
|
|
111
|
-
),
|
|
112
|
-
label="openai_send_messages",
|
|
113
|
-
)
|
|
114
|
-
|
|
115
|
-
# return a stream
|
|
116
|
-
return StreamingResponse(
|
|
117
|
-
sse_async_generator(
|
|
118
|
-
streaming_interface.get_generator(),
|
|
119
|
-
usage_task=None,
|
|
120
|
-
finish_message=True,
|
|
121
|
-
),
|
|
122
|
-
media_type="text/event-stream",
|
|
123
|
-
)
|
|
124
|
-
|
|
125
|
-
except HTTPException:
|
|
126
|
-
raise
|
|
127
|
-
except Exception as e:
|
|
128
|
-
print(e)
|
|
129
|
-
import traceback
|
|
130
|
-
|
|
131
|
-
traceback.print_exc()
|
|
132
|
-
raise HTTPException(status_code=500, detail=f"{e}")
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
from typing import Any, Dict, Optional
|
|
2
|
-
|
|
3
|
-
from letta.constants import COMPOSIO_ENTITY_ENV_VAR_KEY
|
|
4
|
-
from letta.functions.composio_helpers import execute_composio_action_async, generate_composio_action_from_func_name
|
|
5
|
-
from letta.helpers.composio_helpers import get_composio_api_key_async
|
|
6
|
-
from letta.otel.tracing import trace_method
|
|
7
|
-
from letta.schemas.agent import AgentState
|
|
8
|
-
from letta.schemas.sandbox_config import SandboxConfig
|
|
9
|
-
from letta.schemas.tool import Tool
|
|
10
|
-
from letta.schemas.tool_execution_result import ToolExecutionResult
|
|
11
|
-
from letta.schemas.user import User
|
|
12
|
-
from letta.services.tool_executor.tool_executor_base import ToolExecutor
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class ExternalComposioToolExecutor(ToolExecutor):
|
|
16
|
-
"""Executor for external Composio tools."""
|
|
17
|
-
|
|
18
|
-
@trace_method
|
|
19
|
-
async def execute(
|
|
20
|
-
self,
|
|
21
|
-
function_name: str,
|
|
22
|
-
function_args: dict,
|
|
23
|
-
tool: Tool,
|
|
24
|
-
actor: User,
|
|
25
|
-
agent_state: Optional[AgentState] = None,
|
|
26
|
-
sandbox_config: Optional[SandboxConfig] = None,
|
|
27
|
-
sandbox_env_vars: Optional[Dict[str, Any]] = None,
|
|
28
|
-
) -> ToolExecutionResult:
|
|
29
|
-
if agent_state is None:
|
|
30
|
-
return ToolExecutionResult(
|
|
31
|
-
status="error",
|
|
32
|
-
func_return="Agent state is required for external Composio tools. Please contact Letta support if you see this error.",
|
|
33
|
-
)
|
|
34
|
-
action_name = generate_composio_action_from_func_name(tool.name)
|
|
35
|
-
|
|
36
|
-
# Get entity ID from the agent_state
|
|
37
|
-
entity_id = self._get_entity_id(agent_state)
|
|
38
|
-
|
|
39
|
-
# Get composio_api_key
|
|
40
|
-
composio_api_key = await get_composio_api_key_async(actor=actor)
|
|
41
|
-
|
|
42
|
-
# TODO (matt): Roll in execute_composio_action into this class
|
|
43
|
-
function_response = await execute_composio_action_async(
|
|
44
|
-
action_name=action_name, args=function_args, api_key=composio_api_key, entity_id=entity_id
|
|
45
|
-
)
|
|
46
|
-
|
|
47
|
-
return ToolExecutionResult(
|
|
48
|
-
status="success",
|
|
49
|
-
func_return=function_response,
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
def _get_entity_id(self, agent_state: AgentState) -> Optional[str]:
|
|
53
|
-
"""Extract the entity ID from environment variables."""
|
|
54
|
-
for env_var in agent_state.secrets:
|
|
55
|
-
if env_var.key == COMPOSIO_ENTITY_ENV_VAR_KEY:
|
|
56
|
-
return env_var.value
|
|
57
|
-
return None
|
|
File without changes
|
|
File without changes
|