On the notion of set equality. I should start by providing some context. I want to understand the foundations of mathematics and in doing so have been looking at different texts involving ZF set theory and category theory. I understand that set theory takes the view that every mathematical object is to be described as a set. I don't have a problem with that, but I've seen in the past that when others (usually as new to the subject as me) try to ask questions on the foundations of set theory and look for alternatives to doing mathematics, the questions are often met with a response of the form 'why would one want to get rid of set theory?'. That's not my intention. I just want to see if there are precise descriptions of terms like 'object', 'rule' and 'equality' outside of it that one can talk about rigorously without using sets to define them. 
I'm currently looking at the notions of equality in set theory. We define sets to be equal when they have the same elements. 
Basically, we can say that $A = B$ if and only if for every $x \in A$ we have $x \in B$ and for every $x \in B$ we have $x \in A$. 
Now we are using $x$ as a symbol representing arbitrary elements of $A$ and $B$, so suppose that the definition holds true and $A$ and $B$ are equal but using set notation we have $A = \{a, b, c\}$ and $B =\{d,e,f\}$. In order for you to be able to say that $A$ and $B$ are equal, you have to be able to provide some means through which you can say things like $a = d$. In other words, it seems to me that you need rules which say the objects themselves are equal prior to being able to define notions of set equality. 
It seems to me that if you say, $a$ and $d$ are sets, then you can continue asking about how equality is defined for the elements of $a$ and $d$ indefinitely until you run into some kind of object that isn't a set or the empty set.  
My question therefore is this: do we have a way of talking about mathematics that deals with 'rules' on 'mathematical objects' directly in order to define some form of equality? And can such a way of talking about mathematics be used at the foundations in a rigorous way alongside the notion of sets? For a simple example, maybe the rule is addition and the objects are numbers. Only in the context of such a rule can we say the set $\{2 + 2, 3 + 4\}$ is equal to the set $\{4,7\}$. However, without such a rule, they must be treated as different sets. The idea of numbers and addition being sets themselves doesn't have to be removed, but I would rather treat them as 'examples' of objects with a 'number-like' property and an 'addition-like' property that has been defined prior to constructing them with sets. 
 A: Usually, equality is assumed to exist already at the level of logic. Therefore the axiom of equality does not define the equality of sets, but it says that no two sets can have the same elements.
It's like when you say that different natural numbers have different prime factorizations. You don't define equality of natural numbers by their prime factorization, you just describe the fact that different natural numbers with the same prime factorization do not exist.
The only difference is that for natural numbers it is a property that you prove from the axioms, while for sets it is an axiom.
Said differently: The axiom does not say “if two sets have equal elements, we call them equal”, it says “There are no two different sets with the same elements.”
A: Any object is equal to itself, and only it can be equal to itself.  That's just how it is.
OK, you say, but what about the case where $a=d$?
Well, that just indicates that we use two different labels for the same one object. 
OK, you say, but how would we know that $a=d$? Shouldn't we have a definition that spells out what equality_of_elements is before we can say that the-element-referred-to-by-$a$ is equal to the-element-referred-to-by-$d$?
No, we don't have such a definition. Equality is assumed. And there are no definitions that explicitly refer to the-way-we-refer-to-objects-using-different-labels. And finally, the fact that you would not know that $a=d$ is simply about just that: you just don't know. But it is still true. What you know and what is true is not the same thing.
But wait, you say, we aren't defining equality .. and yet we are defining equality of sets?! What gives?
Ah, well that is an interesting observation! Interestingly, there are 2 schools of thought on set equality.
Using the extensional view, two sets are said to be equal if and only if they contain the same elements. This is the typical way mathematicians look at set equality. As such, if $a=d$, $b=e$, and $c=f$, then $A = \{ a,b,c \} = \{d,e,f \} = B$. And again, just because we use two different labels $A$ and $B$ for these sets, does nt mean that the sets are different. In fact, if you know that $a=d$, $b=e$, and $c=f$, then you now also know that $A = B$. But even if you didn't know that, it would still be true.
OK, but there is also an intensional view on sets. This view says that sets are not solely defined in terms of their contents. We often informally think of sets as bags. So: think of two different 'bags', that happen to contain the same elements. On the extensional view, the two bags/sets must in fact be thew same one bag, but on the intensional view, they could still be different bags: while the contents are the same, the containers themselves are different.  Why might one hold such a weird view?  Well, here are two arguments for making such a move:


*

