Thread memory for AI agents
Project description
threadmem
Chat thread memory for AI agents
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
ThreadMem is a simple tool that helps manage chat conversations with language models.
Installation
pip install threadmem
Usage
Role Threads
Role based threads are useful for managing openai-style chat schemas.
from threadmem import RoleThread
# Create a thread storing it in a local sqlite db
thread = RoleThread(owner_id="dolores@agentsea.ai")
# Post messages
thread.post("user", "Hello, Thread!")
thread.post("assistant", "How can I help?")
thread.post("user", "Whats this image?", images=["data:image/jpeg;base64,..."])
# Output in openai chat schema format
print(thread.to_oai())
# Find a thread
threads = RoleThread.find(owner_id="dolores@agentsea.ai")
# Delete a thread
threads[0].delete()
Add images of any variety to the thread. We support base64, filepath, PIL, and URL:
from PIL import Image
img1 = Image.open("img1.png")
thread.post(
role="user",
msg="Whats this image?",
images=["data:image/jpeg;base64,...", "./img1.png", img1, "https://shorturl.at/rVyAS"]
)
Integrations
Threadmem is integrated into:
- MLLM - A prompt management, routing, and schema validation library for multimodal LLMs.
- Taskara - A task management library for AI agents.
- Skillpacks - A library to fine tune AI agents on tasks.
- SurfKit - A platform for AI agents.
Community
Come join us on Discord.
Backends
Thread and prompt storage can be backed by:
- Sqlite
- Postgresql
Sqlite will be used by default. To use postgres simply configure the env vars:
DB_TYPE=postgres
DB_NAME=threads
DB_HOST=localhost
DB_USER=postgres
DB_PASS=abc123
Image storage by default will utilize the db, to configure bucket storage using GCS:
- Create a bucket with fine grained permissions
- Create a GCP service account JSON with permissions to write to the bucket
export THREAD_STORAGE_SA_JSON='{
"type": "service_account",
...
}'
export THREAD_STORAGE_BUCKET=my-bucket
Develop
To test
make test
To publish
make publish
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for threadmem-0.2.33-py3-none-any.whl
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 | 1fea4dada42ad8ecb2b982d159bcc4f293b630fb9e74d9a1689332809f1cc3dc |
|
| MD5 | 12563b0261a6f611db23c068b15bc2cf |
|
| BLAKE2b-256 | b611e2574ddf3594d5981c00b04dd8825ca6edf4b1e4e2e7b4a9caa9a2100d2a |