From f37e0ea5224013317dd24e0607eef572ce4d3086 Mon Sep 17 00:00:00 2001 From: Josh XT Date: Tue, 14 Jan 2025 12:07:55 -0500 Subject: [PATCH] add agent if not exists --- agixt/Agent.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/agixt/Agent.py b/agixt/Agent.py index 48216db44791..a9f06ca98fe0 100644 --- a/agixt/Agent.py +++ b/agixt/Agent.py @@ -481,9 +481,25 @@ def get_agent_config(self): ) .first() ) - self.agent_id = str(agent.id) if agent else None if not agent: - raise HTTPException(status_code=404, detail="Agent not found.") + agent = ( + session.query(AgentModel) + .filter(AgentModel.user_id == self.user_id) + .first() + ) + if not agent: + # Create an agent. + add_agent(agent_name=self.agent_name, user=self.user) + # Get the agent + agent = ( + session.query(AgentModel) + .filter( + AgentModel.name == self.agent_name, + AgentModel.user_id == self.user_id, + ) + .first() + ) + self.agent_id = str(agent.id) if agent else None config = {"settings": {}, "commands": {}} if agent: all_commands = session.query(Command).all()