The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
docstrings `memory` (#8018)
Leonid Ganeline120cdf813de1
diff --git a/libs/langchain/langchain/memory/__init__.py b/libs/langchain/langchain/memory/__init__.pyindex 4c28f61814..de669b4778 100644--- a/libs/langchain/langchain/memory/__init__.py+++ b/libs/langchain/langchain/memory/__init__.py@@ -1,3 +1,4 @@+"""Memory maintains Chain state, incorporating context from past runs."""from langchain.memory.buffer import (ConversationBufferMemory,ConversationStringBufferMemory,diff --git a/libs/langchain/langchain/memory/buffer_window.py b/libs/langchain/langchain/memory/buffer_window.pyindex 34d70f59d3..af27f41d33 100644--- a/libs/langchain/langchain/memory/buffer_window.py+++ b/libs/langchain/langchain/memory/buffer_window.py@@ -5,12 +5,13 @@ from langchain.schema.messages import BaseMessage, get_buffer_stringclass ConversationBufferWindowMemory(BaseChatMemory):- """Buffer for storing conversation memory."""+ """Buffer for storing conversation memory inside a limited size window."""human_prefix: str = "Human"ai_prefix: str = "AI"memory_key: str = "history" #: :meta private:k: int = 5+ """Number of messages to store in buffer."""@propertydef buffer(self) -> List[BaseMessage]:diff --git a/libs/langchain/langchain/memory/chat_memory.py b/libs/langchain/langchain/memory/chat_memory.pyindex 767f68d908..e322c6ddb2 100644--- a/libs/langchain/langchain/memory/chat_memory.py+++ b/libs/langchain/langchain/memory/chat_memory.py@@ -9,6 +9,8 @@ from langchain.schema import BaseChatMessageHistory, BaseMemoryclass BaseChatMemory(BaseMemory, ABC):+ """Abstract base class for chat memory."""+chat_memory: BaseChatMessageHistory = Field(default_factory=ChatMessageHistory)output_key: Optional[str] = Noneinput_key: Optional[str] = Nonediff --git a/libs/langchain/langchain/memory/chat_message_histories/cosmos_db.py b/libs/langchain/langchain/memory/chat_message_histories/cosmos_db.pyindex e1e5ad3261..819599e351 100644--- a/libs/langchain/langchain/memory/chat_message_histories/cosmos_db.py+++ b/libs/langchain/langchain/memory/chat_message_histories/cosmos_db.py@@ -17,7 +17,7 @@ if TYPE_CHECKING:class CosmosDBChatMessageHistory(BaseChatMessageHistory):- """Chat history backed by Azure CosmosDB."""+ """Chat message history backed by Azure CosmosDB."""def __init__(self,diff --git a/libs/langchain/langchain/memory/chat_message_histories/dynamodb.py b/libs/langchain/langchain/memory/chat_message_histories/dynamodb.pyindex 219ca9844a..3800017516 100644--- a/libs/langchain/langchain/memory/chat_message_histories/dynamodb.py+++ b/libs/langchain/langchain/memory/chat_message_histories/dynamodb.py@@ -16,6 +16,7 @@ logger = logging.getLogger(__name__)class DynamoDBChatMessageHistory(BaseChatMessageHistory):"""Chat message history that stores history in AWS DynamoDB.+This class expects that a DynamoDB table with name `table_name`and a partition Key of `SessionId` is present.diff --git a/libs/langchain/langchain/memory/chat_message_histories/firestore.py b/libs/langchain/langchain/memory/chat_message_histories/firestore.pyindex fdfb4e5669..9e20a9ba96 100644--- a/libs/langchain/langchain/memory/chat_message_histories/firestore.py+++ b/libs/langchain/langchain/memory/chat_message_histories/firestore.py@@ -16,7 +16,7 @@ if TYPE_CHECKING:class FirestoreChatMessageHistory(BaseChatMessageHistory):- """Chat history backed by Google Firestore."""+ """Chat message history backed by Google Firestore."""def __init__(self,diff --git a/libs/langchain/langchain/memory/chat_message_histories/momento.py b/libs/langchain/langchain/memory/chat_message_histories/momento.pyindex 5fefc790ef..448801db81 100644--- a/libs/langchain/langchain/memory/chat_message_histories/momento.py+++ b/libs/langchain/langchain/memory/chat_message_histories/momento.py@@ -36,6 +36,7 @@ def _ensure_cache_exists(cache_client: momento.CacheClient, cache_name: str) ->class MomentoChatMessageHistory(BaseChatMessageHistory):"""Chat message history cache that uses Momento as a backend.+See https://gomomento.com/"""def __init__(diff --git a/libs/langchain/langchain/memory/chat_message_histories/sql.py b/libs/langchain/langchain/memory/chat_message_histories/sql.pyindex 85baf037e5..43fedd531d 100644--- a/libs/langchain/langchain/memory/chat_message_histories/sql.py+++ b/libs/langchain/langchain/memory/chat_message_histories/sql.py@@ -21,6 +21,7 @@ logger = logging.getLogger(__name__)def create_message_model(table_name, DynamicBase): # type: ignore"""Create a message model for a given table name.+Args:table_name: The name of the table to use.DynamicBase: The base class to use for the model.diff --git a/libs/langchain/langchain/memory/chat_message_histories/zep.py b/libs/langchain/langchain/memory/chat_message_histories/zep.pyindex e468369ac8..30983677bd 100644--- a/libs/langchain/langchain/memory/chat_message_histories/zep.py+++ b/libs/langchain/langchain/memory/chat_message_histories/zep.py@@ -20,7 +20,7 @@ logger = logging.getLogger(__name__)class ZepChatMessageHistory(BaseChatMessageHistory):- """A ChatMessageHistory implementation that uses Zep as a backend.+ """Chat message history that uses Zep as a backend.Recommended usage::diff --git a/libs/langchain/langchain/memory/combined.py b/libs/langchain/langchain/memory/combined.pyindex a5cc1d4057..1c46c184d4 100644--- a/libs/langchain/langchain/memory/combined.py+++ b/libs/langchain/langchain/memory/combined.py@@ -8,7 +8,7 @@ from langchain.schema import BaseMemoryclass CombinedMemory(BaseMemory):- """Class for combining multiple memories' data together."""+ """Combining multiple memories' data together."""memories: List[BaseMemory]"""For tracking all the memories that should be accessed."""diff --git a/libs/langchain/langchain/memory/entity.py b/libs/langchain/langchain/memory/entity.pyindex 68be77a8dd..54b9574b0d 100644--- a/libs/langchain/langchain/memory/entity.py+++ b/libs/langchain/langchain/memory/entity.py@@ -21,6 +21,8 @@ logger = logging.getLogger(__name__)class BaseEntityStore(BaseModel, ABC):+ """Abstract base class for Entity store."""+@abstractmethoddef get(self, key: str, default: Optional[str] = None) -> Optional[str]:"""Get entity value from store."""@@ -48,7 +50,7 @@ class BaseEntityStore(BaseModel, ABC):class InMemoryEntityStore(BaseEntityStore):- """Basic in-memory entity store."""+ """In-memory Entity store."""store: Dict[str, Optional[str]] = {}@@ -69,7 +71,9 @@ class InMemoryEntityStore(BaseEntityStore):class RedisEntityStore(BaseEntityStore):- """Redis-backed Entity store. Entities get a TTL of 1 day by default, and+ """Redis-backed Entity store.++ Entities get a TTL of 1 day by default, andthat TTL is extended by 3 days every time the entity is read back."""@@ -245,7 +249,7 @@ class ConversationEntityMemory(BaseChatMemory):"""Entity extractor & summarizer memory.Extracts named entities from the recent chat history and generates summaries.- With a swapable entity store, persisting entities across conversations.+ With a swappable entity store, persisting entities across conversations.Defaults to an in-memory entity store, and can be swapped out for a Redis,SQLite, or other entity store."""diff --git a/libs/langchain/langchain/memory/kg.py b/libs/langchain/langchain/memory/kg.pyindex dc1019fc12..400ed34987 100644--- a/libs/langchain/langchain/memory/kg.py+++ b/libs/langchain/langchain/memory/kg.py@@ -17,7 +17,7 @@ from langchain.schema.messages import BaseMessage, SystemMessage, get_buffer_strclass ConversationKGMemory(BaseChatMemory):- """Knowledge graph memory for storing conversation memory.+ """Knowledge graph conversation memory.Integrates with external knowledge graph to store and retrieveinformation about knowledge triples in the conversation.diff --git a/libs/langchain/langchain/memory/motorhead_memory.py b/libs/langchain/langchain/memory/motorhead_memory.pyindex f84ebe0f1f..30dfbb7cea 100644--- a/libs/langchain/langchain/memory/motorhead_memory.py+++ b/libs/langchain/langchain/memory/motorhead_memory.py@@ -10,6 +10,8 @@ MANAGED_URL = "https://api.getmetal.io/v1/motorhead"class MotorheadMemory(BaseChatMemory):+ """Chat message memory backed by Motorhead service."""+url: str = MANAGED_URLtimeout = 3000memory_key = "history"diff --git a/libs/langchain/langchain/memory/simple.py b/libs/langchain/langchain/memory/simple.pyindex c30f70240d..00caa9d5b2 100644--- a/libs/langchain/langchain/memory/simple.py+++ b/libs/langchain/langchain/memory/simple.py@@ -4,7 +4,7 @@ from langchain.schema import BaseMemoryclass SimpleMemory(BaseMemory):- """Simple memory for storing context or other bits of information that shouldn't+ """Simple memory for storing context or other information that shouldn'tever change between prompts."""diff --git a/libs/langchain/langchain/memory/summary.py b/libs/langchain/langchain/memory/summary.pyindex 449a4361fe..afa0f9c8ef 100644--- a/libs/langchain/langchain/memory/summary.py+++ b/libs/langchain/langchain/memory/summary.py@@ -16,6 +16,8 @@ from langchain.schema.messages import BaseMessage, SystemMessage, get_buffer_strclass SummarizerMixin(BaseModel):+ """Mixin for summarizer."""+human_prefix: str = "Human"ai_prefix: str = "AI"llm: BaseLanguageModel@@ -36,7 +38,7 @@ class SummarizerMixin(BaseModel):class ConversationSummaryMemory(BaseChatMemory, SummarizerMixin):- """Conversation summarizer to memory."""+ """Conversation summarizer to chat memory."""buffer: str = ""memory_key: str = "history" #: :meta private:diff --git a/libs/langchain/langchain/memory/token_buffer.py b/libs/langchain/langchain/memory/token_buffer.pyindex 80f76c3b76..a964f2f6b4 100644--- a/libs/langchain/langchain/memory/token_buffer.py+++ b/libs/langchain/langchain/memory/token_buffer.py@@ -6,7 +6,7 @@ from langchain.schema.messages import BaseMessage, get_buffer_stringclass ConversationTokenBufferMemory(BaseChatMemory):- """Buffer for storing conversation memory."""+ """Conversation chat memory with token limit."""human_prefix: str = "Human"ai_prefix: str = "AI"diff --git a/libs/langchain/langchain/memory/vectorstore.py b/libs/langchain/langchain/memory/vectorstore.pyindex 7c6772fda6..41f0d8c671 100644--- a/libs/langchain/langchain/memory/vectorstore.py+++ b/libs/langchain/langchain/memory/vectorstore.py@@ -11,7 +11,7 @@ from langchain.vectorstores.base import VectorStoreRetrieverclass VectorStoreRetrieverMemory(BaseMemory):- """Class for a VectorStore-backed memory object."""+ """VectorStoreRetriever-backed memory."""retriever: VectorStoreRetriever = Field(exclude=True)"""VectorStoreRetriever object to connect to."""diff --git a/libs/langchain/langchain/memory/zep_memory.py b/libs/langchain/langchain/memory/zep_memory.pyindex 8e56eb4773..6e2a7ec823 100644--- a/libs/langchain/langchain/memory/zep_memory.py+++ b/libs/langchain/langchain/memory/zep_memory.py@@ -7,7 +7,7 @@ from langchain.memory.chat_message_histories import ZepChatMessageHistoryclass ZepMemory(ConversationBufferMemory):- """Persist your chain history to the Zep Long-term Memory Server+ """Persist your chain history to the Zep Memory Server.The number of messages returned by Zep and when the Zep server summarizes chathistories is configurable. See the Zep documentation for more details.diff --git a/libs/langchain/langchain/schema/memory.py b/libs/langchain/langchain/schema/memory.pyindex 14a07bb379..46da7504b2 100644--- a/libs/langchain/langchain/schema/memory.py+++ b/libs/langchain/langchain/schema/memory.py@@ -8,7 +8,7 @@ from langchain.schema.messages import AIMessage, BaseMessage, HumanMessageclass BaseMemory(Serializable, ABC):- """Base abstract class for memory in Chains.+ """Abstract base class for memory in Chains.Memory refers to state in Chains. Memory can be used to store information aboutpast executions of a Chain and inject that information into the inputs of