-
Notifications
You must be signed in to change notification settings - Fork 1k
first proposal for a memory module in mesa #2735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Performance benchmarks:
|
Thanks for your PR!
|
I need some time to make up my mind about this. I do appreciate the well-thought-out and clear API. However, I also have some questions
|
@quaquel, thank you for the quick answer
I don't really get your question, are you referring to code complexity or performance overhead ? If you meant in terms of performance, can you tell my how I can verify this ?
I originally chose ordered dict over the plain dict because there were pre-implemented functionalities such as
Alright, I didn't really know where to put it at first, I'll move it at my next commit.
It would indeed be quite handy to have a deque for this but I'm not sure if its compatible with the memory_storage structure that I've implemented... Do you have improvement ideas for it ? If you have any other suggestions regarding the global idea or a specific aspect of the feature, I'd love to discuss it ! |
|
Thanks again for working on this! I have two comments, one on conceptual level, and one on an implementation level. 1. Use case / valueFirst of all, I love the extensive example models. However, I don't immediately see how much code would be saved here, compared to implementing something like this yourself in a model. I feel the main advantage is the automatic Could you give a few examples of use cases in which this approach saves a significant amount of code or enables new behavior compared to just storing things agents need to remember in their attributes directly? Like Using Lists as Stacks? I just want to prevent building a complete module if that functionality is already there in plain Python. 2. Memory efficiencyI already mentioned it in my video call, but I think the current storage way is very inefficient. I'm not an expert on this, but I did a bit of LLM brainstorming, which led to options I think are viable:
Ideally you would do some benchmarks comparing the memory size and write and read performance of different memory structures. Of course that has to be weighted against code complexity and the user API. Totally out of scope, but it might also be good to keep in mind what we want to do with that memory once we have it. We might consider extending the memory module's capabilities beyond simple storage and retrieval to include built-in analytical functions. This could involve features like calculating recency-weighted values for specific entry types (e.g., using exponential decay based on entry timestamps) to give more importance to recent information, or performing basic trend estimation (e.g., using linear regression over a recent window of numerical entries) to determine if values are increasing or decreasing. To allow such features, we might want to (optionally) support recording timestamps when a memory value was added. |
Thanks a lot for this detailed answer @EwoutH ! I've actually worked quite a bit on a new prototype of a memory module based on :
After quite a lot of prototyping, I've started the code for an upgrade of the memory module corresponding to this architecture. This is starting to be a consequential code (about 300 lines) so I will double-check it and push it as a commit on the PR rather than just in a comment. Here is what the architecture could look like : I had already upgraded the entry to a Meanwhile, I'll try to be back with more usecases and some statistics for the performance as well as the code. PS : all the methods for the different classes that I have coded here aren't necessarily definitive, I'd love hear what you think about them ! |
In this approach, does long-term memory simply have infinite capacity compared to a fixed amount of short term memory? |
That's what I envisioned, but I'm open to discussion ! There is a |
Maintenance and codebase wise it might be beneficial to keep them as similar as possible - or even just one class - with |
Thanks for pinging me on this one! It really helps in these times where I am less active on mesa, even though it now took me some time to respond here. Honestly, at the moment I think this is a nice thing to have for some specific models, but I am not sure about the general usefulness. Conceptually I find it difficult to determine what agent information should be stored in a simple attribute and what should be "memory". Also the concept of "memory sharing" sounds a bit strange to me, but the topic of communication between Agents is something I think we haven't really approached in a standard way. So this is an interesting discussion pathway. Also, it seems you are developing the memory feature further, which is great to see and I am looking forward to how this evolves |
Thank you for your feedback @Corvince !
According to me, it could be useful for very basic learning patterns, to name a few :
I'm also trying to think a bit about the LLM approach, where memory is necessary. Might as well build it as something that all agents can use. Or do you think it's too much ?
I see this as "communicating in general is just a way to make a memory of something (like a sentence) and transmitting it to another being". I understand it's unusual, but if the memory module works well, it could mean opening agent communication without building other complex modules. I'd really like to hear you opinion on this ! I'm also working on an upgrade of the memory to make it a little more useful and powerful. I should push it tonight or in the next few days. |
Add agent memory module for storing and retrieving information
**PR is closed - New architecture for memory in #2744 !
Summary
This PR introduces a new Memory module that enables agents to store, recall, and share information during simulations. The mesa user may need memory for a wide range of different usages. Taking this in consideration, I made the memory very flexible and able to store different types of information (cf. memory structure).
Overall, this memory system provides a simple but useful way to add memory capabilities to any Mesa agent with minimal implementation overhead.
Key features
Basic features
Extra features - the value of this memory module is here
Memory structure
After studying different data structures (plain dict, building my own structure, etc.) I chose to use an
OrderedDict
that have roughly the same complexity as a plain dict, but with features relative to its ordering (pop and related).Example of a structure for my_agent.memory.memory_structure :
Example usage
I created a whole working model (the foraging ants model) using this memory feature, feel free to explore it (and don't hesitate to give me feedbacks)
I would love to have your feedbacks on this proposal !
Update : Next steps
I came across a paper on LLM based agents detailing the possible configuration for memory structures in this case. I am going to experiment around this to see if we can make a general memory structure (not only around LLMs) with these elements.