Experimental
This module contains experimental modules and reproductions of existing work using LangChain primitives.
Autonomous agents
Here, we document the BabyAGI and AutoGPT classes from the langchain.experimental module.
class langchain.experimental.BabyAGI(*, memory=None, callbacks=None, callback_manager=None, verbose=None, tags=None, task_list=None, task_creation_chain, task_prioritization_chain, execution_chain, task_id_counter=1, vectorstore, max_iterations=None)[source]
Bases: langchain.chains.base.Chain, pydantic.main.BaseModel
Controller model for the BabyAGI agent.
Parameters
memory (Optional[langchain.schema.BaseMemory]) – 
callbacks (Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]]) – 
callback_manager (Optional[langchain.callbacks.base.BaseCallbackManager]) – 
verbose (bool) – 
tags (Optional[List[str]]) – 
task_list (collections.deque) – 
task_creation_chain (langchain.chains.base.Chain) – 
task_prioritization_chain (langchain.chains.base.Chain) – 
execution_chain (langchain.chains.base.Chain) – 
task_id_counter (int) – 
vectorstore (langchain.vectorstores.base.VectorStore) – 
max_iterations (Optional[int]) – 
Return type
None
model Config[source]
Bases: object
Configuration for this pydantic object.
arbitrary_types_allowed = True
property input_keys: List[str]
Input keys this chain expects.
property output_keys: List[str]
Output keys this chain expects.
get_next_task(result, task_description, objective)[source]
Get the next task.
Parameters
result (str) – 
task_description (str) – 
objective (str) – 
Return type
List[Dict]
prioritize_tasks(this_task_id, objective)[source]
Prioritize tasks.
Parameters
this_task_id (int) – 
objective (str) – 
Return type
List[Dict]
execute_task(objective, task, k=5)[source]
Execute a task.
Parameters
objective (str) – 
task (str) – 
k (int) – 
Return type
str
classmethod from_llm(llm, vectorstore, verbose=False, task_execution_chain=None, **kwargs)[source]
Initialize the BabyAGI Controller.
Parameters
llm (langchain.base_language.BaseLanguageModel) – 
vectorstore (langchain.vectorstores.base.VectorStore) – 
verbose (bool) – 
task_execution_chain (Optional[langchain.chains.base.Chain]) – 
kwargs (Dict[str, Any]) – 
Return type
langchain.experimental.autonomous_agents.baby_agi.baby_agi.BabyAGI
class langchain.experimental.AutoGPT(ai_name, memory, chain, output_parser, tools, feedback_tool=None, chat_history_memory=None)[source]
Bases: object
Agent class for interacting with Auto-GPT.
Parameters
ai_name (str) – 
memory (VectorStoreRetriever) – 
chain (LLMChain) – 
output_parser (BaseAutoGPTOutputParser) – 
tools (List[BaseTool]) – 
feedback_tool (Optional[HumanInputRun]) – 
chat_history_memory (Optional[BaseChatMessageHistory]) – 
Generative agents
Here, we document the GenerativeAgent and GenerativeAgentMemory classes from the langchain.experimental module.
class langchain.experimental.GenerativeAgent(*, name, age=None, traits='N/A', status, memory, llm, verbose=False, summary='', summary_refresh_seconds=3600, last_refreshed=None, daily_summaries=None)[source]
Bases: pydantic.main.BaseModel
A character with memory and innate characteristics.
Parameters
name (str) – 
age (Optional[int]) – 
traits (str) – 
status (str) – 
memory (langchain.experimental.generative_agents.memory.GenerativeAgentMemory) – 
llm (langchain.base_language.BaseLanguageModel) – 
verbose (bool) – 
summary (str) – 
summary_refresh_seconds (int) – 
last_refreshed (datetime.datetime) – 
daily_summaries (List[str]) – 
Return type
None
attribute name: str [Required]
The character’s name.
attribute age: Optional[int] = None
The optional age of the character.
attribute traits: str = 'N/A'
Permanent traits to ascribe to the character.
attribute status: str [Required]
The traits of the character you wish not to change.
attribute memory: langchain.experimental.generative_agents.memory.GenerativeAgentMemory [Required]
The memory object that combines relevance, recency, and ‘importance’.
attribute llm: langchain.base_language.BaseLanguageModel [Required]
The underlying language model.
attribute summary: str = ''
Stateful self-summary generated via reflection on the character’s memory.
attribute summary_refresh_seconds: int = 3600
How frequently to re-generate the summary.
attribute last_refreshed: datetime.datetime [Optional]
The last time the character’s summary was regenerated.
attribute daily_summaries: List[str] [Optional]
Summary of the events in the plan that the agent took.
model Config[source]
Bases: object
Configuration for this pydantic object.
arbitrary_types_allowed = True
summarize_related_memories(observation)[source]
Summarize memories that are most relevant to an observation.
Parameters
observation (str) – 
Return type
str
generate_reaction(observation, now=None)[source]
React to a given observation.
Parameters
observation (str) – 
now (Optional[datetime.datetime]) – 
Return type
Tuple[bool, str]
generate_dialogue_response(observation, now=None)[source]
React to a given observation.
Parameters
observation (str) – 
now (Optional[datetime.datetime]) – 
Return type
Tuple[bool, str]
get_summary(force_refresh=False, now=None)[source]
Return a descriptive summary of the agent.
Parameters
force_refresh (bool) – 
now (Optional[datetime.datetime]) – 
Return type
str
get_full_header(force_refresh=False, now=None)[source]
Return a full header of the agent’s status, summary, and current time.
Parameters
force_refresh (bool) – 
now (Optional[datetime.datetime]) – 
Return type
str
class langchain.experimental.GenerativeAgentMemory(*, llm, memory_retriever, verbose=False, reflection_threshold=None, current_plan=[], importance_weight=0.15, aggregate_importance=0.0, max_tokens_limit=1200, queries_key='queries', most_recent_memories_token_key='recent_memories_token', add_memory_key='add_memory', relevant_memories_key='relevant_memories', relevant_memories_simple_key='relevant_memories_simple', most_recent_memories_key='most_recent_memories', now_key='now', reflecting=False)[source]
Bases: langchain.schema.BaseMemory
Parameters
llm (langchain.base_language.BaseLanguageModel) – 
memory_retriever (langchain.retrievers.time_weighted_retriever.TimeWeightedVectorStoreRetriever) – 
verbose (bool) – 
reflection_threshold (Optional[float]) – 
current_plan (List[str]) – 
importance_weight (float) – 
aggregate_importance (float) – 
max_tokens_limit (int) – 
queries_key (str) – 
most_recent_memories_token_key (str) – 
add_memory_key (str) – 
relevant_memories_key (str) – 
relevant_memories_simple_key (str) – 
most_recent_memories_key (str) – 
now_key (str) – 
reflecting (bool) – 
Return type
None
attribute llm: langchain.base_language.BaseLanguageModel [Required]
The core language model.
attribute memory_retriever: langchain.retrievers.time_weighted_retriever.TimeWeightedVectorStoreRetriever [Required]
The retriever to fetch related memories.
attribute reflection_threshold: Optional[float] = None
When aggregate_importance exceeds reflection_threshold, stop to reflect.
attribute current_plan: List[str] = []
The current plan of the agent.
attribute importance_weight: float = 0.15
How much weight to assign the memory importance.
attribute aggregate_importance: float = 0.0
Track the sum of the ‘importance’ of recent memories.
Triggers reflection when it reaches reflection_threshold.
pause_to_reflect(now=None)[source]
Reflect on recent observations and generate ‘insights’.
Parameters
now (Optional[datetime.datetime]) – 
Return type
List[str]
add_memories(memory_content, now=None)[source]
Add an observations or memories to the agent’s memory.
Parameters
memory_content (str) – 
now (Optional[datetime.datetime]) – 
Return type
List[str]
add_memory(memory_content, now=None)[source]
Add an observation or memory to the agent’s memory.
Parameters
memory_content (str) – 
now (Optional[datetime.datetime]) – 
Return type
List[str]
fetch_memories(observation, now=None)[source]
Fetch related memories.
Parameters
observation (str) – 
now (Optional[datetime.datetime]) – 
Return type
List[langchain.schema.Document]
property memory_variables: List[str]
Input keys this memory class will load dynamically.
load_memory_variables(inputs)[source]
Return key-value pairs given the text input to the chain.
Parameters
inputs (Dict[str, Any]) – 
Return type
Dict[str, str]
save_context(inputs, outputs)[source]
Save the context of this model run to memory.
Parameters
inputs (Dict[str, Any]) – 
outputs (Dict[str, Any]) – 
Return type
None
clear()[source]
Clear memory contents.
Return type
None