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: change env vars to json string [PRO-1061] (#4216)

cthomase0c79002d98a
diff --git a/letta/server/rest_api/routers/v1/agents.py b/letta/server/rest_api/routers/v1/agents.py
index d849ba9a8..0e2f2607e 100644
--- a/letta/server/rest_api/routers/v1/agents.py
+++ b/letta/server/rest_api/routers/v1/agents.py
@@ -301,7 +301,9 @@ async def import_agent_serialized(
False,
description="If set to True, strips all messages from the agent before importing.",
),
- env_vars: Optional[Dict[str, Any]] = Form(None, description="Environment variables to pass to the agent for tool execution."),
+ env_vars_json: Optional[str] = Form(
+ None, description="Environment variables as a JSON string to pass to the agent for tool execution."
+ ),
):
"""
Import a serialized agent file and recreate the agent(s) in the system.
@@ -315,6 +317,17 @@ async def import_agent_serialized(
except json.JSONDecodeError:
raise HTTPException(status_code=400, detail="Corrupted agent file format.")
+ # Parse env_vars_json if provided
+ env_vars = None
+ if env_vars_json:
+ try:
+ env_vars = json.loads(env_vars_json)
+ except json.JSONDecodeError:
+ raise HTTPException(status_code=400, detail="env_vars_json must be a valid JSON string")
+
+ if not isinstance(env_vars, dict):
+ raise HTTPException(status_code=400, detail="env_vars_json must be a valid JSON string")
+
# 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):