Windows Live Agents: Context Zones

With Buddyscript, you can define context zones, that restrict processing of patterns based on a simple condition. We're going to talk about some "advanced" tricks you can do.

Usually, we will use context zones with flag variables, in order to activate or deactivate them.
But one point not mentioned in the documentation is that you can nest them, or even have them in different files. I will show you an example.

First, define this two variables and context subsections somewhere in your code (for example in a global variables file):

variable G_MAIN_SECTION = 0
context MainSection {condition="G_MAIN_SECTION==1" out-of-context="0"}

variable G_SUB_SECTION = 0
context SubSection {condition="G_SUB_SECTION==1" in-context="110" out-of-context="0"}

Then, place this code in one separate file:

begin context MainSection

+ test_split_section {score=900}
- You're in the main context section, split file

begin context SubSection

+ test_split_section {score=900}
- You're in the sub-context section, split file

end context SubSection

end context MainSection

We define a pattern (test_split_section) that will only be triggered if we're on the MainSection context, and another one with the same name that will only be triggered if we're both in the main and the SubSection contexts. So, we will get different outputs if we've entered one or both contexts ;)

Finally, put the following code in another separate file:

+ start
- Entering main section
G_MAIN_SECTION = 1

+ test_section
- You're out of the main section

begin context MainSection

+ test_section {score=900}
- You're on the main section

+ abandon {score=900}
- Going out of the main section
G_MAIN_SECTION = 0

+ start {score=900}
- Entering sub-section
G_SUB_SECTION = 1

begin context SubSection

+ test_section {score=900}
- You're on the sub-section

+ abandon {score=900}
- Going out of the sub-section
G_SUB_SECTION = 0

end context SubSection

end context MainSection

So, we have re-definitions of three patterns:

  • start: Enters the main section, or if we're inside it, enters the sub-section
  • abandon: Exits the main section, or if we're inside the sub-section, exits the sub-section (if we're not on either section, it doesn't works)
  • test_section: Tells us where we are

Now, here is a sample question/response output showing how all the code works. Notice how being in subsections and calling test_split_section works too!

> test_section
< You're out of the main section
> start
< Entering main section
> test_section
< You're on the main section
> test_split_section
< You're in the main context section, split file
> start
< Entering sub-section
> test_section
< You're on the sub-section
> test_split_section
< You're in the sub-context section, split file
> abandon
< Going out of the sub-section
> test_section
< You're on the main section
> abandon
< Going out of the main section
> test_section
< You're out of the main section

With context zones, you can define advanced conversation flows, "restricted areas", triggers, and even simulate conversation dialogs by using multiple zones.

Tags: Development

Windows Live Agents: Context Zones article, written by Kartones. Published on