docstr: Updates a agent by name, creating one if it doesn't exist
docstr_tok: ["Updates","a","agent","by","name",",","creating","one","if","it","does","n't","exist"]
code: def put(self, project_name, agent_name):
      """Updates a agent by name, creating one if it doesn't exist"""
  
      # Check for required parameters.
      if "agent" not in request.json:
          return http_error(
              HTTPStatus.BAD_REQUEST,
              "Missing parameter",
              'Must provide "agent" parameter in POST body',
          )
      agents_controller = AgentsController()
  
      try:
          existing_agent = agents_controller.get_agent(
              agent_name, project_name=project_name
          )
      except ValueError:
          # Project must exist.
          return http_error(
              HTTPStatus.NOT_FOUND,
              "Project not found",
              f"Project with name {project_name} does not exist",
          )
  
      agent = request.json["agent"]
      name = agent.get("name", None)
      model_name = agent.get("model_name", None)
      skills_to_add = agent.get("skills_to_add", [])
      skills_to_remove = agent.get("skills_to_remove", [])
      params = agent.get("params", None)
  
      # Model needs to exist.
      if model_name is not None:
          session_controller = SessionController()
          (
              model_name_no_version,
              version,
          ) = Predictor.get_name_and_version(model_name)
          try:
              session_controller.model_controller.get_model(
                  model_name_no_version,
                  version=version,
                  project_name=project_name,
              )
          except PredictorRecordNotFound:
              return http_error(
                  HTTPStatus.NOT_FOUND,
                  "Model not found",
                  f"Model with name {model_name} not found",
              )
  
      # Agent must not exist with new name.
      if name is not None and name != agent_name:
          agent_with_new_name = agents_controller.get_agent(
              name, project_name=project_name
          )
          if agent_with_new_name is not None:
              return http_error(
                  HTTPStatus.CONFLICT,
                  "Agent already exists",
                  f"Agent with name {name} already exists. Please choose a different one.",
              )
  
      if existing_agent is None:
          # Create
          return create_agent(project_name, name, agent)
  
      # Update
      try:
          updated_agent = agents_controller.update_agent(
              agent_name,
              project_name=project_name,
              name=name,
              model_name=model_name,
              skills_to_add=skills_to_add,
              skills_to_remove=skills_to_remove,
              params=params,
          )
          return updated_agent.as_dict()
      except ValueError as e:
          # Model or skill doesn't exist.
          return http_error(
              HTTPStatus.NOT_FOUND, "Resource not found", str(e)
          )
  
file_path: mindsdb/mindsdb/api/http/namespaces/agents.py
imports: from http import HTTPStatus
  from flask import request
  from flask_restx import Resource
  from mindsdb.api.http.namespaces.configs.projects import ns_conf
  from mindsdb.api.executor.controllers.session_controller import SessionController
  from mindsdb.api.http.utils import http_error
  from mindsdb.interfaces.agents.agents_controller import AgentsController
  from mindsdb.interfaces.model.functions import PredictorRecordNotFound
  from mindsdb.interfaces.storage.db import Predictor
label_desc: Use image node_id 2 for calling the AgentResource obj's underlying member method code with example usage: obj.put(project_name, agent_name) and returns: http_error, create_agent, updated_agent, http_error, http_error, http_error, http_error