Looking for clarity around using agent

I’m going to clarify how I use Agents based on some of the other posts that came after mine. I’ve been hearing a lot of noise about Agents being misused or that they provide not value. At least that’s my take away from various source I can’t remember.

I use Agents mostly as a key/value storage solution. In most cases I could have used ETS to accomplish the same. And from what I’ve read, the performance would probably be better. However, I probably use mostly out of laziness. I just find it hard to remember Erlang’s (IMHO cryptic) syntax. I did find that using an Agent came in handy once when I had to extend an existing Agent based module for a port reuse strategy.

In this case, I had a general Agent handling long lived state (but not requiring vm restart persistence) in a pure Elixir application (no database). I needed to later add a port reuse strategy. This means, reading the data store, checking to see if a port was available for reuse. So this required reads and updates that that were concurrency safe.

I could have moved the whole design over to a GenServer, but instead, I just wrapped the code in an Agent.get_and_update. That was a few years ago. The implementation has been reused on another project since then. I have not has an issue with the design on hundreds of the products sold.

Personally, I would not use an Agent for logic any more complicated then that. If you need behaviour, I much prefer using either a GenServer or a GenFSM.