langchain.memory.token_buffer.ConversationTokenBufferMemory

class langchain.memory.token_buffer.ConversationTokenBufferMemory(*, chat_memory: BaseChatMessageHistory = None, output_key: Optional[str] = None, input_key: Optional[str] = None, return_messages: bool = False, human_prefix: str = 'Human', ai_prefix: str = 'AI', llm: BaseLanguageModel, memory_key: str = 'history', max_token_limit: int = 2000)[source]

Bases: BaseChatMemory

Conversation chat memory with token limit.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

param ai_prefix: str = 'AI'
param chat_memory: BaseChatMessageHistory [Optional]
param human_prefix: str = 'Human'
param input_key: Optional[str] = None
param llm: langchain.schema.language_model.BaseLanguageModel [Required]
param max_token_limit: int = 2000
param memory_key: str = 'history'
param output_key: Optional[str] = None
param return_messages: bool = False
clear() None

Clear memory contents.

load_memory_variables(inputs: Dict[str, Any]) Dict[str, Any][source]

Return history buffer.

save_context(inputs: Dict[str, Any], outputs: Dict[str, str]) None[source]

Save context from this conversation to buffer. Pruned.

to_json() Union[SerializedConstructor, SerializedNotImplemented]
to_json_not_implemented() SerializedNotImplemented
property buffer: List[langchain.schema.messages.BaseMessage]

String buffer of memory.

property lc_attributes: Dict

Return a list of attribute names that should be included in the serialized kwargs. These attributes must be accepted by the constructor.

property lc_namespace: List[str]

Return the namespace of the langchain object. eg. [“langchain”, “llms”, “openai”]

property lc_secrets: Dict[str, str]

Return a map of constructor argument names to secret ids. eg. {“openai_api_key”: “OPENAI_API_KEY”}

property lc_serializable: bool

Return whether or not the class is serializable.

model Config

Bases: object

Configuration for this pydantic object.

arbitrary_types_allowed = True

Examples using ConversationTokenBufferMemory