Skip to main content

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

Metadata

Release files for threadmem 0.2.39

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for threadmem 0.2.39
File Size Uploaded
threadmem-0.2.39.tar.gz 24.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for threadmem 0.2.39
File Interpreter ABI Platform
threadmem-0.2.39-py3-none-any.whl Python 3 none any Details

Total release size: 52.3 kB

Release files / threadmem-0.2.39.tar.gz

Download URL threadmem-0.2.39.tar.gz
Size 24.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c6bb30c24e27456ce3498d330550cf3ab02b5c33e2a58747d86200213e659f17
BLAKE2b-256 checksum
How to use checksums
f49801e1b6b4be23059578b6788093412b16994959f056221d3f86ae0737f9d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.9 Darwin/23.4.0

Release files / threadmem-0.2.39-py3-none-any.whl

Download URL threadmem-0.2.39-py3-none-any.whl
Size 27.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8e51f16de07cc86499b1f50dae7aeee1f9faa90be82af991531b5c5c5f3ea64d
BLAKE2b-256 checksum
How to use checksums
b10e863cb2e1b447e08e6e6bf6c96aeff1d253785d1a88ca956d8a909153187e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.9 Darwin/23.4.0

Release history Release notifications | RSS feed

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page