<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def create_agent(self, configuration, agent_id=""):
 """Create an agent. :param dict configuration: Form given by the craftai documentation. :param str agent_id: Optional. The id of the agent to create. It must be an str containing only characters in "a-zA-Z0-9_-" and must be between 1 and 36 characters. :default agent_id: "", the agent_id is generated. :return: agent created. :rtype: dict. :raise CraftAiBadRequestError: if the input is not of the right form. """

    # Extra header in addition to the main session's
    ct_header = {"Content-Type": "application/json; charset=utf-8"}

    # Building payload and checking that it is valid for a JSON
    # serialization
    payload = {"configuration": configuration}

    if agent_id != "":
      # Raises an error when agent_id is invalid
      self._check_agent_id(agent_id)

      payload["id"] = agent_id

    try:
      json_pl = json.dumps(payload)
    except TypeError as err:
      raise CraftAiBadRequestError("Invalid configuration or agent id given. {}"
                                   .format(err.__str__()))

    req_url = "{}/agents".format(self._base_url)
    resp = self._requests_session.post(req_url, headers=ct_header, data=json_pl)

    agent = self._decode_response(resp)

    return agent