From e56d54c3f0236c4c327e481b481ca44816729198 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 6 May 2025 10:59:25 +0100 Subject: [PATCH] fix: improve source and description handling in GetAgent and GetAgents responses --- application/api/user/routes.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/application/api/user/routes.py b/application/api/user/routes.py index 3b3cb21f..bacc8bb7 100644 --- a/application/api/user/routes.py +++ b/application/api/user/routes.py @@ -997,12 +997,8 @@ class GetAgent(Resource): data = { "id": str(agent["_id"]), "name": agent["name"], - "description": agent["description"], - "source": ( - str(db.dereference(agent["source"])["_id"]) - if "source" in agent and isinstance(agent["source"], DBRef) - else "" - ), + "description": agent.get("description", ""), + "source": (str(source_doc["_id"]) if isinstance(agent.get("source"), DBRef) and (source_doc := db.dereference(agent.get("source"))) else ""), "chunks": agent["chunks"], "retriever": agent.get("retriever", ""), "prompt_id": agent["prompt_id"], @@ -1035,12 +1031,8 @@ class GetAgents(Resource): { "id": str(agent["_id"]), "name": agent["name"], - "description": agent["description"], - "source": ( - str(db.dereference(agent["source"])["_id"]) - if "source" in agent and isinstance(agent["source"], DBRef) - else "" - ), + "description": agent.get("description", ""), + "source": (str(source_doc["_id"]) if isinstance(agent.get("source"), DBRef) and (source_doc := db.dereference(agent.get("source"))) else ""), "chunks": agent["chunks"], "retriever": agent.get("retriever", ""), "prompt_id": agent["prompt_id"],