letta-nightly 0.5.4.dev20241122104229__py3-none-any.whl → 0.5.5.dev20241122170327__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/client/client.py +0 -65
- letta/metadata.py +4 -17
- letta/schemas/block.py +1 -15
- letta/schemas/memory.py +0 -33
- letta/server/rest_api/routers/v1/agents.py +1 -85
- letta/server/server.py +5 -137
- {letta_nightly-0.5.4.dev20241122104229.dist-info → letta_nightly-0.5.5.dev20241122170327.dist-info}/METADATA +1 -1
- {letta_nightly-0.5.4.dev20241122104229.dist-info → letta_nightly-0.5.5.dev20241122170327.dist-info}/RECORD +12 -12
- {letta_nightly-0.5.4.dev20241122104229.dist-info → letta_nightly-0.5.5.dev20241122170327.dist-info}/LICENSE +0 -0
- {letta_nightly-0.5.4.dev20241122104229.dist-info → letta_nightly-0.5.5.dev20241122170327.dist-info}/WHEEL +0 -0
- {letta_nightly-0.5.4.dev20241122104229.dist-info → letta_nightly-0.5.5.dev20241122170327.dist-info}/entry_points.txt +0 -0
letta/__init__.py
CHANGED
letta/client/client.py
CHANGED
|
@@ -1565,53 +1565,6 @@ class RESTClient(AbstractClient):
|
|
|
1565
1565
|
# Parse and return the deleted organization
|
|
1566
1566
|
return Organization(**response.json())
|
|
1567
1567
|
|
|
1568
|
-
def update_agent_memory_label(self, agent_id: str, current_label: str, new_label: str) -> Memory:
|
|
1569
|
-
|
|
1570
|
-
# @router.patch("/{agent_id}/memory/label", response_model=Memory, operation_id="update_agent_memory_label")
|
|
1571
|
-
response = requests.patch(
|
|
1572
|
-
f"{self.base_url}/{self.api_prefix}/agents/{agent_id}/memory/label",
|
|
1573
|
-
headers=self.headers,
|
|
1574
|
-
json={"current_label": current_label, "new_label": new_label},
|
|
1575
|
-
)
|
|
1576
|
-
if response.status_code != 200:
|
|
1577
|
-
raise ValueError(f"Failed to update agent memory label: {response.text}")
|
|
1578
|
-
return Memory(**response.json())
|
|
1579
|
-
|
|
1580
|
-
def add_agent_memory_block(self, agent_id: str, create_block: BlockCreate) -> Memory:
|
|
1581
|
-
|
|
1582
|
-
# @router.post("/{agent_id}/memory/block", response_model=Memory, operation_id="add_agent_memory_block")
|
|
1583
|
-
response = requests.post(
|
|
1584
|
-
f"{self.base_url}/{self.api_prefix}/agents/{agent_id}/memory/block",
|
|
1585
|
-
headers=self.headers,
|
|
1586
|
-
json=create_block.model_dump(),
|
|
1587
|
-
)
|
|
1588
|
-
if response.status_code != 200:
|
|
1589
|
-
raise ValueError(f"Failed to add agent memory block: {response.text}")
|
|
1590
|
-
return Memory(**response.json())
|
|
1591
|
-
|
|
1592
|
-
def remove_agent_memory_block(self, agent_id: str, block_label: str) -> Memory:
|
|
1593
|
-
|
|
1594
|
-
# @router.delete("/{agent_id}/memory/block/{block_label}", response_model=Memory, operation_id="remove_agent_memory_block")
|
|
1595
|
-
response = requests.delete(
|
|
1596
|
-
f"{self.base_url}/{self.api_prefix}/agents/{agent_id}/memory/block/{block_label}",
|
|
1597
|
-
headers=self.headers,
|
|
1598
|
-
)
|
|
1599
|
-
if response.status_code != 200:
|
|
1600
|
-
raise ValueError(f"Failed to remove agent memory block: {response.text}")
|
|
1601
|
-
return Memory(**response.json())
|
|
1602
|
-
|
|
1603
|
-
def update_agent_memory_limit(self, agent_id: str, block_label: str, limit: int) -> Memory:
|
|
1604
|
-
|
|
1605
|
-
# @router.patch("/{agent_id}/memory/limit", response_model=Memory, operation_id="update_agent_memory_limit")
|
|
1606
|
-
response = requests.patch(
|
|
1607
|
-
f"{self.base_url}/{self.api_prefix}/agents/{agent_id}/memory/limit",
|
|
1608
|
-
headers=self.headers,
|
|
1609
|
-
json={"label": block_label, "limit": limit},
|
|
1610
|
-
)
|
|
1611
|
-
if response.status_code != 200:
|
|
1612
|
-
raise ValueError(f"Failed to update agent memory limit: {response.text}")
|
|
1613
|
-
return Memory(**response.json())
|
|
1614
|
-
|
|
1615
1568
|
|
|
1616
1569
|
class LocalClient(AbstractClient):
|
|
1617
1570
|
"""
|
|
@@ -2820,21 +2773,3 @@ class LocalClient(AbstractClient):
|
|
|
2820
2773
|
|
|
2821
2774
|
def delete_org(self, org_id: str) -> Organization:
|
|
2822
2775
|
return self.server.organization_manager.delete_organization_by_id(org_id=org_id)
|
|
2823
|
-
|
|
2824
|
-
def update_agent_memory_label(self, agent_id: str, current_label: str, new_label: str) -> Memory:
|
|
2825
|
-
return self.server.update_agent_memory_label(
|
|
2826
|
-
user_id=self.user_id, agent_id=agent_id, current_block_label=current_label, new_block_label=new_label
|
|
2827
|
-
)
|
|
2828
|
-
|
|
2829
|
-
def add_agent_memory_block(self, agent_id: str, create_block: BlockCreate) -> Memory:
|
|
2830
|
-
block_req = Block(**create_block.model_dump())
|
|
2831
|
-
block = self.server.block_manager.create_or_update_block(actor=self.user, block=block_req)
|
|
2832
|
-
# Link the block to the agent
|
|
2833
|
-
updated_memory = self.server.link_block_to_agent_memory(user_id=self.user_id, agent_id=agent_id, block_id=block.id)
|
|
2834
|
-
return updated_memory
|
|
2835
|
-
|
|
2836
|
-
def remove_agent_memory_block(self, agent_id: str, block_label: str) -> Memory:
|
|
2837
|
-
return self.server.unlink_block_from_agent_memory(user_id=self.user_id, agent_id=agent_id, block_label=block_label)
|
|
2838
|
-
|
|
2839
|
-
def update_agent_memory_limit(self, agent_id: str, block_label: str, limit: int) -> Memory:
|
|
2840
|
-
return self.server.update_agent_memory_limit(user_id=self.user_id, agent_id=agent_id, block_label=block_label, limit=limit)
|
letta/metadata.py
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
import os
|
|
4
4
|
import secrets
|
|
5
|
-
import warnings
|
|
6
5
|
from typing import List, Optional
|
|
7
6
|
|
|
8
7
|
from sqlalchemy import JSON, Column, DateTime, Index, String, TypeDecorator
|
|
@@ -354,14 +353,8 @@ class MetadataStore:
|
|
|
354
353
|
raise ValueError(f"Agent with name {agent.name} already exists")
|
|
355
354
|
fields = vars(agent)
|
|
356
355
|
fields["memory"] = agent.memory.to_dict()
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
else:
|
|
360
|
-
warnings.warn(f"Agent {agent.id} has no _internal_memory field")
|
|
361
|
-
if "tags" in fields:
|
|
362
|
-
del fields["tags"]
|
|
363
|
-
else:
|
|
364
|
-
warnings.warn(f"Agent {agent.id} has no tags field")
|
|
356
|
+
del fields["_internal_memory"]
|
|
357
|
+
del fields["tags"]
|
|
365
358
|
session.add(AgentModel(**fields))
|
|
366
359
|
session.commit()
|
|
367
360
|
|
|
@@ -371,14 +364,8 @@ class MetadataStore:
|
|
|
371
364
|
fields = vars(agent)
|
|
372
365
|
if isinstance(agent.memory, Memory): # TODO: this is nasty but this whole class will soon be removed so whatever
|
|
373
366
|
fields["memory"] = agent.memory.to_dict()
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
else:
|
|
377
|
-
warnings.warn(f"Agent {agent.id} has no _internal_memory field")
|
|
378
|
-
if "tags" in fields:
|
|
379
|
-
del fields["tags"]
|
|
380
|
-
else:
|
|
381
|
-
warnings.warn(f"Agent {agent.id} has no tags field")
|
|
367
|
+
del fields["_internal_memory"]
|
|
368
|
+
del fields["tags"]
|
|
382
369
|
session.query(AgentModel).filter(AgentModel.id == agent.id).update(fields)
|
|
383
370
|
session.commit()
|
|
384
371
|
|
letta/schemas/block.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from typing import Optional
|
|
2
2
|
|
|
3
|
-
from pydantic import
|
|
3
|
+
from pydantic import Field, model_validator
|
|
4
4
|
from typing_extensions import Self
|
|
5
5
|
|
|
6
6
|
from letta.schemas.letta_base import LettaBase
|
|
@@ -95,13 +95,6 @@ class BlockCreate(BaseBlock):
|
|
|
95
95
|
label: str = Field(..., description="Label of the block.")
|
|
96
96
|
|
|
97
97
|
|
|
98
|
-
class BlockLabelUpdate(BaseModel):
|
|
99
|
-
"""Update the label of a block"""
|
|
100
|
-
|
|
101
|
-
current_label: str = Field(..., description="Current label of the block.")
|
|
102
|
-
new_label: str = Field(..., description="New label of the block.")
|
|
103
|
-
|
|
104
|
-
|
|
105
98
|
class CreatePersona(BlockCreate):
|
|
106
99
|
"""Create a persona block"""
|
|
107
100
|
|
|
@@ -124,13 +117,6 @@ class BlockUpdate(BaseBlock):
|
|
|
124
117
|
extra = "ignore" # Ignores extra fields
|
|
125
118
|
|
|
126
119
|
|
|
127
|
-
class BlockLimitUpdate(BaseModel):
|
|
128
|
-
"""Update the limit of a block"""
|
|
129
|
-
|
|
130
|
-
label: str = Field(..., description="Label of the block.")
|
|
131
|
-
limit: int = Field(..., description="New limit of the block.")
|
|
132
|
-
|
|
133
|
-
|
|
134
120
|
class UpdatePersona(BlockUpdate):
|
|
135
121
|
"""Update a persona block"""
|
|
136
122
|
|
letta/schemas/memory.py
CHANGED
|
@@ -158,13 +158,6 @@ class Memory(BaseModel, validate_assignment=True):
|
|
|
158
158
|
|
|
159
159
|
self.memory[block.label] = block
|
|
160
160
|
|
|
161
|
-
def unlink_block(self, block_label: str) -> Block:
|
|
162
|
-
"""Unlink a block from the memory object"""
|
|
163
|
-
if block_label not in self.memory:
|
|
164
|
-
raise ValueError(f"Block with label {block_label} does not exist")
|
|
165
|
-
|
|
166
|
-
return self.memory.pop(block_label)
|
|
167
|
-
|
|
168
161
|
def update_block_value(self, label: str, value: str):
|
|
169
162
|
"""Update the value of a block"""
|
|
170
163
|
if label not in self.memory:
|
|
@@ -174,32 +167,6 @@ class Memory(BaseModel, validate_assignment=True):
|
|
|
174
167
|
|
|
175
168
|
self.memory[label].value = value
|
|
176
169
|
|
|
177
|
-
def update_block_label(self, current_label: str, new_label: str):
|
|
178
|
-
"""Update the label of a block"""
|
|
179
|
-
if current_label not in self.memory:
|
|
180
|
-
raise ValueError(f"Block with label {current_label} does not exist")
|
|
181
|
-
if not isinstance(new_label, str):
|
|
182
|
-
raise ValueError(f"Provided new label must be a string")
|
|
183
|
-
|
|
184
|
-
# First change the label of the block
|
|
185
|
-
self.memory[current_label].label = new_label
|
|
186
|
-
|
|
187
|
-
# Then swap the block to the new label
|
|
188
|
-
self.memory[new_label] = self.memory.pop(current_label)
|
|
189
|
-
|
|
190
|
-
def update_block_limit(self, label: str, limit: int):
|
|
191
|
-
"""Update the limit of a block"""
|
|
192
|
-
if label not in self.memory:
|
|
193
|
-
raise ValueError(f"Block with label {label} does not exist")
|
|
194
|
-
if not isinstance(limit, int):
|
|
195
|
-
raise ValueError(f"Provided limit must be an integer")
|
|
196
|
-
|
|
197
|
-
# Check to make sure the new limit is greater than the current length of the block
|
|
198
|
-
if len(self.memory[label].value) > limit:
|
|
199
|
-
raise ValueError(f"New limit {limit} is less than the current length of the block {len(self.memory[label].value)}")
|
|
200
|
-
|
|
201
|
-
self.memory[label].limit = limit
|
|
202
|
-
|
|
203
170
|
|
|
204
171
|
# TODO: ideally this is refactored into ChatMemory and the subclasses are given more specific names.
|
|
205
172
|
class BasicBlockMemory(Memory):
|
|
@@ -7,7 +7,6 @@ from fastapi.responses import JSONResponse, StreamingResponse
|
|
|
7
7
|
|
|
8
8
|
from letta.constants import DEFAULT_MESSAGE_TOOL, DEFAULT_MESSAGE_TOOL_KWARG
|
|
9
9
|
from letta.schemas.agent import AgentState, CreateAgent, UpdateAgentState
|
|
10
|
-
from letta.schemas.block import Block, BlockCreate, BlockLabelUpdate, BlockLimitUpdate
|
|
11
10
|
from letta.schemas.enums import MessageStreamStatus
|
|
12
11
|
from letta.schemas.letta_message import (
|
|
13
12
|
LegacyLettaMessage,
|
|
@@ -218,9 +217,7 @@ def update_agent_memory(
|
|
|
218
217
|
):
|
|
219
218
|
"""
|
|
220
219
|
Update the core memory of a specific agent.
|
|
221
|
-
|
|
222
|
-
This endpoint accepts new memory contents to update the core memory of the agent.
|
|
223
|
-
This endpoint only supports modifying existing blocks; it does not support deleting/unlinking or creating/linking blocks.
|
|
220
|
+
This endpoint accepts new memory contents (human and persona) and updates the core memory of the agent identified by the user ID and agent ID.
|
|
224
221
|
"""
|
|
225
222
|
actor = server.get_user_or_default(user_id=user_id)
|
|
226
223
|
|
|
@@ -228,87 +225,6 @@ def update_agent_memory(
|
|
|
228
225
|
return memory
|
|
229
226
|
|
|
230
227
|
|
|
231
|
-
@router.patch("/{agent_id}/memory/label", response_model=Memory, operation_id="update_agent_memory_label")
|
|
232
|
-
def update_agent_memory_label(
|
|
233
|
-
agent_id: str,
|
|
234
|
-
update_label: BlockLabelUpdate = Body(...),
|
|
235
|
-
server: "SyncServer" = Depends(get_letta_server),
|
|
236
|
-
user_id: Optional[str] = Header(None, alias="user_id"), # Extract user_id from header, default to None if not present
|
|
237
|
-
):
|
|
238
|
-
"""
|
|
239
|
-
Update the label of a block in an agent's memory.
|
|
240
|
-
"""
|
|
241
|
-
actor = server.get_user_or_default(user_id=user_id)
|
|
242
|
-
|
|
243
|
-
memory = server.update_agent_memory_label(
|
|
244
|
-
user_id=actor.id, agent_id=agent_id, current_block_label=update_label.current_label, new_block_label=update_label.new_label
|
|
245
|
-
)
|
|
246
|
-
return memory
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
@router.post("/{agent_id}/memory/block", response_model=Memory, operation_id="add_agent_memory_block")
|
|
250
|
-
def add_agent_memory_block(
|
|
251
|
-
agent_id: str,
|
|
252
|
-
create_block: BlockCreate = Body(...),
|
|
253
|
-
server: "SyncServer" = Depends(get_letta_server),
|
|
254
|
-
user_id: Optional[str] = Header(None, alias="user_id"), # Extract user_id from header, default to None if not present
|
|
255
|
-
):
|
|
256
|
-
"""
|
|
257
|
-
Creates a memory block and links it to the agent.
|
|
258
|
-
"""
|
|
259
|
-
actor = server.get_user_or_default(user_id=user_id)
|
|
260
|
-
|
|
261
|
-
# Copied from POST /blocks
|
|
262
|
-
block_req = Block(**create_block.model_dump())
|
|
263
|
-
block = server.block_manager.create_or_update_block(actor=actor, block=block_req)
|
|
264
|
-
|
|
265
|
-
# Link the block to the agent
|
|
266
|
-
updated_memory = server.link_block_to_agent_memory(user_id=actor.id, agent_id=agent_id, block_id=block.id)
|
|
267
|
-
|
|
268
|
-
return updated_memory
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
@router.delete("/{agent_id}/memory/block/{block_label}", response_model=Memory, operation_id="remove_agent_memory_block")
|
|
272
|
-
def remove_agent_memory_block(
|
|
273
|
-
agent_id: str,
|
|
274
|
-
# TODO should this be block_id, or the label?
|
|
275
|
-
# I think label is OK since it's user-friendly + guaranteed to be unique within a Memory object
|
|
276
|
-
block_label: str,
|
|
277
|
-
server: "SyncServer" = Depends(get_letta_server),
|
|
278
|
-
user_id: Optional[str] = Header(None, alias="user_id"), # Extract user_id from header, default to None if not present
|
|
279
|
-
):
|
|
280
|
-
"""
|
|
281
|
-
Removes a memory block from an agent by unlnking it. If the block is not linked to any other agent, it is deleted.
|
|
282
|
-
"""
|
|
283
|
-
actor = server.get_user_or_default(user_id=user_id)
|
|
284
|
-
|
|
285
|
-
# Unlink the block from the agent
|
|
286
|
-
updated_memory = server.unlink_block_from_agent_memory(user_id=actor.id, agent_id=agent_id, block_label=block_label)
|
|
287
|
-
|
|
288
|
-
return updated_memory
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
@router.patch("/{agent_id}/memory/limit", response_model=Memory, operation_id="update_agent_memory_limit")
|
|
292
|
-
def update_agent_memory_limit(
|
|
293
|
-
agent_id: str,
|
|
294
|
-
update_label: BlockLimitUpdate = Body(...),
|
|
295
|
-
server: "SyncServer" = Depends(get_letta_server),
|
|
296
|
-
user_id: Optional[str] = Header(None, alias="user_id"), # Extract user_id from header, default to None if not present
|
|
297
|
-
):
|
|
298
|
-
"""
|
|
299
|
-
Update the limit of a block in an agent's memory.
|
|
300
|
-
"""
|
|
301
|
-
actor = server.get_user_or_default(user_id=user_id)
|
|
302
|
-
|
|
303
|
-
memory = server.update_agent_memory_limit(
|
|
304
|
-
user_id=actor.id,
|
|
305
|
-
agent_id=agent_id,
|
|
306
|
-
block_label=update_label.label,
|
|
307
|
-
limit=update_label.limit,
|
|
308
|
-
)
|
|
309
|
-
return memory
|
|
310
|
-
|
|
311
|
-
|
|
312
228
|
@router.get("/{agent_id}/memory/recall", response_model=RecallMemorySummary, operation_id="get_agent_recall_memory_summary")
|
|
313
229
|
def get_agent_recall_memory_summary(
|
|
314
230
|
agent_id: str,
|
letta/server/server.py
CHANGED
|
@@ -409,10 +409,8 @@ class SyncServer(Server):
|
|
|
409
409
|
logger.exception(f"Error occurred while trying to get agent {agent_id}:\n{e}")
|
|
410
410
|
raise
|
|
411
411
|
|
|
412
|
-
def _get_or_load_agent(self, agent_id: str
|
|
412
|
+
def _get_or_load_agent(self, agent_id: str) -> Agent:
|
|
413
413
|
"""Check if the agent is in-memory, then load"""
|
|
414
|
-
|
|
415
|
-
# Gets the agent state
|
|
416
414
|
agent_state = self.ms.get_agent(agent_id=agent_id)
|
|
417
415
|
if not agent_state:
|
|
418
416
|
raise ValueError(f"Agent does not exist")
|
|
@@ -420,24 +418,11 @@ class SyncServer(Server):
|
|
|
420
418
|
actor = self.user_manager.get_user_by_id(user_id)
|
|
421
419
|
|
|
422
420
|
logger.debug(f"Checking for agent user_id={user_id} agent_id={agent_id}")
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
logger.debug(f"Agent not loaded, loading agent user_id={user_id} agent_id={agent_id}")
|
|
428
|
-
letta_agent = self._load_agent(agent_id=agent_id, actor=actor)
|
|
429
|
-
else:
|
|
430
|
-
# This breaks unit tests in test_local_client.py
|
|
421
|
+
# TODO: consider disabling loading cached agents due to potential concurrency issues
|
|
422
|
+
letta_agent = self._get_agent(user_id=user_id, agent_id=agent_id)
|
|
423
|
+
if not letta_agent:
|
|
424
|
+
logger.debug(f"Agent not loaded, loading agent user_id={user_id} agent_id={agent_id}")
|
|
431
425
|
letta_agent = self._load_agent(agent_id=agent_id, actor=actor)
|
|
432
|
-
|
|
433
|
-
# letta_agent = self._get_agent(user_id=user_id, agent_id=agent_id)
|
|
434
|
-
# if not letta_agent:
|
|
435
|
-
# logger.debug(f"Agent not loaded, loading agent user_id={user_id} agent_id={agent_id}")
|
|
436
|
-
|
|
437
|
-
# NOTE: no longer caching, always forcing a lot from the database
|
|
438
|
-
# Loads the agent objects
|
|
439
|
-
# letta_agent = self._load_agent(agent_id=agent_id, actor=actor)
|
|
440
|
-
|
|
441
426
|
return letta_agent
|
|
442
427
|
|
|
443
428
|
def _step(
|
|
@@ -1456,7 +1441,6 @@ class SyncServer(Server):
|
|
|
1456
1441
|
# If we modified the memory contents, we need to rebuild the memory block inside the system message
|
|
1457
1442
|
if modified:
|
|
1458
1443
|
letta_agent.rebuild_memory()
|
|
1459
|
-
# letta_agent.rebuild_memory(force=True, ms=self.ms) # This breaks unit tests in test_local_client.py
|
|
1460
1444
|
# save agent
|
|
1461
1445
|
save_agent(letta_agent, self.ms)
|
|
1462
1446
|
|
|
@@ -1843,119 +1827,3 @@ class SyncServer(Server):
|
|
|
1843
1827
|
# Get the current message
|
|
1844
1828
|
letta_agent = self._get_or_load_agent(agent_id=agent_id)
|
|
1845
1829
|
return letta_agent.get_context_window()
|
|
1846
|
-
|
|
1847
|
-
def update_agent_memory_label(self, user_id: str, agent_id: str, current_block_label: str, new_block_label: str) -> Memory:
|
|
1848
|
-
"""Update the label of a block in an agent's memory"""
|
|
1849
|
-
|
|
1850
|
-
# Get the user
|
|
1851
|
-
user = self.user_manager.get_user_by_id(user_id=user_id)
|
|
1852
|
-
|
|
1853
|
-
# Link a block to an agent's memory
|
|
1854
|
-
letta_agent = self._get_or_load_agent(agent_id=agent_id)
|
|
1855
|
-
letta_agent.memory.update_block_label(current_label=current_block_label, new_label=new_block_label)
|
|
1856
|
-
assert new_block_label in letta_agent.memory.list_block_labels()
|
|
1857
|
-
self.block_manager.create_or_update_block(block=letta_agent.memory.get_block(new_block_label), actor=user)
|
|
1858
|
-
|
|
1859
|
-
# check that the block was updated
|
|
1860
|
-
updated_block = self.block_manager.get_block_by_id(block_id=letta_agent.memory.get_block(new_block_label).id, actor=user)
|
|
1861
|
-
|
|
1862
|
-
# Recompile the agent memory
|
|
1863
|
-
letta_agent.rebuild_memory(force=True, ms=self.ms)
|
|
1864
|
-
|
|
1865
|
-
# save agent
|
|
1866
|
-
save_agent(letta_agent, self.ms)
|
|
1867
|
-
|
|
1868
|
-
updated_agent = self.ms.get_agent(agent_id=agent_id)
|
|
1869
|
-
if updated_agent is None:
|
|
1870
|
-
raise ValueError(f"Agent with id {agent_id} not found after linking block")
|
|
1871
|
-
assert new_block_label in updated_agent.memory.list_block_labels()
|
|
1872
|
-
assert current_block_label not in updated_agent.memory.list_block_labels()
|
|
1873
|
-
return updated_agent.memory
|
|
1874
|
-
|
|
1875
|
-
def link_block_to_agent_memory(self, user_id: str, agent_id: str, block_id: str) -> Memory:
|
|
1876
|
-
"""Link a block to an agent's memory"""
|
|
1877
|
-
|
|
1878
|
-
# Get the user
|
|
1879
|
-
user = self.user_manager.get_user_by_id(user_id=user_id)
|
|
1880
|
-
|
|
1881
|
-
# Get the block first
|
|
1882
|
-
block = self.block_manager.get_block_by_id(block_id=block_id, actor=user)
|
|
1883
|
-
if block is None:
|
|
1884
|
-
raise ValueError(f"Block with id {block_id} not found")
|
|
1885
|
-
|
|
1886
|
-
# Link a block to an agent's memory
|
|
1887
|
-
letta_agent = self._get_or_load_agent(agent_id=agent_id)
|
|
1888
|
-
letta_agent.memory.link_block(block=block)
|
|
1889
|
-
assert block.label in letta_agent.memory.list_block_labels()
|
|
1890
|
-
|
|
1891
|
-
# Recompile the agent memory
|
|
1892
|
-
letta_agent.rebuild_memory(force=True, ms=self.ms)
|
|
1893
|
-
|
|
1894
|
-
# save agent
|
|
1895
|
-
save_agent(letta_agent, self.ms)
|
|
1896
|
-
|
|
1897
|
-
updated_agent = self.ms.get_agent(agent_id=agent_id)
|
|
1898
|
-
if updated_agent is None:
|
|
1899
|
-
raise ValueError(f"Agent with id {agent_id} not found after linking block")
|
|
1900
|
-
assert block.label in updated_agent.memory.list_block_labels()
|
|
1901
|
-
|
|
1902
|
-
return updated_agent.memory
|
|
1903
|
-
|
|
1904
|
-
def unlink_block_from_agent_memory(self, user_id: str, agent_id: str, block_label: str, delete_if_no_ref: bool = True) -> Memory:
|
|
1905
|
-
"""Unlink a block from an agent's memory. If the block is not linked to any agent, delete it."""
|
|
1906
|
-
|
|
1907
|
-
# Get the user
|
|
1908
|
-
user = self.user_manager.get_user_by_id(user_id=user_id)
|
|
1909
|
-
|
|
1910
|
-
# Link a block to an agent's memory
|
|
1911
|
-
letta_agent = self._get_or_load_agent(agent_id=agent_id)
|
|
1912
|
-
unlinked_block = letta_agent.memory.unlink_block(block_label=block_label)
|
|
1913
|
-
assert unlinked_block.label not in letta_agent.memory.list_block_labels()
|
|
1914
|
-
|
|
1915
|
-
# Check if the block is linked to any other agent
|
|
1916
|
-
# TODO needs reference counting GC to handle loose blocks
|
|
1917
|
-
# block = self.block_manager.get_block_by_id(block_id=unlinked_block.id, actor=user)
|
|
1918
|
-
# if block is None:
|
|
1919
|
-
# raise ValueError(f"Block with id {block_id} not found")
|
|
1920
|
-
|
|
1921
|
-
# Recompile the agent memory
|
|
1922
|
-
letta_agent.rebuild_memory(force=True, ms=self.ms)
|
|
1923
|
-
|
|
1924
|
-
# save agent
|
|
1925
|
-
save_agent(letta_agent, self.ms)
|
|
1926
|
-
|
|
1927
|
-
updated_agent = self.ms.get_agent(agent_id=agent_id)
|
|
1928
|
-
if updated_agent is None:
|
|
1929
|
-
raise ValueError(f"Agent with id {agent_id} not found after linking block")
|
|
1930
|
-
assert unlinked_block.label not in updated_agent.memory.list_block_labels()
|
|
1931
|
-
return updated_agent.memory
|
|
1932
|
-
|
|
1933
|
-
def update_agent_memory_limit(self, user_id: str, agent_id: str, block_label: str, limit: int) -> Memory:
|
|
1934
|
-
"""Update the limit of a block in an agent's memory"""
|
|
1935
|
-
|
|
1936
|
-
# Get the user
|
|
1937
|
-
user = self.user_manager.get_user_by_id(user_id=user_id)
|
|
1938
|
-
|
|
1939
|
-
# Link a block to an agent's memory
|
|
1940
|
-
letta_agent = self._get_or_load_agent(agent_id=agent_id)
|
|
1941
|
-
letta_agent.memory.update_block_limit(label=block_label, limit=limit)
|
|
1942
|
-
assert block_label in letta_agent.memory.list_block_labels()
|
|
1943
|
-
|
|
1944
|
-
# write out the update the database
|
|
1945
|
-
self.block_manager.create_or_update_block(block=letta_agent.memory.get_block(block_label), actor=user)
|
|
1946
|
-
|
|
1947
|
-
# check that the block was updated
|
|
1948
|
-
updated_block = self.block_manager.get_block_by_id(block_id=letta_agent.memory.get_block(block_label).id, actor=user)
|
|
1949
|
-
assert updated_block and updated_block.limit == limit
|
|
1950
|
-
|
|
1951
|
-
# Recompile the agent memory
|
|
1952
|
-
letta_agent.rebuild_memory(force=True, ms=self.ms)
|
|
1953
|
-
|
|
1954
|
-
# save agent
|
|
1955
|
-
save_agent(letta_agent, self.ms)
|
|
1956
|
-
|
|
1957
|
-
updated_agent = self.ms.get_agent(agent_id=agent_id)
|
|
1958
|
-
if updated_agent is None:
|
|
1959
|
-
raise ValueError(f"Agent with id {agent_id} not found after linking block")
|
|
1960
|
-
assert updated_agent.memory.get_block(label=block_label).limit == limit
|
|
1961
|
-
return updated_agent.memory
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
letta/__init__.py,sha256=
|
|
1
|
+
letta/__init__.py,sha256=ipA7AF1PmUrwfj0xf_j3pB4IMe9wwRoX0yMzNU-Umos,1014
|
|
2
2
|
letta/__main__.py,sha256=6Hs2PV7EYc5Tid4g4OtcLXhqVHiNYTGzSBdoOnW2HXA,29
|
|
3
3
|
letta/agent.py,sha256=7uc2v0mfAX46RdxPY-HIlfeO15mgBORfnr7bi84Ik4o,77430
|
|
4
4
|
letta/agent_store/chroma.py,sha256=upR5zGnGs6I6btulEYbiZdGG87BgKjxUJOQZ4Y-RQ_M,12492
|
|
@@ -13,7 +13,7 @@ letta/cli/cli.py,sha256=1dJIZ8DIGM8mg0G0UGLKMTa3fwgHzrN8Hkxd5Uxx7X4,16946
|
|
|
13
13
|
letta/cli/cli_config.py,sha256=D-CpSZI1cDvdSQr3-zhGuDrJnZo1Ko7bi_wuxcBxxqo,8555
|
|
14
14
|
letta/cli/cli_load.py,sha256=x4L8s15GwIW13xrhKYFWHo_y-IVGtoPDHWWKcHDRP10,4587
|
|
15
15
|
letta/client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
|
-
letta/client/client.py,sha256=
|
|
16
|
+
letta/client/client.py,sha256=Fx_3peTW88ycfscSb5DdSYzABWpliCcpDDr8Wd_bfTY,98751
|
|
17
17
|
letta/client/streaming.py,sha256=Hh5pjlyrdCuO2V75ZCxSSOCPd3BmHdKFGaIUJC6fBp0,4775
|
|
18
18
|
letta/client/utils.py,sha256=OJlAKWrldc4I6M1WpcTWNtPJ4wfxlzlZqWLfCozkFtI,2872
|
|
19
19
|
letta/config.py,sha256=eK-ip06ELHNYriInkgfidDvJxQ2tD1u49I-VLXB87nE,18929
|
|
@@ -85,7 +85,7 @@ letta/local_llm/webui/settings.py,sha256=gmLHfiOl1u4JmlAZU2d2O8YKF9lafdakyjwR_ft
|
|
|
85
85
|
letta/log.py,sha256=Oy5b71AXfrnQShxI_4ULo5U3kmZJG01bXbP_64Nr4Fk,2105
|
|
86
86
|
letta/main.py,sha256=cFnjnbzyrRRM5sZeRAnGVq_rPIgJRHRFyFNCY--sRI4,19163
|
|
87
87
|
letta/memory.py,sha256=YupXOvzVJXH59RW4XWBrd7qMNEYaMbtWXCheKeWZwpU,17873
|
|
88
|
-
letta/metadata.py,sha256=
|
|
88
|
+
letta/metadata.py,sha256=DoLXPfxqgWEWYpwg1B8g19Vae6v6jnljSwUr8wXEF3M,17620
|
|
89
89
|
letta/o1_agent.py,sha256=qYyAdLnKu7dQw6OxxsFQz32d-lLJLo64MnH165oQm7s,3180
|
|
90
90
|
letta/openai_backcompat/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
91
91
|
letta/openai_backcompat/openai_object.py,sha256=Y1ZS1sATP60qxJiOsjOP3NbwSzuzvkNAvb3DeuhM5Uk,13490
|
|
@@ -131,7 +131,7 @@ letta/pytest.ini,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
131
131
|
letta/schemas/agent.py,sha256=f0khTBWIRGZva4_C15Nm_tkmn1cwaVQlWa7_7laRbEE,7866
|
|
132
132
|
letta/schemas/agents_tags.py,sha256=9DGr8fN2DHYdWvZ_qcXmrKI0w7YKCGz2lfEcrX2KAkI,1130
|
|
133
133
|
letta/schemas/api_key.py,sha256=u07yzzMn-hBAHZIIKbWY16KsgiFjSNR8lAghpMUo3_4,682
|
|
134
|
-
letta/schemas/block.py,sha256=
|
|
134
|
+
letta/schemas/block.py,sha256=drnVWEmsx9NevCgq2STIxdSoCDPrp09Sy0Vq42Xbzz4,4315
|
|
135
135
|
letta/schemas/embedding_config.py,sha256=1kD6NpiXeH4roVumxqDAKk7xt8SpXGWNhZs_XXUSlEU,2855
|
|
136
136
|
letta/schemas/enums.py,sha256=WfRYpLh_pD-VyhEnp3Y6pPfx063zq2o4jky6PulqO8w,629
|
|
137
137
|
letta/schemas/file.py,sha256=ChN2CWzLI2TT9WLItcfElEH0E8b7kzPylF2OQBr6Beg,1550
|
|
@@ -142,7 +142,7 @@ letta/schemas/letta_message.py,sha256=RuVVtwFbi85yP3dXQxowofQ6cI2cO_CdGtgpHGQzgH
|
|
|
142
142
|
letta/schemas/letta_request.py,sha256=_oiDshc_AoFWIfXRk2VX5-AxO5vDlyN-9r-gnyLj_30,1890
|
|
143
143
|
letta/schemas/letta_response.py,sha256=li_j4VUF_WtxdJy7ufRmmmchzvhVmr1idbOxtgFGiy0,6253
|
|
144
144
|
letta/schemas/llm_config.py,sha256=RbgnCaqYd_yl-Xs7t-DEI1NhpKD8WiVWjxcwq5mZd5M,4467
|
|
145
|
-
letta/schemas/memory.py,sha256=
|
|
145
|
+
letta/schemas/memory.py,sha256=fHkJZr8CrGcHhbJlckWgfRYMhLkRliKCU-hRxqr19ks,11725
|
|
146
146
|
letta/schemas/message.py,sha256=DQxnRYrYgHXpTKfMzfS-bpCAe-BO_Rmcfc1Wf-4GHjw,33703
|
|
147
147
|
letta/schemas/openai/chat_completion_request.py,sha256=AOIwgbN3CZKVqkuXeMHeSa53u4h0wVq69t3T_LJ0vIE,3389
|
|
148
148
|
letta/schemas/openai/chat_completion_response.py,sha256=ub-oVSyLpuJd-5_yzCSIRR8tD3GM83IeDO1c1uAATa4,3970
|
|
@@ -174,7 +174,7 @@ letta/server/rest_api/routers/openai/assistants/threads.py,sha256=WXVGBaBvSNPB7Z
|
|
|
174
174
|
letta/server/rest_api/routers/openai/chat_completions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
175
175
|
letta/server/rest_api/routers/openai/chat_completions/chat_completions.py,sha256=-uye6cm4SnoQGwxhr1N1FrSXOlnO2Hvbfj6k8JSc45k,4918
|
|
176
176
|
letta/server/rest_api/routers/v1/__init__.py,sha256=sqlVZa-u9DJwdRsp0_8YUGrac9DHguIB4wETlEDRylA,666
|
|
177
|
-
letta/server/rest_api/routers/v1/agents.py,sha256=
|
|
177
|
+
letta/server/rest_api/routers/v1/agents.py,sha256=bvlKgARwXWHq8_gJkiqYsU9ZXKBm2iDRTuosLnY8d9w,22043
|
|
178
178
|
letta/server/rest_api/routers/v1/blocks.py,sha256=ogJdn-Ir7h1ZEv28bHtUNNsR2zq9-wxXAMpu2t1EoIA,2946
|
|
179
179
|
letta/server/rest_api/routers/v1/health.py,sha256=pKCuVESlVOhGIb4VC4K-H82eZqfghmT6kvj2iOkkKuc,401
|
|
180
180
|
letta/server/rest_api/routers/v1/jobs.py,sha256=a-j0v-5A0un0pVCOHpfeWnzpOWkVDQO6ti42k_qAlZY,2272
|
|
@@ -185,7 +185,7 @@ letta/server/rest_api/routers/v1/tools.py,sha256=Bkb9oKswOycj5S3fBeim7LpDrZf37Sy
|
|
|
185
185
|
letta/server/rest_api/routers/v1/users.py,sha256=M1wEr2IyHzuRwINYxLXTkrbAH3osLe_cWjzrWrzR1aw,3729
|
|
186
186
|
letta/server/rest_api/static_files.py,sha256=NG8sN4Z5EJ8JVQdj19tkFa9iQ1kBPTab9f_CUxd_u4Q,3143
|
|
187
187
|
letta/server/rest_api/utils.py,sha256=GdHYCzXtbM5VCAYDPR0z5gnNZpRhwPld2BGZV7xT6cU,2924
|
|
188
|
-
letta/server/server.py,sha256=
|
|
188
|
+
letta/server/server.py,sha256=sH1_y5PUFcpjsNZe2OiVx5OZooSom9akedr1qPW094Y,77721
|
|
189
189
|
letta/server/startup.sh,sha256=wTOQOJJZw_Iec57WIu0UW0AVflk0ZMWYZWg8D3T_gSQ,698
|
|
190
190
|
letta/server/static_files/assets/index-3ab03d5b.css,sha256=OrA9W4iKJ5h2Wlr7GwdAT4wow0CM8hVit1yOxEL49Qw,54295
|
|
191
191
|
letta/server/static_files/assets/index-9fa459a2.js,sha256=j2oMcDJO9dWJaH5e-tsflbVpWK20gLWpZKJk4-Kuy6A,1815592
|
|
@@ -210,8 +210,8 @@ letta/streaming_interface.py,sha256=_FPUWy58j50evHcpXyd7zB1wWqeCc71NCFeWh_TBvnw,
|
|
|
210
210
|
letta/streaming_utils.py,sha256=329fsvj1ZN0r0LpQtmMPZ2vSxkDBIUUwvGHZFkjm2I8,11745
|
|
211
211
|
letta/system.py,sha256=buKYPqG5n2x41hVmWpu6JUpyd7vTWED9Km2_M7dLrvk,6960
|
|
212
212
|
letta/utils.py,sha256=COwQLAt02eEM9tjp6p5kN8YeTqGXr714l5BvffLVCLU,32376
|
|
213
|
-
letta_nightly-0.5.
|
|
214
|
-
letta_nightly-0.5.
|
|
215
|
-
letta_nightly-0.5.
|
|
216
|
-
letta_nightly-0.5.
|
|
217
|
-
letta_nightly-0.5.
|
|
213
|
+
letta_nightly-0.5.5.dev20241122170327.dist-info/LICENSE,sha256=mExtuZ_GYJgDEI38GWdiEYZizZS4KkVt2SF1g_GPNhI,10759
|
|
214
|
+
letta_nightly-0.5.5.dev20241122170327.dist-info/METADATA,sha256=J90RtHFQaC45m_vweNgH-iimhBIgn6u2oCLVIDh3GzM,11395
|
|
215
|
+
letta_nightly-0.5.5.dev20241122170327.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
216
|
+
letta_nightly-0.5.5.dev20241122170327.dist-info/entry_points.txt,sha256=2zdiyGNEZGV5oYBuS-y2nAAgjDgcC9yM_mHJBFSRt5U,40
|
|
217
|
+
letta_nightly-0.5.5.dev20241122170327.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|