Skip to main content

Advanced Examples

This collection of advanced examples illustrates quite complex topics at the frontier of AI cognitive modeling.


Here we display a much more complex example of the following and intriguing concept: what if an AI Soul is given the capacity to remember and think about how it is thinking? This concept is generally known as metacognition, and is a core skill humans display. This example is currently presented without further context.

import * as readline from "readline";

import {
} from "../src/next";
import { Blueprints } from "../src";

const blueprint = Blueprints.SAMANTHA;

const goal = `Making the user happy`;
const initialMemory = [
role: ChatMessageRoleEnum.System,
content: `You are modeling the mind of ${}


${} has the following goal of: ${goal}

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,

let dialog = new CortexStep(;
dialog = dialog.withMemory(initialMemory);

let intermediateThoughtProcess = ["pondered how she feels", "wondered about intention"];

async function addDialogLine(text: string) {
const newUserMemory = [
role: ChatMessageRoleEnum.User,
content: text,
dialog = dialog.withMemory(newUserMemory);

let thoughtProcess:CortexStep<any> = dialog;
for (const process of intermediateThoughtProcess) {
thoughtProcess = await`Samantha ${process}. The response should be 1 to 2 sentences at most.`, process));
console.log("\n",, process, thoughtProcess.value, "\n");
const says = await;
const newAssistantMemory = [
role: ChatMessageRoleEnum.Assistant,
content: says.value,
dialog = dialog.withMemory(newAssistantMemory);
const decisionStep = await
`Consider the prior dialog and the goal of ${goal}. ${} has the following INTERNAL METACOGNITION: [${intermediateThoughtProcess}]. Should the INTERNAL METACOGNITION change or stay the same?`,
["change thought process", "keep process the same"]
console.log(, "decides", decisionStep.value);
if (decisionStep.value === "change thought process") {
const newProcess = await
`Previously, ${} used the following INTERNAL METACOGNITION to think to themselves before speaking: [${intermediateThoughtProcess}]. Now, REVISE the INTERNAL METACOGNITION, adding, deleting, or modifying the processes.

For example. Revise [process1, process2] to [process1', process4, process5]. The revised processes must be different than the prior ones.
Each thought process should be two or three words to describe an internal thought process, these should be phrased in the past tense like "analyzed" "challenged" etc

MAKE SURE the new actions are all INTERNAL thought processes to think through PRIOR to speaking to the user, directed at oneself. Actions like provoking are all more external and don't qualify.
intermediateThoughtProcess = newProcess.value;
console.log(, "concludes", intermediateThoughtProcess);

'- Type a message to send to Soul\n- Type "reset" to reset\n- Type "exit" to quit\n'

rl.on("line", async (line) => {
if (line.toLowerCase() === "exit") {
} else {
const text: string = line;