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.

feat: fix agentfile in clooud [PRO-1013] (#4271)

Shubham Naika64f500a8d9a
diff --git a/letta/server/rest_api/routers/v1/agents.py b/letta/server/rest_api/routers/v1/agents.py
index df34961ce..313ee0bec 100644
--- a/letta/server/rest_api/routers/v1/agents.py
+++ b/letta/server/rest_api/routers/v1/agents.py
@@ -264,7 +264,7 @@ async def import_agent(
try:
if override_embedding_handle:
- embedding_config_override = server.get_cached_embedding_config_async(actor=actor, handle=override_embedding_handle)
+ embedding_config_override = await server.get_cached_embedding_config_async(actor=actor, handle=override_embedding_handle)
else:
embedding_config_override = None
@@ -275,6 +275,7 @@ async def import_agent(
override_existing_tools=override_existing_tools,
env_vars=env_vars,
override_embedding_config=embedding_config_override,
+ project_id=project_id,
)
if not import_result.success:
@@ -303,6 +304,7 @@ async def import_agent_serialized(
file: UploadFile = File(...),
server: "SyncServer" = Depends(get_letta_server),
actor_id: str | None = Header(None, alias="user_id"),
+ x_override_embedding_model: str | None = Header(None, alias="x-override-embedding-model"),
append_copy_suffix: bool = Form(True, description='If set to True, appends "_copy" to the end of the agent name.'),
override_existing_tools: bool = Form(
True,
@@ -344,6 +346,9 @@ async def import_agent_serialized(
if not isinstance(env_vars, dict):
raise HTTPException(status_code=400, detail="env_vars_json must be a valid JSON string")
+ # Prioritize header over form data for override_embedding_handle
+ final_override_embedding_handle = x_override_embedding_model or override_embedding_handle
+
# Check if the JSON is AgentFileSchema or AgentSchema
# TODO: This is kind of hacky, but should work as long as dont' change the schema
if "agents" in agent_json and isinstance(agent_json.get("agents"), list):
@@ -357,6 +362,7 @@ async def import_agent_serialized(
project_id=project_id,
strip_messages=strip_messages,
env_vars=env_vars,
+ override_embedding_handle=final_override_embedding_handle,
)
else:
# This is a legacy AgentSchema
diff --git a/letta/services/agent_serialization_manager.py b/letta/services/agent_serialization_manager.py
index 047fd3321..f279bab03 100644
--- a/letta/services/agent_serialization_manager.py
+++ b/letta/services/agent_serialization_manager.py
@@ -434,6 +434,7 @@ class AgentSerializationManager:
dry_run: bool = False,
env_vars: Optional[Dict[str, Any]] = None,
override_embedding_config: Optional[EmbeddingConfig] = None,
+ project_id: Optional[str] = None,
) -> ImportResult:
"""
Import AgentFileSchema into the database.
@@ -649,6 +650,10 @@ class AgentSerializationManager:
for var in agent_data["tool_exec_environment_variables"]:
var["value"] = env_vars.get(var["key"], "")
+ # Override project_id if provided
+ if project_id:
+ agent_data["project_id"] = project_id
+
agent_create = CreateAgent(**agent_data)
created_agent = await self.agent_manager.create_agent_async(agent_create, actor, _init_with_no_messages=True)
file_to_db_ids[agent_schema.id] = created_agent.id