Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

threadmem-0.2.31.tar.gz (23.9 kB view details)

Uploaded Source

Built Distribution

threadmem-0.2.31-py3-none-any.whl (27.4 kB view details)

Uploaded Python 3

File details

Details for the file threadmem-0.2.31.tar.gz.

File metadata

  • Download URL: threadmem-0.2.31.tar.gz
  • Upload date:
  • Size: 23.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Darwin/23.4.0

File hashes

Hashes for threadmem-0.2.31.tar.gz
Algorithm Hash digest
SHA256 9ece3eb1890759505f028162cc9615efe62f663f172d79c58e3c56d95faed6d4
MD5 47c7e67af736a201954e06b613b7474c
BLAKE2b-256 c291736f98efcb3a07a0ccc1717608c5c1f9a4a2f6985480912936767c29209f

See more details on using hashes here.

File details

Details for the file threadmem-0.2.31-py3-none-any.whl.

File metadata

  • Download URL: threadmem-0.2.31-py3-none-any.whl
  • Upload date:
  • Size: 27.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Darwin/23.4.0

File hashes

Hashes for threadmem-0.2.31-py3-none-any.whl
Algorithm Hash digest
SHA256 3955fa9923de40d3e636e8ec9cee264e0d82b44d84a00364d978de44b0d9d3b8
MD5 d408703eb4c3971bd0620c03e7a98cc9
BLAKE2b-256 6b8a7ca64568da2cfd4cba512b788eb48eef1ceb8a15b5f7c16dba807680b17a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page