From e0c79002d98a1b7c6a08f2fd02c5eb5abdec955c Mon Sep 17 00:00:00 2001 From: cthomas Date: Tue, 26 Aug 2025 14:53:27 -0700 Subject: [PATCH] feat: change env vars to json string [PRO-1061] (#4216) feat: change env vars to json string --- letta/server/rest_api/routers/v1/agents.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/letta/server/rest_api/routers/v1/agents.py b/letta/server/rest_api/routers/v1/agents.py index d849ba9a..0e2f2607 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):