twagents is a framework for building and comparing language model agents with different memory architectures in interactive, text-based environments. It is designed to work with TextWorld and focuses on exploring how working, episodic, and semantic memory influence agent behavior, recall, and decision-making.
Rather than relying solely on fixed context windows, twagents introduces structured memory components that support selective recall, strategic planning, and long-term knowledge accumulation.
- Memory: Working memory only (recent state context).
- Behavior: Acts based solely on the most recent game output.
- Use Case: Serves as a minimal memory-free baseline.
- Memory: Episodic memory (vector store of past observations).
- Behavior: Uses similarity-based recall to recover earlier steps.
- Use Case: Tests recall-based planning over time.
- Memory: Episodic + Semantic memory with tool-assisted recall.
- Behavior: Uses dedicated memory tools in a ReAct-style loop to retrieve structured past knowledge and facts.
- Use Case: Models higher-level cognitive memory usage and flexible reasoning.
.
āāā config.py # Global settings and constants
āāā requirements.txt # Required Python packages
āāā logs/ # Game logs and trace data per agent
ā
āāā src/
ā āāā agents/ # Agent definitions and control loops
ā āāā memory/ # Memory storage and retrieval logic
ā āāā game/ # TextWorld interaction wrapper
ā āāā tools/ # Memory and environment tools callable by agents
ā āāā utils/ # Utility functions and formatting
ā
āāā notebooks/ # Notebooks for running agents and analysis
ā āāā baseline_runner.ipynb
ā āāā retrieval_runner.ipynb
ā āāā langmem_runner.ipynb
ā āāā analysis.ipynb
git clone https://github.com/kelbudiul/twagents.git
cd twagentspython -m venv venv source venv/bin/activate # or venv\Scripts\activate on Windows
pip install -r requirements.txt
Create a .env file in the root directory (or set variables manually) with the following:
OPENAI_API_KEY=your_openai_api_key
LANGCHAIN_API_KEY=your_langchain_api_key
LANGCHAIN_PROJECT=twagents
LANGSMITH_API_KEY=your_langsmith_api_key
These are required for interacting with language models and logging tools (e.g., LangSmith).
| Memory Type | Purpose | Used By |
|---|---|---|
| Working Memory | Short-term buffer of recent steps | All agents |
| Episodic Memory | Chronological trace of past interactions | Retrieval, LangMem |
| Semantic Memory | General facts, object properties, and affordances | LangMem |
- Study the role of structured memory in language agent behavior.
- Benchmark agents on memory-intensive tasks in controlled environments.
- Build reusable components for long-term LLM reasoning architectures.
For questions, suggestions, or contributions, please open an issue or submit a pull request.