feat: change env vars to json string [PRO-1061] (#4216)

feat: change env vars to json string
This commit is contained in:
cthomas
2025-08-26 14:53:27 -07:00
committed by GitHub
parent cae23cbdd5
commit e0c79002d9

View File

@@ -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):