Implementation of a generative agent that can learn and form new memories over time. It extends the BaseChain class, which is a generic sequence of calls to components, including other chains.

const tommie: GenerativeAgent = new GenerativeAgent(
new OpenAI({ temperature: 0.9, maxTokens: 1500 }),
new GenerativeAgentMemory(
new ChatOpenAI(),
new TimeWeightedVectorStoreRetriever({
vectorStore: new MemoryVectorStore(new OpenAIEmbeddings()),
otherScoreKeys: ["importance"],
k: 15,
}),
{ reflectionThreshold: 8 },
),
{
name: "Tommie",
age: 25,
traits: "anxious, likes design, talkative",
status: "looking for a job",
},
);

await tommie.addMemory(
"Tommie remembers his dog, Bruno, from when he was a kid",
new Date(),
);
const summary = await tommie.getSummary({ forceRefresh: true });
const response = await tommie.generateDialogueResponse(
"USER says Hello Tommie, how are you today?",
);

Hierarchy (view full)

Constructors

Properties

llm: BaseLanguageModelInterface
longTermMemory: GenerativeAgentMemory
name: string
status: string
traits: string
verbose: boolean
age?: number
memory?: any

Accessors

Methods

  • Adds a memory to the agent's long-term memory.

    Parameters

    • memoryContent: string

      The content of the memory to add.

    • Optionalnow: Date

      Optional current date.

    • Optionalmetadata: Record<string, unknown>

      Optional metadata for the memory.

    • Optionalcallbacks: any

      Optional Callbacks instance.

    Returns Promise<ChainValues>

    The result of adding the memory to the agent's long-term memory.

  • Parameters

    • inputs: ChainValues[]
    • Optionalconfig: any[]

    Returns Promise<ChainValues[]>

    Use .batch() instead. Will be removed in 0.2.0.

    Call the chain on all inputs in the list

  • Parameters

    • values: any
    • Optionalconfig: any
    • Optionaltags: string[]

    Returns Promise<ChainValues>

    Use .invoke() instead. Will be removed in 0.2.0.

    Run the core logic of this chain and add to output if desired.

    Wraps _call and handles memory.

  • Computes the agent's summary by summarizing the agent's core characteristics given the agent's relevant memories.

    Parameters

    • OptionalrunManager: any

      Optional CallbackManagerForChainRun instance.

    Returns Promise<string>

    The computed summary as a string.

  • Generates a dialogue response to the given observation.

    Parameters

    • observation: string

      The observation to generate a dialogue response for.

    • Optionalnow: Date

      Optional current date.

    Returns Promise<[boolean, string]>

    A boolean indicating whether to continue the dialogue and the output string.

  • Generates a reaction to the given observation.

    Parameters

    • observation: string

      The observation to generate a reaction for.

    • Optionalnow: Date

      Optional current date.

    Returns Promise<[boolean, string]>

    A boolean indicating whether to continue the dialogue and the output string.

  • Extracts the action of the given entity from the given observation.

    Parameters

    • observation: string

      The observation to extract the action from.

    • entityName: string

      The name of the entity to extract the action for.

    • OptionalrunManager: any

      Optional CallbackManagerForChainRun instance.

    Returns Promise<string>

    The extracted action as a string.

  • Extracts the observed entity from the given observation.

    Parameters

    • observation: string

      The observation to extract the entity from.

    • OptionalrunManager: any

      Optional CallbackManagerForChainRun instance.

    Returns Promise<string>

    The extracted entity as a string.

  • Returns a full header of the agent's status, summary, and current time.

    Parameters

    • config: {
          forceRefresh?: boolean;
          now?: Date;
      } = {}

      Optional configuration object with current date and a boolean to force refresh.

      • OptionalforceRefresh?: boolean
      • Optionalnow?: Date

    Returns string

    The full header as a string.

  • Gets the agent's summary, which includes the agent's name, age, traits, and a summary of the agent's core characteristics. The summary is updated periodically through probing the agent's memories.

    Parameters

    • Optionalconfig: {
          forceRefresh?: boolean;
          now?: Date;
      }

      Optional configuration object with current date and a boolean to force refresh.

      • OptionalforceRefresh?: boolean
      • Optionalnow?: Date
    • OptionalrunManager: any

      Optional CallbackManagerForChainRun instance.

    Returns Promise<string>

    The agent's summary as a string.

  • Invoke the chain with the provided input and returns the output.

    Parameters

    • input: ChainValues

      Input values for the chain run.

    • Optionaloptions: any

    Returns Promise<ChainValues>

    Promise that resolves with the output of the chain run.

  • Parameters

    • inputs: Record<string, unknown>
    • outputs: Record<string, unknown>
    • returnOnlyOutputs: boolean = false

    Returns Promise<Record<string, unknown>>

  • Parameters

    • input: any
    • Optionalconfig: any

    Returns Promise<string>

    Use .invoke() instead. Will be removed in 0.2.0.

  • Summarizes memories that are most relevant to an observation.

    Parameters

    • observation: string

      The observation to summarize related memories for.

    • OptionalrunManager: any

      Optional CallbackManagerForChainRun instance.

    Returns Promise<string>

    The summarized memories as a string.