This is a simple implementation of a Recursive Language Model (RLM) in JavaScript using Bun. It was inspired by Arjun's Own Implementation In Python
Feel free to use, modify, and improve this code as you see fit. This was made mostly for learning
Create a .env file with the following content:
API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
BASE_API=https://api.openai.com/v1
To install dependencies:
bun installTo run:
bun run src/index.ts- This implementation uses Bun instead of Python
- I prefer to use simple functions instead of classes so that was my preference
- On his implementation the LLM pretty much called an
eval, on the main thread. Instead I let the code run on a separate worker usingnew Worker. You can probably improve it by letting the LLM call on a separate process instead, offering even more isolation. - Also I don't use
eval, i opted fornew Functioninstead. So i can control the sandbox environment the SubLLM is iterating on without worrying to much if it'll leak my secrets.
The RLM framework is a significant architectural shift that reframes the problem of long-context processing from a hardware/architectural challenge to a software/algorithmic one. It suggests that the solution to "infinite context" lies not just in bigger context windows, but in teaching models how to manage and interact with information programmatically. Researchers suggest that explicitly training models to operate within this recursive framework could unlock even greater potential.