*Consider the 'set of all people alive'. Clearly the contents of this set is going to change from day to day as people are dying or getting born. So ... everytime this happens, are we dealing with a different set?  The extensional view says yes. The intensional view says: no, it is still the same container .. but its content changes.  This mirrors a problem in philosophy of mind: are you still the same person when you lose a hair ro some cell in your body dies? You clearly went through a change ... and yet we also want to say that you are still the same person. In fact, the very notion of change only makes sense if there is the same one thing that goes through a change: the alternative is to say that things go in and out of existence every millisecond. Indeed, on the extensional view, you can't add elements to a set, because as soon as you do, you are dealing with a different set. The intensional view, however, will say that it is useful for to be able to think of adding things to a set just as we can add new things to a bag. Indeed, if we want to apply set theory to real life, where 'collections' do regularly change, then we may opt for a definition that can handle sets changing their contents.

*As a continuation of the first point: Say I have a group of people in front of me, and I define two sets: the set of all people whose favorite sandwich is Peanut butter Jelly, and the set of all people born on a Tuesday. Now, it could of course so happen that these two sets completely coincide in terms of their contents. But this would be a fluke, of course. In fact, a new person (whose favorite sandwich is PBJ, but is born on a Wednesday) could walk in at any moment, and at that point the two sets will diverge. But the intensional view will say that the two sets were different the whole time: I was collecting different 'kinds' of things.
Anyway, to wrap up: on the intensional view, when we define 'set-equality' in terms of 'having the same elements', the intensional view says that that is not about 'equality of sets', but merely about 'equality of contents'. As such, even equality of sets is not defined, and hence any perceived inconsistency between 'we never define equality in math' vs 'we do define equality for sets' is resolved.
But even on the extensional view, you can regard the 'equality of sets' principle not as a definition, but rather as a truthful axiom: it is not that we define what makes two sets identical, but rather that it is simply true that identity of sets corresponds to identity of their elements.
A: 
Only in the context of such a rule can we say the set {2+2,3+4} is
  equal to the set {4,7}

It is true that if we were working with basic objects as primary elements, we would need an equality rule/ criterion specially for these objects. And this rule should precede the statement of the equality rule for sets. 
But, in ZF set theory , any object is supposed to be itself a set. 
So, we do not need a further rule to  state that $2+2$ and $4$ are identical. We use the same rule for the identity of sets $A$ and $B$ and for the elements of $A$ and $B$, namely, the extensionnality principle 
I mean that, $2+2$ and $4$ are set themselves, and the rule you will use to show that they are identical is the extensionnality axiom. 
Using the construction of natural numbers and the definition of addition in terms of successor , you will end up with 
$2+2= 2+S(1)=S(2+1)=S(3)= 3\cup \{3\} =\{0,1,2,3\}$
You also have, by definiton : $4=S(3) = \{0,1,2,3\}$. 
The extensionnality axiom tells you that the two sets are identical. 

I think your question is based on a couple of false assumptions regarding the universal quantifier and the meaning of the definiton of set equality. Maybe pointing out these assumptions could bring some clarification. 


' Basically, we can say that $A=B$ if and only if for every $x\in A$ we have
  $x \in B$  and for every $x\in B$ we have $x\in A$ 
Now we are using $x$ as a symbol representing arbitrary elements of $A$
  and $B$'

In the definition of set equality , more precisely in the " for all (x) " part, x is not supposed to stand for an element of A or of B. The variable $x$ stands for any object whatever. 
Consider this example. $A = \{1,2\}$ and $B = \{1,2,3\}$. 
It is true that $\forall(x)\space ( x\in A \rightarrow x\in B)$. 

The reason it is true for all $x$ is that it is true, not only for all $x$
  belonging to $A$ but also for all $x$ not belonging to $A$.

Consider the case , say,  $x=5$. In that case $x\in A$ is false. So the conditional $x\in A \rightarrow x\in B$ is true for $x=5$ ( since its antecedent is false). And the same thing holds for any object not belonging to $A$. It would even be true for , say $x=$ The Eiffel Tower. 

'In order for you to be able to say that $A$ and $B$ are equal, you have to
  be able to provide some means through which you can say things like
  $a=d$'.

It is true that informally we define set identity in terms of having identical elements. But in fact, technically, identity of elements is not used in the definition of set equality. Rather, it is expressed in terms of reciprocal inclusion, which , itself, in analyzed in terms of conditionned membership. 
If set equality required identity of elements, no equality statement would hold for the empty set. 
