How to access state variable in Custom Tool in Flowise

I am trying to get the value of a variable that is stored in the state node. In the custom tool, I have the following JavaScript:

return `The value stored in the state is ${$flow.state.value}`;

The state is properly defined and has value in it.

Can someone tell me what I am doing wrong?