Skip to main content

A text memory meant to be used with conversational language models.

Project description

GoodAI-LTM

GoodAI-LTM equips agents with text-based long-term memory by combining essential components such as

text embedding models, reranking, vector databases, memory and query rewriting, automatic chunking,

chunk metadata, and chunk expansion. This package is specifically designed to offer a dialog-centric

memory stream for social agents.

Additionally, GoodAI-LTM includes a conversational agent component (LTMAgent) for seamless

integration into Python-based apps.

Installation

pip install goodai-ltm

Usage of LTMAgent

Call the reply method of an LTMAgent instance to get a response from the agent.

from goodai.ltm.agent import LTMAgent



agent = LTMAgent(model="gpt-3.5-turbo")

response = agent.reply("What can you tell me about yourself?")

print(response)

The model parameter can be the name of any model supported by the litellm library.

A session history is maintained automatically by the agent. If you want to start a

new session, call the new_session method.

agent.new_session()

print(f"Number of messages in session: {len(agent.session.message_history)}")    

The agent has a conversational memory and also a knowledge base. You can tell the agent

to store knowledge by invoking the add_knowledge method.

agent.clear_knowledge()

agent.add_knowledge("The user's birthday is February 10.")

agent.add_knowledge("Refer to the user as 'boss'.")

response = agent.reply("Today is February 10. I think this is an important date. Can you remind me?")

print(response)

LTMAgent is a seamless RAG system. The ltm_agent_with_wiki example

shows how to add Wikipedia articles to the agent's knowledge base.

You can persist the agent's configuration and its memories/knowledge by obtaining

its state as a string via the state_as_text method.

state_text = agent.state_as_text()

# Persist state_text to secondary storage

To build an agent from state text, call the from_state_text method.

agent2 = LTMAgent.from_state_text(state_text)

Note that this does not restore the conversation session. The persist the conversation session

call the state_as_text method of the session.

from goodai.ltm.agent import LTMAgentSession



session_state_text = agent.session.state_as_text()

# session_state_text can be persisted in secondary storage

# The session.session_id field can serve as an identifier of the persisted session

# Now let's restore the session in agent2

p_session = LTMAgentSession.from_state_text(session_state_text)

agent2.use_session(p_session)

Additional information

Visit the Github page: https://github.com/GoodAI/goodai-ltm

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

goodai-ltm-0.4.2.tar.gz (143.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

goodai_ltm-0.4.2-py3-none-any.whl (169.9 kB view details)

Uploaded Python 3

File details

Details for the file goodai-ltm-0.4.2.tar.gz.

File metadata

  • Download URL: goodai-ltm-0.4.2.tar.gz
  • Upload date:
  • Size: 143.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for goodai-ltm-0.4.2.tar.gz
Algorithm Hash digest
SHA256 2014d7ddd155ded622eb6de163af8aecf1e59ac6d960514f88e215d824e631f2
MD5 44258f128328c32473c24ea8cddc179e
BLAKE2b-256 d585970f4c851b71ec77b6b61fa9ce49048e60657c8fc08a20fdc304057e37ba

See more details on using hashes here.

File details

Details for the file goodai_ltm-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: goodai_ltm-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 169.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for goodai_ltm-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9378ffd0a13601b073e16cc1ed8e3bf013313b3ea9f43358a6f32d0005c3bec8
MD5 34b8d6382b38214295d53c358b17e5ec
BLAKE2b-256 3fa4cc382e6072182501ca5d77a7e9386d3e3f8cea69994d118fbaca983e82bd

See more details on using hashes here.

Supported by

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