Self-awareness

Consciousness and self-awareness. They affect our behavior. But how do you technically recognize yourself in data?
I see a system as conscious if it saves and extracts data in real time. If you stop all data flows, the consciousness goes away. Complex systems may have many data channels connected to their memory. We can see different levels of consciousness, depending on which set of channels is active at the moment.
If you have a memory, a bunch of sensors, and data channels to connect everything, you may start to react to things in a structured manner. On the lower levels of evolution, where random mutations affect everything, we would expect to see all sorts of odd reactions. They don't have to make any logical sense to us. Natural selection will take care of them.
If your system is functionally independent from other things, it would be very convenient to mark sensors or channels as internal or external. You get that mutation, sooner or later.
These are simple binary flags. It definitely works on the level of bacteria. They don't necessarily have enough brains to understand what they're doing in detail, but they collect data and use it to guide their behavior in the environment.
At this moment your system is aware of the fact that there is you and there is an environment. And it's not the same. This is the most primal version of self-awareness that you can get.
You would probably say that this is far from our human self-awareness. Yes. But we add more internal sensors and connect data channels in loops. This is where the real magic begins.
You may observe data extraction from your memory. Now you're aware that you're aware. You can clearly see your selfies being used. Some people would probably argue that this is where you get the "real" consciousness and self-awareness.
If you have intelligence and work with rules, you may observe their creation. You make your own decisions! This data comes from your internal channels. It's yours! It's your will! Philosophers may call this an illusion, in the sense that this will is not free from prior causes, but it's a functional part of the system anyway. You won't be a human without it.
New sensors. More loops. More data. More rules. More bizarre effects. Eventually you pass the mirror test. But. It's not a functional self-awareness test. It's an IQ test. It's not enough to distinguish yourself from the environment. That's easy. You need to work with Euclidean relations in your data to pass the mirror test. We have to be aware of that.