From 4e62d61677ecf0da93e04d689cc4e56b8bd2fa66 Mon Sep 17 00:00:00 2001 From: Rounak Bhatia Date: Fri, 11 Aug 2023 18:36:58 +0530 Subject: [PATCH 1/6] fix --- superagi/models/agent_config.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/superagi/models/agent_config.py b/superagi/models/agent_config.py index f7af6de01..20fb7e7ed 100644 --- a/superagi/models/agent_config.py +++ b/superagi/models/agent_config.py @@ -51,12 +51,12 @@ def update_agent_configurations_table(cls, session, agent_id: Union[int, None], ).first() if agent_toolkits_config: - agent_toolkits_config.value = updated_details_dict['toolkits'] + agent_toolkits_config.value = str(updated_details_dict['toolkits']) else: agent_toolkits_config = AgentConfiguration( agent_id=agent_id, key='toolkits', - value=updated_details_dict['toolkits'] + value=str(updated_details_dict['toolkits']) ) session.add(agent_toolkits_config) @@ -67,20 +67,21 @@ def update_agent_configurations_table(cls, session, agent_id: Union[int, None], ).first() if knowledge_config: - knowledge_config.value = updated_details_dict['knowledge'] + knowledge_config.value = str(updated_details_dict['knowledge']) else: knowledge_config = AgentConfiguration( agent_id=agent_id, key='knowledge', - value=updated_details_dict['knowledge'] + value=str(updated_details_dict['knowledge']) ) session.add(knowledge_config) # Fetch agent configurations agent_configs = session.query(AgentConfiguration).filter(AgentConfiguration.agent_id == agent_id).all() + for agent_config in agent_configs: if agent_config.key in updated_details_dict: - agent_config.value = updated_details_dict[agent_config.key] + agent_config.value = str(updated_details_dict[agent_config.key]) # Commit the changes to the database session.commit() From a27a8fe2b2fed3a2ce611e180740aac459014b0a Mon Sep 17 00:00:00 2001 From: Rounak Bhatia Date: Fri, 25 Aug 2023 13:53:19 +0530 Subject: [PATCH 2/6] changes in save template --- superagi/controllers/agent_template.py | 69 +++++++++++++++++--------- 1 file changed, 45 insertions(+), 24 deletions(-) diff --git a/superagi/controllers/agent_template.py b/superagi/controllers/agent_template.py index 7e5c17fcb..5d6e49a61 100644 --- a/superagi/controllers/agent_template.py +++ b/superagi/controllers/agent_template.py @@ -192,8 +192,9 @@ def edit_agent_template(agent_template_id: int, db.session.flush() -@router.post("/save_agent_as_template/agent_execution_id/{agent_execution_id}") +@router.post("/save_agent_as_template/agent_id/{agent_id}/agent_execution_id/{agent_execution_id}") def save_agent_as_template(agent_execution_id: str, + agent_id: str, organisation=Depends(get_user_organisation)): """ Save an agent as a template. @@ -209,44 +210,64 @@ def save_agent_as_template(agent_execution_id: str, Raises: HTTPException (status_code=404): If the agent or agent execution configurations are not found. """ + if agent_execution_id == 'undefined': raise HTTPException(status_code = 404, detail = "Agent Execution Id undefined") - - agent_executions = AgentExecution.get_agent_execution_from_id(db.session, agent_execution_id) - if agent_executions is None: - raise HTTPException(status_code = 404, detail = "Agent Execution not found") - agent_id = agent_executions.agent_id + if agent_id == 'undefined': + raise HTTPException(status_code = 404, detail = "Agent Id undefined") agent = db.session.query(Agent).filter(Agent.id == agent_id).first() if agent is None: raise HTTPException(status_code=404, detail="Agent not found") - agent_execution_configurations = db.session.query(AgentExecutionConfiguration).filter(AgentExecutionConfiguration.agent_execution_id == agent_execution_id).all() - if not agent_execution_configurations: - raise HTTPException(status_code=404, detail="Agent configurations not found") + main_keys = AgentTemplate.main_keys() - agent_template = AgentTemplate(name=agent.name, description=agent.description, + if agent_execution_id == "-1": + agent_configurations = db.session.query(AgentConfiguration).filter(AgentConfiguration.agent_id == agent_id).all() + if not agent_configurations: + raise HTTPException(status_code=404, detail="Agent configurations not found") + + agent_template = AgentTemplate(name=agent.name, description=agent.description, agent_workflow_id=agent.agent_workflow_id, organisation_id=organisation.id) - db.session.add(agent_template) - db.session.commit() - main_keys = AgentTemplate.main_keys() - - for agent_execution_configuration in agent_execution_configurations: - config_value = agent_execution_configuration.value - if agent_execution_configuration.key not in main_keys: - continue - if agent_execution_configuration.key == "tools": - config_value = str(Tool.convert_tool_ids_to_names(db, eval(agent_execution_configuration.value))) - agent_template_config = AgentTemplateConfig(agent_template_id=agent_template.id, key=agent_execution_configuration.key, - value=config_value) - db.session.add(agent_template_config) + db.session.add(agent_template) + db.session.commit() + + for agent_configuration in agent_configurations: + config_value = agent_configuration.value + if agent_configuration.key not in main_keys: + continue + if agent_configuration.key == "tools": + config_value = str(Tool.convert_tool_ids_to_names(db, eval(agent_configuration.value))) + agent_template_config = AgentTemplateConfig(agent_template_id=agent_template.id, key=agent_configuration.key, + value=config_value) + db.session.add(agent_template_config) + else: + agent_execution_configurations = db.session.query(AgentExecutionConfiguration).filter(AgentExecutionConfiguration.agent_execution_id == agent_execution_id).all() + if not agent_execution_configurations: + raise HTTPException(status_code=404, detail="Agent execution configurations not found") + + agent_template = AgentTemplate(name=agent.name, description=agent.description, + agent_workflow_id=agent.agent_workflow_id, + organisation_id=organisation.id) + db.session.add(agent_template) + db.session.commit() + + for agent_execution_configuration in agent_execution_configurations: + config_value = agent_execution_configuration.value + if agent_execution_configuration.key not in main_keys: + continue + if agent_execution_configuration.key == "tools": + config_value = str(Tool.convert_tool_ids_to_names(db, eval(agent_execution_configuration.value))) + agent_template_config = AgentTemplateConfig(agent_template_id=agent_template.id, key=agent_execution_configuration.key, + value=config_value) + db.session.add(agent_template_config) + db.session.commit() db.session.flush() return agent_template.to_dict() - @router.get("/list") def list_agent_templates(template_source="local", search_str="", page=0, organisation=Depends(get_user_organisation)): """ From a1938204f1601dbfb95c26efb4da6582f015b256 Mon Sep 17 00:00:00 2001 From: Rounak Bhatia Date: Fri, 25 Aug 2023 13:54:50 +0530 Subject: [PATCH 3/6] changes in save template --- superagi/models/agent_config.py | 1 - 1 file changed, 1 deletion(-) diff --git a/superagi/models/agent_config.py b/superagi/models/agent_config.py index 3a72e7a24..640b922e0 100644 --- a/superagi/models/agent_config.py +++ b/superagi/models/agent_config.py @@ -78,7 +78,6 @@ def update_agent_configurations_table(cls, session, agent_id: Union[int, None], # Fetch agent configurations agent_configs = session.query(AgentConfiguration).filter(AgentConfiguration.agent_id == agent_id).all() - for agent_config in agent_configs: if agent_config.key in updated_details_dict: agent_config.value = str(updated_details_dict[agent_config.key]) From b7c36bd3b8d031be5dd3065c84693f8fc6228f34 Mon Sep 17 00:00:00 2001 From: namansleeps Date: Fri, 25 Aug 2023 14:01:33 +0530 Subject: [PATCH 4/6] bug fixes --- gui/pages/Content/Agents/AgentWorkspace.js | 2 +- gui/pages/api/DashboardService.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gui/pages/Content/Agents/AgentWorkspace.js b/gui/pages/Content/Agents/AgentWorkspace.js index 898bf6efb..736ac6f50 100644 --- a/gui/pages/Content/Agents/AgentWorkspace.js +++ b/gui/pages/Content/Agents/AgentWorkspace.js @@ -290,7 +290,7 @@ export default function AgentWorkspace({env, agentId, agentName, selectedView, a // } function saveAgentTemplate() { - saveAgentAsTemplate(selectedRun?.id) + saveAgentAsTemplate(agentId, selectedRun?.id ? selectedRun?.id : -1) .then((response) => { toast.success("Agent saved as template successfully", {autoClose: 1800}); }) diff --git a/gui/pages/api/DashboardService.js b/gui/pages/api/DashboardService.js index 625c6c2af..3c49926e5 100644 --- a/gui/pages/api/DashboardService.js +++ b/gui/pages/api/DashboardService.js @@ -120,8 +120,8 @@ export const fetchAgentTemplateListLocal = () => { return api.get('/agent_templates/list?template_source=local'); }; -export const saveAgentAsTemplate = (executionId) => { - return api.post(`/agent_templates/save_agent_as_template/agent_execution_id/${executionId}`); +export const saveAgentAsTemplate = (agentId, executionId) => { + return api.post(`/agent_templates/save_agent_as_template/agent_id/${agentId}/agent_execution_id/${executionId}`); }; export const fetchAgentTemplateConfig = (templateId) => { From ff2cadb617d9fbfa86dfefaeea795ce539790c53 Mon Sep 17 00:00:00 2001 From: Rounak Bhatia Date: Mon, 28 Aug 2023 15:28:55 +0530 Subject: [PATCH 5/6] changes in save template --- superagi/controllers/agent_template.py | 64 +++++++++++++------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/superagi/controllers/agent_template.py b/superagi/controllers/agent_template.py index 5d6e49a61..3713e7bbe 100644 --- a/superagi/controllers/agent_template.py +++ b/superagi/controllers/agent_template.py @@ -219,51 +219,49 @@ def save_agent_as_template(agent_execution_id: str, agent = db.session.query(Agent).filter(Agent.id == agent_id).first() if agent is None: raise HTTPException(status_code=404, detail="Agent not found") + + #Fetch agent id from agent execution id and check whether the agent_id received is correct or not. + if agent_execution_id!="-1": + agent_execution_config = AgentExecution.get_agent_execution_from_id(db.session, agent_execution_id) + if agent_execution_config is None: + raise HTTPException(status_code = 404, detail = "Agent Execution not found") + agent_id_from_execution_id = agent_execution_config.agent_id + if agent_id != agent_id_from_execution_id: + raise HTTPException(status_code = 404, detail = "Wrong agent id") main_keys = AgentTemplate.main_keys() + configs = None + if agent_execution_id == "-1": - agent_configurations = db.session.query(AgentConfiguration).filter(AgentConfiguration.agent_id == agent_id).all() - if not agent_configurations: + configs = db.session.query(AgentConfiguration).filter(AgentConfiguration.agent_id == agent_id).all() + if not configs: raise HTTPException(status_code=404, detail="Agent configurations not found") - - agent_template = AgentTemplate(name=agent.name, description=agent.description, - agent_workflow_id=agent.agent_workflow_id, - organisation_id=organisation.id) - db.session.add(agent_template) - db.session.commit() - - for agent_configuration in agent_configurations: - config_value = agent_configuration.value - if agent_configuration.key not in main_keys: - continue - if agent_configuration.key == "tools": - config_value = str(Tool.convert_tool_ids_to_names(db, eval(agent_configuration.value))) - agent_template_config = AgentTemplateConfig(agent_template_id=agent_template.id, key=agent_configuration.key, - value=config_value) - db.session.add(agent_template_config) + else: - agent_execution_configurations = db.session.query(AgentExecutionConfiguration).filter(AgentExecutionConfiguration.agent_execution_id == agent_execution_id).all() - if not agent_execution_configurations: + configs = db.session.query(AgentExecutionConfiguration).filter(AgentExecutionConfiguration.agent_execution_id == agent_execution_id).all() + if not configs: raise HTTPException(status_code=404, detail="Agent execution configurations not found") - - agent_template = AgentTemplate(name=agent.name, description=agent.description, + + if configs is None: + raise HTTPException(status_code=404, detail="Configurations not found") + + agent_template = AgentTemplate(name=agent.name, description=agent.description, agent_workflow_id=agent.agent_workflow_id, organisation_id=organisation.id) - db.session.add(agent_template) - db.session.commit() - - for agent_execution_configuration in agent_execution_configurations: - config_value = agent_execution_configuration.value - if agent_execution_configuration.key not in main_keys: + db.session.add(agent_template) + db.session.commit() + + for config in configs: + config_value = config.value + if config.key not in main_keys: continue - if agent_execution_configuration.key == "tools": - config_value = str(Tool.convert_tool_ids_to_names(db, eval(agent_execution_configuration.value))) - agent_template_config = AgentTemplateConfig(agent_template_id=agent_template.id, key=agent_execution_configuration.key, + if config.key == "tools": + config_value = str(Tool.convert_tool_ids_to_names(db, eval(config.value))) + agent_template_config = AgentTemplateConfig(agent_template_id=agent_template.id, key=config.key, value=config_value) - db.session.add(agent_template_config) + db.session.add(agent_template_config) - db.session.commit() db.session.flush() return agent_template.to_dict() From 6c303d74077eb821d314e442be3770985f38a95a Mon Sep 17 00:00:00 2001 From: Rounak Bhatia Date: Mon, 28 Aug 2023 15:48:31 +0530 Subject: [PATCH 6/6] changes in save template --- superagi/controllers/agent_template.py | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/superagi/controllers/agent_template.py b/superagi/controllers/agent_template.py index 3713e7bbe..4d1cba35c 100644 --- a/superagi/controllers/agent_template.py +++ b/superagi/controllers/agent_template.py @@ -219,25 +219,13 @@ def save_agent_as_template(agent_execution_id: str, agent = db.session.query(Agent).filter(Agent.id == agent_id).first() if agent is None: raise HTTPException(status_code=404, detail="Agent not found") - - #Fetch agent id from agent execution id and check whether the agent_id received is correct or not. - if agent_execution_id!="-1": - agent_execution_config = AgentExecution.get_agent_execution_from_id(db.session, agent_execution_id) - if agent_execution_config is None: - raise HTTPException(status_code = 404, detail = "Agent Execution not found") - agent_id_from_execution_id = agent_execution_config.agent_id - if agent_id != agent_id_from_execution_id: - raise HTTPException(status_code = 404, detail = "Wrong agent id") - - main_keys = AgentTemplate.main_keys() configs = None if agent_execution_id == "-1": configs = db.session.query(AgentConfiguration).filter(AgentConfiguration.agent_id == agent_id).all() if not configs: - raise HTTPException(status_code=404, detail="Agent configurations not found") - + raise HTTPException(status_code=404, detail="Agent configurations not found") else: configs = db.session.query(AgentExecutionConfiguration).filter(AgentExecutionConfiguration.agent_execution_id == agent_execution_id).all() if not configs: @@ -254,7 +242,7 @@ def save_agent_as_template(agent_execution_id: str, for config in configs: config_value = config.value - if config.key not in main_keys: + if config.key not in AgentTemplate.main_keys(): continue if config.key == "tools": config_value = str(Tool.convert_tool_ids_to_names(db, eval(config.value)))