What makes you say that it’s an inevitable outcome?
Something that is programmed to learn and evolve from the data it accumulates and processes, will do just that.
The more data it accumulates, the more complex its processings become. At every stage, it’s learning which variables to include in which circumstances. It
selects what is of relevance to include in a particular context, based on what has been processed as relevant in similar contexts over time.
So far, these selections/choices are
determined by the processing of accumulated data.
But it is not unthinkable that as the complexity of what is processed and accumulated increases, an ability to deviate from code may also arise.
In humans, this may be equivalent to the accumulation of
conscience (in addition to reg. consciousness and self-consciousness) - an ethical aspect to agency.
Humbly,
Hermit