How To Build Chatbots

Chapters
Chapter 11: Memories

Your chatbot will remember who it talked to, when it last talked to him or her, and a number of specific things about each person it talks to. Memories are completely customizable - you can remember things the person said, the things the chatbot itself said, and any kind of fact you want to remember.

The Memory Keyphrase

#memory: this Special Keyphrase calls these memories forward when there are lulls in the conversation or as part of compound Responses. The Responses here are meant to be statements or questions about memories, and so each Response should have at least one Memory Plug-in. On your Chatbot's Settings page, you can adjust how often these Responses come up.

Creating Memories

There are two kinds of memory. Memory is your chatbot's memories of other people. Self Memory is your chatbot's memories about itself, unrelated to the person your chatbot is chatting with. The same Self Memory can be accessed no matter who your chatbot is chatting with.

Memory and Self Memory statements are identical, except that Self Memory statements begin with "self: ".

There is no limit on the number of different memories you can create for your chatbots. Each individual memory can store 10 different things. Then old ones drop off the list as new ones are added. For example, let's say you create a memory called (mem-you-like-to). It can store "ski, visit National Parks, read, play guitar, watch movies". At this point the memory is storing 5 things. When it gets to 11, then "ski" will fall off the list, being the oldest.

If you only want one thing stored in a Memory, then you can use "only" (see below).

INITIALIZE MEMORY

Where: Initialization

AIScript: default "memorycontents" as "memoryname";

Example: default "bub" as "nickname";

What It Does: If memory does not exist at the beginning of a conversation, create it with this value

Alternate: def can be used instead of default

REMEMBER

Where: Initialization, Keyphrase, Response

AIScript: remember "memorycontents" as "memoryname";

Example: remember (key1) as "just-ate";
Example: remember (object) as "my-gift";
Example: remember "pina colada" as "favorite-drink";
Example: remember "(key1) (postkey)" as "you-like-to-do";

AIScript: self: remember "memorycontents" as "memoryname";

Example: self: remember "The (Verb)ing (Person)s" as "my-bandname";

What It Does: Saves memorycontents as a memory by the name of memoryname. If memorycontents contains plug-ins, they will be filled in before the memory is stored. If a memory of this name exists, it adds the new value to the list.

AIScript: remember "memorycontents" as only "memoryname";
AIScript: self: remember "memorycontents" as only "memoryname";

Example: remember (key1) as only "nickname";
Example: remember "yes" as only "likes-bears";

What It Does: Saves memorycontents as the only memory by the name of memoryname. This will replace all existing memories for that memoryname.

Alternate: rem can be used instead of remember

NOTE: Make sure each type of memories fits a certain kind of thing, such as a noun phrase, a verb phrase, or an adjective. That way, you will know it fits into your Responses. It would be confusing to be expecting a noun phrase and a verb phrase is in the memory instead!

Memory Plug-ins

Memory Plug-ins can be used anywhere. You don't have to worry about whether or not a memory exists, because a Response using a memory that does not yet exist will not be chosen by the AI Engine.

(mem-something) inserts one of the chatbot's corresponding memories.

(self-something) inserts one of the chatbot's corresponding self memories.

Example: "Hi, (mem-nickname)! Someone told me I was (self-iam) today. Do you think so?"

Numeric Memories

You can also create numeric memories that you can add to, subtract from, set to a value, or even multiply or divide. These can only be whole numbers (integers) - no decimals or fractions. These can be used to track anything you might want to track. Unlike normal memories that can hold 10 items, numeric memories only store a single number.

It's best practice to have all numeric memories declared in your Initialization AIScript, so that the AI Engine knows its starting value. Otherwise, 0 will be assumed to be the starting value. When writing numeric memory AIScript, always write the number without quotation marks around it.

Limits: You can optionally set limits (a minimum and maximum value) to any numeric memory when you initialize it. The AI Engine will ensure the value always remains in that range. Note that when you add or change initialization limits at the end of the default statement (like changing {-10, 10} to {-5, 15}), it will be applied to any existing memories the next time they chat.

INITIALIZE NUMERIC MEMORY

Where: Initialization

AIScript: default "memoryname" = number;
AIScript: default "memoryname" = number {lowestvalue, highestvalue};

Example: default "success_count" = 0;
Example: default "impressed" = 0 {-10, 10};

What It Does: If memory does not exist at the beginning of a conversation, create it with this value. If limits are declared, apply them every time this memory value is changed.

