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.

Example

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.

    • Optional now: Date

      Optional current date.

    • Optional metadata: Record<string, unknown>

      Optional metadata for the memory.

    • Optional callbacks: any

      Optional Callbacks instance.

    Returns Promise<ChainValues>

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

  • Parameters

    • inputs: ChainValues[]
    • Optional config: any[]

    Returns Promise<ChainValues[]>

    ⚠️ Deprecated ⚠️

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

    This feature is deprecated and will be removed in the future.

    It is not recommended for use.

    Call the chain on all inputs in the list

  • Parameters

    • values: any
    • Optional config: any
    • Optional tags: string[]

      Deprecated

    Returns Promise<ChainValues>

    Deprecated

    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

    • Optional runManager: 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.

    • Optional now: 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.

    • Optional now: 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.

    • Optional runManager: 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.

    • Optional runManager: 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.

      • Optional forceRefresh?: boolean
      • Optional now?: 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

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

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

      • Optional forceRefresh?: boolean
      • Optional now?: Date
    • Optional runManager: 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.

    • Optional options: 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
    • Optional config: any

    Returns Promise<string>

    Deprecated

    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.

    • Optional runManager: any

      Optional CallbackManagerForChainRun instance.

    Returns Promise<string>

    The summarized memories as a string.

Generated using TypeDoc