How a minimal learning agent can infer the existence of unobserved variables in a complex environment