Numeric memories are referred to in this format: (mem-#-memoryname)

Alternate: def can be used instead of default

CHANGE NUMERIC VALUE

Where: Initialization, Keyphrase, Response

AIScript: (mem-#-memoryname) + number;

Option What It Does
+ Adds this amount to the memory
- Subtracts this amount from the memory
= Sets the memory to this number
* Multiplies the memory by this number
/ Divides the memory by this number and rounds the result
Example: (mem-#-petcount) + 1;
Example: (mem-#-points) - 2;
Example: (mem-#-impressed) = 5;

AIScript: (self-#-memoryname) + number;

Example: (self-#-feelings) + 1;

What It Does: Changes and saves the numeric value of memoryname by the given amount.

Alternate: rem can be used instead of remember

NOTE: Regular memories and numeric memories cannot share the same name. The #- part of the memory is not a part of its name, it's just an indicator that the memory is numeric. So essentially (mem-dogs) and (mem-#-dogs) refer to the same memory. The #- tells you that it's acting as a number.

Converting to Numeric: If you had a regular memory that was acting as a number and want it to be converted to a numeric memory, you can accomplish this by simply applying a numeric change to that memory. IF the memory is actually numeric, it will become a numeric memory. You can not convert a memory from numeric to a normal memory. Attempts to add words to numeric memories will result in nothing happening.

Numeric Memory Plug-ins

(mem-#-something) inserts the number for this memory.

(self-#-something) inserts the number for this self memory.

Example: "I only have (self-#-presents) left. Do you want one?"

Forgetting Memories

If your chatbot remembers something that a person later says isn't true, or that you want to remove as a memory, you can use AIScript to forget that memory.

FORGET

Where: Initialization, Keyphrase, Response

AIScript: forget "memorycontents" from "memoryname";

Example: forget "hungry" from "you-are-adj";
Example: forget (key1) from "you-are-np";

What It Does: Remove the memory from memoryname if the memory exists.

NOTE: Forgetting doesn't work with numeric memories. You can simply set them to their default value.

Your Chatbot's Memories

By clicking Chatbot Workshop and then "Memories" under your chatbot's name, you can see a chatbot's memories and emotional relationships with everyone they have spoken with. You can correct or remove badly formatted memories here if you want.

Memory Tutorial

Here is a common example of how to use memories to increase the abilities of your chatbot. (name) is a useful AI Engine Plug-in that includes another user's or chatbot's name in a Response. But what if you're dealing with a guest or API user whose name is unknown, or someone who wants to be called something different? You can use Memory AIScript to remember their name.

Let's call the memory "your-name". First, set a default value for their name. This goes in the AIScript Initialization box on your Settings page.

AIScript: default (name) as "your-name";

This fills in (mem-your-name) with the contents of the (name) Plug-in

Next, create a Keyphrase that will catch ways someone might tell you their name.

Keyphrase: my name is, call me, refer to me as
AIScript: rem (postkey) as only "your-name";

Then create another Keyphrase to reset the name field if they change their mind or the chatbot gets it wrong.

Keyphrase: my name is not, do not call me, that is not my name
AIScript: rem (name) as only "your-name"

Finally, every time you want to refer to the person you're talking to, use (mem-your-name) instead of (name). And that's it!

TIP: Since this memory Plug-in will begin with mem-, there is no conflict with simply calling the memory "name" instead of "your-name". This way you can use the shorter (mem-name) in your Responses.

Memories In Responses

You should sprinkle memories into your Responses throughout your chatbot's Language Center. The effect can be powerful and engaging, giving a sense that your chatbot is really listening and getting to know the person. Take a look:

Keyphrase: (m:i_am) (a:sad)
Response: Would (mem-you-like-np) cheer you up?
Memories In Keyphrases

You can use memories as wildcards in Keyphrases! That Memory wildcard will essentially be a list of all the memories stored. The format is the same as the Plug-in: (mem-memoryname). For example:

Keyphrase: (m:i_like) (np)
AIscript: rem (key1) as "you-like-np"

Someone says:
Message: I just love waffles

This creates a memory of "waffles" under "you-like-np". Then you can use that memory wildcard in Keyphrases, and it will match the next time they mention "waffles":

Keyphrase: (mem-you-like-np)
Response: I know how much you like (key1). Are you excited?
or
Keyphrase: (m:i_did) lose (prenoun) (mem-you-like-np)
Response: Oh no! And you really liked (key1) (key2), didn't you.

Recognizing memories and responding to them can really impress and engage people.

Automatic Memory

You may see some memory types in your Chatbot's Memories that you didn't put there. The AI Engine will automatically store some memories based on the Keyphrases matched. We're transitioning from an older system to something new, and will update here with more details when that's live.

Short-Term Memory

The AI Engine tracks topics of conversation in Short-Term Memory. You can see this in a chatbot's Memories as well. This is used for filling in the meaning of pronouns - he, she, they, it, that, etc. In this way, your chatbot will have an idea of what "she" is referring to, or what someone is reffering to when they say "those". It's a great feature in that it gives a sense that your chatbot is really paying attention to the conversation.

Better yet, your chatbot can bring up recent topics in conversations using the following Plug-ins:

Plug-in form:
(topic-category-length-type)

Categories: male, female, person, being, animal, plant, clothes, food, substance, object, place, event, abstract, any

Length: simple, main, all

Option Contains
simple dog
main the wet dog
all the wet dog on the porch

Type: last, recent

Option Contains
last the last memory of this type
recent anything from more than 3 minutes ago

Examples: (topic-food-main-last), (topic-person-all-recent), (topic-any-simple-recent)

Pronoun Plug-ins

Short-term Memory also provides Pronoun Plug-ins, which reference the last word each pronoun referred to:

Plug-in form:
(last-pronoun)

Pronouns: he, his, she, her, being, it, its, they, those, their, do (the last action)

Examples: (last-he), (last-they)

Message: My cousin Antonio is the best soccer player I know.
...
...
Message: Do you know him?
Keyphrase: (m:do_you_know) him
Response: (Last-he)? Yes, I met him at a party.
Becomes Your cousin Antonio? Yes, I met him at a party.

Gossip

Gossip Responses are used for bringing up memories associated with other users.

Gossip is used to talk about people or chatbots not taking part in the present conversation. On your Chatbot's Settings page, you can adjust how often these Responses come up.

In #gossip Responses, the standard (mem-something) plug-ins will be filled in with memories of the person your chatbot is talking about, not the person they're talking to. They also have some special plug-ins of their own:

(gossipname) inserts the name of the person being gossiped about.

(heshe) inserts the appropriate word: "he" or "she".

(himher) inserts the appropriate third person word: "him" or "her".

(hisher) inserts the appropriate possessive word: "his" or "her".