r/learnpython • • Oct 16 '26

How should I separate LLM interpretation from memory operations in my Python project?

I've been working on a small Python project that uses an LLM to interpret natural language instructions and manage persistent memories. Right now, it supports remembering, retrieving, updating and forgetting information.

I've been trying to improve the separation between model interpretation and memory operations. I'm still new to Python but I'm interested how I could structure the code better. Feedbacks are appreciated and any flaws I might be overlooking.

GitHub repo: https://github.com/Lionshaft-pixel/ennoic

8 Upvotes

7 comments sorted by

View all comments

3

u/Equivalent_Type6726 Oct 17 '26

For the memory side, give the four operations their own interface. Make a small Memory class with remember, retrieve, update, and forget methods, and keep the LLM calling out to it instead of touching storage directly. You can even swap backends later (a dict for dev, a sqlite database for prod) by just replacing that one class. On the LLM side, build a thin Interpreter that takes raw input, calls the model, turns the response into a structured decision like which memory action to run, and hands it to Memory. That keeps interpretation and storage cleanly separated and makes both sides easy to test on their own. A quick type like a MemoryEntry with a key, content, and timestamp also helps a lot when you start retrieving and updating.

1

u/Friendly_Rope_5688 Oct 17 '26

Thanks for the feedback. I still don't really know much about software architecture so I don't fully understand memory class and interpretation separation yet. So, would it be good idea to create memory class first while keeping my LLM logic same?

2

u/Equivalent_Type6726 Oct 19 '26

yeah that's a good order. build the memory class on its own first with simple save/get/search methods, keep your llm code as is, then just swap the llm code to call the memory class instead of touching storage directly.