code: @RequirePOST
      public synchronized void doCreateItem( StaplerRequest req, StaplerResponse rsp,
                                             @QueryParameter String name, @QueryParameter String mode,
                                             @QueryParameter String from ) throws IOException, ServletException {
          final Jenkins app = Jenkins.getInstance();
          app.checkPermission(Computer.CREATE);
  
          if(mode!=null && mode.equals("copy")) {
              name = checkName(name);
  
              Node src = app.getNode(from);
              if(src==null) {
                  if (Util.fixEmpty(from) == null) {
                      throw new Failure(Messages.ComputerSet_SpecifySlaveToCopy());
                  } else {
                      throw new Failure(Messages.ComputerSet_NoSuchSlave(from));
                  }
              }
  
              // copy through XStream
              String xml = Jenkins.XSTREAM.toXML(src);
              Node result = (Node) Jenkins.XSTREAM.fromXML(xml);
              result.setNodeName(name);
              if(result instanceof Slave){ //change userId too
                  User user = User.current();
                  ((Slave)result).setUserId(user==null ? "anonymous" : user.getId());
               }
              result.holdOffLaunchUntilSave = true;
  
              app.addNode(result);
  
              // send the browser to the config page
              rsp.sendRedirect2(result.getNodeName()+"/configure");
          } else {
              // proceed to step 2
              if (mode == null) {
                  throw new Failure("No mode given");
              }
  
              NodeDescriptor d = NodeDescriptor.all().findByName(mode);
              if (d == null) {
                  throw new Failure("No node type ‘" + mode + "’ is known");
              }
              d.handleNewNodePage(this,name,req,rsp);
          }
      }
docs: First check point in creating a new agent.