There is currently no way to store state easily in the session across PSQL-blocks other than through storing it in an in-memory or other table.
A good example is shown in Easily determine changed values in custom data-integration triggers with synchronize.
In the future, the package concept might be extended to allow defining your own packages. In that case, there might be variables available to store data in from outside the package or through a function in the package, just like with the dbms_output
package.