Most definitions of the conditional expectation use $\sigma$-algebra arguments:
Let $X$ be a random variable on a probability space $(E, \mathcal{E}, \mathbb{P})$ with $\mathbb{E}| X|\le\infty$ and $\mathcal{E}^\prime$ be sub-$\sigma$-algebra w.r.t. $\mathcal{E}$, the conditional expectation $\mathbb{E}\big[X| \mathcal{E}^\prime\big]$ is any random variable $Y$ on $\mathcal{E}^\prime$ such that for all $A\in\mathcal{E}^\prime$, $\int_{A} Xd\mathbb{P}=\int_{A} Yd\mathbb{P}$.
But I also encounter conditional expectations of two random variables $X$ and $Y$ which are simply like $\mathbb{E}[X|Y]$. Most of the time $X$ is a function of $Y$ (and another random variable). What is the formal definition of this version?
My personal definition is:
Given a random variables $X$ on $(E, \mathcal{E}, \mathbb{P})$ and another random variable $Y$ on $(E, \mathcal{E}^\prime, \mathbb{P})$ with $\mathcal{E}^\prime\subseteq\mathcal{E}$, the conditional expectation $\mathbb{E}[X|Y]$ is any random variable $Z$ on $(E, \sigma(Y), \mathbb{P})$ such that for all $A\in\sigma(Y)$, $\int_{A} Xd\mathbb{P}=\int_{A} Zd\mathbb{P}$.
$\sigma(Y)$ is the $\sigma$-algebra generated by $Y$. Is this correct?
Conditioning on $\sigma$-algebra or on random variable (or rather the $\sigma$-algebra generated by the random variable) amounts to the same thing. This is because any sub-$\sigma$-algebra is generated by a random variable (by random variable I mean measurable function).
Suppose $(\Omega,\mathscr{F},\mu)$ is a probability space, and let $\mathcal{A}$ a $\sigma$-algebra contained $\mathscr{F}$, and $X:(\Omega,\mathscr{F})\rightarrow(\mathbb{R},\mathcal{B}(\mathbb{R}))$ a numeric random variable. Define the function $Y:\Omega\rightarrow\Omega$ as $Y(\omega)=\omega$. Notice that $Y$ is a $(\Omega,\mathscr{F})$-$(\Omega,\mathcal{A})$ random variable for if $A\in\mathcal{A}$, $Y^{-1}(A)=A\in\mathcal{A}\subset\mathscr{F}$, furthermore, $\sigma(Y)=\{Y^{-1}(A):A\in\mathcal{A}\}=\mathcal{A}$. Hence $$\mathbb{E}[X|Y]:=\mathbb{E}[X|\sigma(Y)]=\mathbb{E}[X|\mathcal{A}]$$