Tesla agreed to pay up to $2 billion to buy an AI hardware business.