I believe you just pass objects instead, like you would in OOP, and take the hit of pickling and unpickling them every time.
If you really want to pass lambdas, you can use a third party library to pickle them
https://github.com/cloudpipe/cloudpickle
Yes, this is not great.
I mean a situation like where in threaded context there would be code like:
..without needing to provide a protocol that covers each possible scenario the client might wish to execute in the process?I believe the answer is "you don't", but passing functions in messages is a highly convenient way to structure code in a way that local decisions can stay local, instead of being interspersed around the codebase.