class_docstr: Handles CRUD operations at the database level for Agents
class_docstr_tok: ["Handles","CRUD","operations","at","the","database","level","for","Agents"]
docstr: Adds an agent to the database.
  
  Parameters:
      name (str): The name of the new agent
      project_name (str): The containing project
      model_name (str): The name of the existing ML model the agent will use
      skills (List[str]): List of existing skill names to add to the new agent
      params (Dict[str, str]): Parameters to use when running the agent
  
  Returns:
      agent (db.Agents): The created agent
  
  Raises:
      ValueError: Agent with given name already exists, or skill/model with given name does not exist.
      NotImplementedError: Free users try to create an agent.
docstr_tok: ["Adds","an","agent","to","the","database",".","Parameters",":","name","(","str",")",":","The","name","of","the","new","agent","project_name","(","str",")",":","The","containing","project","model_name","(","str",")",":","The","name","of","the","existing","ML","model","the","agent","will","use","skills","(","List","[","str","]",")",":","List","of","existing","skill","names","to","add","to","the","new","agent","params","(","Dict","[","str",",","str","]",")",":","Parameters","to","use","when","running","the","agent","Returns",":","agent","(","db.Agents",")",":","The","created","agent","Raises",":","ValueError",":","Agent","with","given","name","already","exists",",","or","skill\/model","with","given","name","does","not","exist",".","NotImplementedError",":","Free","users","try","to","create","an","agent","."]
code: def add_agent(
      self,
      name: str,
      project_name: str,
      model_name: str,
      skills: List[str],
      params: Dict[str, str] = {},
  ) -> db.Agents:
      """
      Adds an agent to the database.
  
      Parameters:
          name (str): The name of the new agent
          project_name (str): The containing project
          model_name (str): The name of the existing ML model the agent will use
          skills (List[str]): List of existing skill names to add to the new agent
          params (Dict[str, str]): Parameters to use when running the agent
  
      Returns:
          agent (db.Agents): The created agent
  
      Raises:
          ValueError: Agent with given name already exists, or skill/model with given name does not exist.
          NotImplementedError: Free users try to create an agent.
      """
  
      config = Config()
  
      is_cloud = config.get("cloud", False)
      if is_cloud and ctx.user_class == 0:
          raise NotImplementedError(
              "Free users cannot create agents. Please subscribe to MindsDB Pro."
          )
  
      if project_name is None:
          project_name = "mindsdb"
      project = self.project_controller.get(name=project_name)
  
      agent = self.get_agent(name, project_name)
  
      if agent is not None:
          raise ValueError(f"Agent with name already exists: {name}")
  
      # Check if model exists.
      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,
          )
      except PredictorRecordNotFound:
          raise ValueError(
              f"Model with name does not exist: {model_name}"
          )
  
      agent = db.Agents(
          name=name,
          project_id=project.id,
          company_id=ctx.company_id,
          user_class=ctx.user_class,
          model_name=model_name,
          params=params,
      )
      skills_to_add = []
      # Check if given skills exist.
      for skill in skills:
          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}"
              )
          skills_to_add.append(existing_skill)
      agent.skills = skills_to_add
  
      db.session.add(agent)
      db.session.commit()
  
      return 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 5 for calling the AgentsController obj's underlying member method code with example usage: obj.add_agent(name, project_name, model_name, skills, params) and returns: agent