Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

markdown

tess-memory-hook

A lightweight memory cleanup module triggered by "hook + threshold" for AI Agent systems.

Automatically consolidates short conversations when the number of dialog files exceeds a set threshold.


Features

  • 🔌 Hook-based trigger – check and clean with one method call
  • ⚙️ Threshold configurable – default 50, adjustable
  • 🧠 LLM-powered extraction – uses DeepSeek API to extract and merge memories
  • 💾 Pluggable storage – JSON by default, can be replaced with custom backend
  • 📦 Zero hardcoded paths – cross-platform ready (Windows / macOS / Linux)

Installation

pip install requests python-dotenv
Or copy tess_memory_hook.py into your project.

Quick Start
1. Create a .env file
text
DEEPSEEK_API_KEY=sk-your-deepseek-api-key-here
2. Use it
python
from tess_memory_hook import MemoryHook

hook = MemoryHook(
    short_dir="./short_dialogs",
    threshold=10,
    memory_file="./memory.json",
    api_key="your-api-key"  # or use env var
)

result = hook.run()
print(result)
3. Expected output
python
{
    "status": "triggered",
    "reason": "整理完成",
    "file_count": 3,
    "memories_count": 3,
    "deleted_count": 3
}
Configuration
Parameter	Type	Default	Description
short_dir	str	required	Directory containing short dialog .md files
threshold	int	50	Number of files to trigger cleanup
memory_file	str	"memory.json"	Path to memory storage file
api_key	str	required	DeepSeek API key (or set via .env)
Customization
Use a different LLM
python
from tess_memory_hook import MemoryHook, BaseLLM

class MyLLM(BaseLLM):
    def call(self, prompt: str, max_tokens: int = 2000) -> str:
        # Your own LLM implementation
        return "..."

hook = MemoryHook(short_dir="./dialogs", llm=MyLLM())
Use a different storage backend
python
from tess_memory_hook import MemoryHook, BaseStorage

class MyStorage(BaseStorage):
    def read_memories(self):
        # ...
    def write_memories(self, memories):
        # ...
    # ... implement all abstract methods

hook = MemoryHook(short_dir="./dialogs", storage=MyStorage())
Cross-Platform Support
All paths use os.path.join() – works on:

✅ Windows

✅ macOS

✅ Linux

Requirements
Python 3.10+

requests

python-dotenv

License
MIT © 2026

Author
Maintained by [CCR-WER]

text

---

About

A lightweight memory cleanup module triggered by "hook + threshold" for AI Agent systems, automatically consolidating short conversations.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages