langchain_experimental.generative_agents.memory.GenerativeAgentMemory

class langchain_experimental.generative_agents.memory.GenerativeAgentMemory(*, llm: BaseLanguageModel, memory_retriever: TimeWeightedVectorStoreRetriever, verbose: bool = False, reflection_threshold: Optional[float] = None, current_plan: List[str] = [], importance_weight: float = 0.15, aggregate_importance: float = 0.0, max_tokens_limit: int = 1200, queries_key: str = 'queries', most_recent_memories_token_key: str = 'recent_memories_token', add_memory_key: str = 'add_memory', relevant_memories_key: str = 'relevant_memories', relevant_memories_simple_key: str = 'relevant_memories_simple', most_recent_memories_key: str = 'most_recent_memories', now_key: str = 'now', reflecting: bool = False)[source]

Bases: BaseMemory

Memory for the generative agent.

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 add_memory_key: str = 'add_memory'
param aggregate_importance: float = 0.0

Track the sum of the ‘importance’ of recent memories.

Triggers reflection when it reaches reflection_threshold.

param current_plan: List[str] = []

The current plan of the agent.

param importance_weight: float = 0.15

How much weight to assign the memory importance.

param llm: langchain.schema.language_model.BaseLanguageModel [Required]

The core language model.

param max_tokens_limit: int = 1200
param memory_retriever: langchain.retrievers.time_weighted_retriever.TimeWeightedVectorStoreRetriever [Required]

The retriever to fetch related memories.

param most_recent_memories_key: str = 'most_recent_memories'
param most_recent_memories_token_key: str = 'recent_memories_token'
param now_key: str = 'now'
param queries_key: str = 'queries'
param reflecting: bool = False
param reflection_threshold: Optional[float] = None

When aggregate_importance exceeds reflection_threshold, stop to reflect.

param relevant_memories_key: str = 'relevant_memories'
param relevant_memories_simple_key: str = 'relevant_memories_simple'
param verbose: bool = False
add_memories(memory_content: str, now: Optional[datetime] = None) List[str][source]

Add an observations or memories to the agent’s memory.

add_memory(memory_content: str, now: Optional[datetime] = None) List[str][source]

Add an observation or memory to the agent’s memory.

chain(prompt: PromptTemplate) LLMChain[source]
clear() None[source]

Clear memory contents.

fetch_memories(observation: str, now: Optional[datetime] = None) List[Document][source]

Fetch related memories.

format_memories_detail(relevant_memories: List[Document]) str[source]
format_memories_simple(relevant_memories: List[Document]) str[source]
load_memory_variables(inputs: Dict[str, Any]) Dict[str, str][source]

Return key-value pairs given the text input to the chain.

pause_to_reflect(now: Optional[datetime] = None) List[str][source]

Reflect on recent observations and generate ‘insights’.

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

Save the context of this model run to memory.

to_json() Union[SerializedConstructor, SerializedNotImplemented]
to_json_not_implemented() SerializedNotImplemented
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.

property memory_variables: List[str]

Input keys this memory class will load dynamically.

model Config

Bases: object

Configuration for this pydantic object.

arbitrary_types_allowed = True