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.

Hierarchy

Constructors

Properties

lc_kwargs: SerializedFields
lc_serializable: boolean = false
longTermMemory: GenerativeAgentMemory
name: string
status: string
traits: string
verbose: boolean

Whether to print out response text.

age?: number
callbacks?: Callbacks
memory?: BaseMemory
metadata?: Record<string, unknown>
tags?: string[]
lc_runnable: boolean = true

Accessors

  • get lc_aliases(): undefined | {
        [key: string]: string;
    }
  • A map of aliases for constructor args. Keys are the attribute names, e.g. "foo". Values are the alias that will replace the key in serialization. This is used to eg. make argument names match Python.

    Returns undefined | {
        [key: string]: string;
    }

  • get lc_attributes(): undefined | {
        [key: string]: undefined;
    }
  • A map of additional attributes to merge with constructor args. Keys are the attribute names, e.g. "foo". Values are the attribute values, which will be serialized. These attributes need to be accepted by the constructor as arguments.

    Returns undefined | {
        [key: string]: undefined;
    }

  • get lc_namespace(): string[]
  • A path to the module that contains the class, eg. ["langchain", "llms"] Usually should be the same as the entrypoint the class is exported from.

    Returns string[]

  • get lc_secrets(): undefined | {
        [key: string]: string;
    }
  • A map of secrets, which will be omitted from serialization. Keys are paths to the secret in constructor args, e.g. "foo.bar.baz". Values are the secret ids, which will be used when deserializing.

    Returns undefined | {
        [key: string]: string;
    }

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: Callbacks

      Optional Callbacks instance.

    Returns Promise<ChainValues>

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

  • 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: CallbackManagerForChainRun

      Optional CallbackManagerForChainRun instance.

    Returns Promise<string>

    The extracted action 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: CallbackManagerForChainRun

      Optional CallbackManagerForChainRun instance.

    Returns Promise<string>

    The agent's summary as a string.

  • Stream all output from a runnable, as reported to the callback system. This includes all inner runs of LLMs, Retrievers, Tools, etc. Output is streamed as Log objects, which include a list of jsonpatch ops that describe how the state of the run has changed in each step, and the final state of the run. The jsonpatch ops can be applied in order to construct state.

    Parameters

    Returns AsyncGenerator<RunLogPatch, any, unknown>

  • Helper method to transform an Iterator of Input values into an Iterator of Output values, with callbacks. Use this to implement stream() or transform() in Runnable subclasses.

    Type Parameters

    Parameters

    • inputGenerator: AsyncGenerator<I, any, unknown>
    • transformer: ((generator, runManager?, options?) => AsyncGenerator<O, any, unknown>)
        • (generator, runManager?, options?): AsyncGenerator<O, any, unknown>
        • Parameters

          Returns AsyncGenerator<O, any, unknown>

    • Optional options: BaseCallbackConfig & {
          runType?: string;
      }

    Returns AsyncGenerator<O, any, unknown>

Generated using TypeDoc