class_docstr: Handles CRUD operations at the database level for Agents
class_docstr_tok: ["Handles","CRUD","operations","at","the","database","level","for","Agents"]
docstr: Updates an agent in the database.
  
  Parameters:
      agent_name (str): The name of the new agent, or existing agent to update
      project_name (str): The containing project
      name (str): The updated name of the agent
      model_name (str): The name of the existing ML model the agent will use
      skills_to_add (List[str]): List of skill names to add to the agent
      skills_to_remove (List[str]): List of skill names to remove from the agent
      params: (Dict[str, str]): Parameters to use when running the agent
  
  Returns:
      agent (db.Agents): The created or updated agent
  
  Raises:
      ValueError: Agent with name not found, agent with new name already exists, or model/skill does not exist.
docstr_tok: ["Updates","an","agent","in","the","database",".","Parameters",":","agent_name","(","str",")",":","The","name","of","the","new","agent",",","or","existing","agent","to","update","project_name","(","str",")",":","The","containing","project","name","(","str",")",":","The","updated","name","of","the","agent","model_name","(","str",")",":","The","name","of","the","existing","ML","model","the","agent","will","use","skills_to_add","(","List","[","str","]",")",":","List","of","skill","names","to","add","to","the","agent","skills_to_remove","(","List","[","str","]",")",":","List","of","skill","names","to","remove","from","the","agent","params",":","(","Dict","[","str",",","str","]",")",":","Parameters","to","use","when","running","the","agent","Returns",":","agent","(","db.Agents",")",":","The","created","or","updated","agent","Raises",":","ValueError",":","Agent","with","name","not","found",",","agent","with","new","name","already","exists",",","or","model\/skill","does","not","exist","."]
code: def update_agent(
      self,
      agent_name: str,
      project_name: str = "mindsdb",
      name: str = None,
      model_name: str = None,
      skills_to_add: List[str] = None,
      skills_to_remove: List[str] = None,
      params: Dict[str, str] = None,
  ):
      """
      Updates an agent in the database.
  
      Parameters:
          agent_name (str): The name of the new agent, or existing agent to update
          project_name (str): The containing project
          name (str): The updated name of the agent
          model_name (str): The name of the existing ML model the agent will use
          skills_to_add (List[str]): List of skill names to add to the agent
          skills_to_remove (List[str]): List of skill names to remove from the agent
          params: (Dict[str, str]): Parameters to use when running the agent
  
      Returns:
          agent (db.Agents): The created or updated agent
  
      Raises:
          ValueError: Agent with name not found, agent with new name already exists, or model/skill does not exist.
      """
  
      existing_agent = self.get_agent(
          agent_name, project_name=project_name
      )
      if existing_agent is None:
          raise ValueError(f"Agent with name not found: {agent_name}")
  
      if name is not None and name != agent_name:
          # Check to see if updated name already exists
          agent_with_new_name = self.get_agent(
              name, project_name=project_name
          )
          if agent_with_new_name is not None:
              raise ValueError(
                  f"Agent with updated name already exists: {name}"
              )
  
      # Check if model exists.
      if model_name is not None:
          model_controller = ModelController()
          (
              model_name_no_version,
              model_version,
          ) = Predictor.get_name_and_version(model_name)
          try:
              _ = model_controller.get_model(
                  model_name_no_version,
                  version=model_version,
                  project_name=project_name,
              )
              existing_agent.model_name = model_name
          except PredictorRecordNotFound:
              return ValueError(
                  f"Model with name does not exist: {model_name}"
              )
  
      # Check if given skills exist.
      new_skills = []
      for skill in skills_to_add:
          existing_skill = self.skills_controller.get_skill(
              skill, project_name
          )
          if existing_skill is None:
              raise ValueError(
                  f"Skill with name does not exist: {skill}"
              )
          new_skills.append(existing_skill)
      existing_agent.skills += new_skills
  
      removed_skills = []
      for skill in existing_agent.skills:
          if skill.name in skills_to_remove:
              removed_skills.append(skill)
      for skill_to_remove in removed_skills:
          existing_agent.skills.remove(skill_to_remove)
  
      if params is not None:
          # Merge params on update
          existing_params = existing_agent.params or {}
          existing_params.update(params)
          # Remove None values entirely.
          params = {
              k: v for k, v in existing_params.items() if v is not None
          }
          existing_agent.params = params
          # Some versions of SQL Alchemy won't handle JSON updates correctly without this.
          # See: https://docs.sqlalchemy.org/en/20/orm/session_api.html#sqlalchemy.orm.attributes.flag_modified
          flag_modified(existing_agent, "params")
      db.session.commit()
  
      return existing_agent
  
file_path: mindsdb/mindsdb/interfaces/agents/agents_controller.py
imports: from typing import Dict, List
  from mindsdb.interfaces.model.functions import PredictorRecordNotFound
  from mindsdb.interfaces.storage.db import Predictor
  from mindsdb.interfaces.model.model_controller import ModelController
  from mindsdb.interfaces.skills.skills_controller import SkillsController
  from mindsdb.interfaces.storage import db
  from mindsdb.interfaces.database.projects import ProjectController
  from mindsdb.utilities.context import context
  from mindsdb.utilities.config import Config
  from sqlalchemy.orm.attributes import flag_modified
label_desc: Use image node_id 6 for calling the AgentsController obj's underlying member method code with example usage: obj.update_agent(agent_name, project_name, name, model_name, skills_to_add, skills_to_remove, params) and returns: existing_agent, ValueError