Context Lifespan Overview

Optimal context lifespan in DialogFlow

If you are building bots using Dialogflow, you are probably aware of contexts. They are used to maintain state. For the specific purpose of state management, I find their implementation quite fascinating simply because they have this concept of “lifespan”.

Doesn’t a larger context lifespan help when conversation goes off track?

“By default, Dialogflow sets it to 2. At first I thought that didn’t make sense, but then I realized that many people might send a message like umm.. or accidentally send a typo”

Identifying intents which are candidates for selection

So let us take a closer look at how to identify intents which are candidates for selection.

The context lifespan is like a “hidden feature” in Dialogflow

The context lifespan you set for an output context is like a “hidden” feature. I mention this because I still see this issue for many people who come to me for help with fixing their Dialogflow chatbot. But I notice they don’t use a lifespan of 1. To make things worse, quite often they don’t see the connection between using the default lifespan and the unpredictable behavior of their chatbot.


I also got the following input from a fellow Dialogflow freelancer who has worked on many bots for his clients. He once mentioned that he prefers a context lifespan of 2, but that he also agrees with me. So I asked him to explain. Here is what he said.