Skip to content

armgit / letta

Public Imported from GitHub
0

Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.

Shub/let 1646 add agentfile to cloud (#1540)

Shubham Naikd96cbea250bd
diff --git a/letta/server/rest_api/routers/v1/agents.py b/letta/server/rest_api/routers/v1/agents.py
index 1dc6c632d..9914faffd 100644
--- a/letta/server/rest_api/routers/v1/agents.py
+++ b/letta/server/rest_api/routers/v1/agents.py
@@ -130,6 +130,10 @@ async def import_agent_serialized(
description="If set to True, existing tools can get their source code overwritten by the uploaded tool definitions. Note that Letta core tools can never be updated externally.",
),
project_id: Optional[str] = Query(None, description="The project ID to associate the uploaded agent with."),
+ strip_messages: bool = Query(
+ False,
+ description="If set to True, strips all messages from the agent before importing.",
+ ),
):
"""
Import a serialized agent file and recreate the agent in the system.
@@ -149,6 +153,7 @@ async def import_agent_serialized(
append_copy_suffix=append_copy_suffix,
override_existing_tools=override_existing_tools,
project_id=project_id,
+ strip_messages=strip_messages,
)
return new_agent
diff --git a/letta/services/agent_manager.py b/letta/services/agent_manager.py
index f0ada5454..19e7fb354 100644
--- a/letta/services/agent_manager.py
+++ b/letta/services/agent_manager.py
@@ -525,6 +525,7 @@ class AgentManager:
append_copy_suffix: bool = True,
override_existing_tools: bool = True,
project_id: Optional[str] = None,
+ strip_messages: Optional[bool] = False,
) -> PydanticAgentState:
serialized_agent = serialized_agent.model_dump()
tool_data_list = serialized_agent.pop("tools", [])
@@ -536,6 +537,10 @@ class AgentManager:
agent.name += "_copy"
if project_id:
agent.project_id = project_id
+
+ if strip_messages:
+ # we want to strip all but the first (system) message
+ agent.message_ids = [agent.message_ids[0]]
agent = agent.create(session, actor=actor)
pydantic_agent = agent.to_pydantic()