# Context switching

**URL:** <https://forum.rasa.com/t/context-switching/20589>\
**Category:** Rasa Open Source\
**Created:** [October 29, 2019, 1:33pm UTC](https://forum.rasa.com/t/context-switching/20589 "2019-10-29T13:33:41Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![zeroangel](https://avatars.discourse-cdn.com/v4/letter/z/3da27b/32.png) [@zeroangel](https://forum.rasa.com/u/zeroangel)\
**Post date:** [October 29, 2019, 1:33pm UTC](https://forum.rasa.com/t/context-switching/20589/1 "2019-10-29T13:33:42Z")

</div>

I understand that the best way to handle context switching is to make “stories” for “un-happy paths” like so:

HAPPY PATH:

- intent\_A

- utter\_first response\_to\_A

- answer\_for\_A

- action\_final\_action\_for\_A

UNHAPPY PATH:

- intent\_A

- utter\_first\_response\_to\_A

- intent\_B

- utter\_first\_response\_for\_B

- answer\_for\_B

- action\_final\_action\_for\_B
- utter\_would\_you\_like\_to\_return\_to\_B

The issue is that we have 50+ intents (some of them with very involved dialogue flows alone) and to create stories to cover all (or enough paths) to meet regulatory demands that the stories proceed as they should we would require an exponential number of stories.

Is there any other way this can be handled? I had thought of storing the state of the tracker in some kind of stack when a context switch is made that one could pop off as context switches are finished and return to the previous flow. However, I am at a loss to determine when there is in fact a context switch.

---

<div class="post-metadata">

**Author:** ![amn41](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/amn41/32/20_2.png) [@amn41](https://forum.rasa.com/u/amn41)\
**Post date:** [October 31, 2019, 8:57am UTC](https://forum.rasa.com/t/context-switching/20589/2 "2019-10-31T08:57:03Z")

</div>

Hi @zeroangel ! Couple of things to keep in mind:

- do all of your 50+ user goals require multi-turn interactions? If so you have a very complicated project! If many of these can be handled with a single-turn response, I would highly recommend trying [retrieval actions](https://blog.rasa.com/response-retrieval-models/) which let you model all the single-turn interactions with a single intent.

- the new transformer-based embedding policy is designed to do exactly this. The paper also describes why we don’t use a stack [[1910.00486] Dialogue Transformers](https://arxiv.org/abs/1910.00486)

---

<div class="post-metadata">

**Author:** ![v5out](https://avatars.discourse-cdn.com/v4/letter/v/b5ac83/32.png) [@v5out](https://forum.rasa.com/u/v5out)\
**Post date:** [July 10, 2020, 4:28pm UTC](https://forum.rasa.com/t/context-switching/20589/3 "2020-07-10T16:28:37Z")

</div>

Hi @zeroangel, did you get this working? I have a similar situation and don’t have an answer.

I looked at some of the current research at DSTC7 and DSTC8, on AWS, Google, etc. but can’t see anything that can be used in production.

Did TED work for you?

Thanks!

---

<div class="post-metadata">

**Author:** ![zeroangel](https://avatars.discourse-cdn.com/v4/letter/z/3da27b/32.png) [@zeroangel](https://forum.rasa.com/u/zeroangel)\
**Post date:** [July 10, 2020, 6:55pm UTC](https://forum.rasa.com/t/context-switching/20589/4 "2020-07-10T18:55:25Z")

</div>

Hi John. Actually our team ended up going with a hard-coded dialogue manager instead.

---

<div class="post-metadata">

**Author:** ![noman](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/noman/32/10071_2.png) [@noman](https://forum.rasa.com/u/noman)\
**Post date:** [July 12, 2020, 7:25pm UTC](https://forum.rasa.com/t/context-switching/20589/5 "2020-07-12T19:25:31Z")

</div>

This is what we also did (a hard coded dialogue manager)

---

<div class="post-metadata">

**Author:** ![v5out](https://avatars.discourse-cdn.com/v4/letter/v/b5ac83/32.png) [@v5out](https://forum.rasa.com/u/v5out)\
**Post date:** [July 12, 2020, 8:27pm UTC](https://forum.rasa.com/t/context-switching/20589/6 "2020-07-12T20:27:21Z")

</div>

Sorry, but I’m not sure what you mean by “hard-coded dialogue manager”. Do you mean many if-then-else/switch statements or a state machine or a discourse tree or something else? Thanks!

---

<div class="post-metadata">

**Author:** ![zeroangel](https://avatars.discourse-cdn.com/v4/letter/z/3da27b/32.png) [@zeroangel](https://forum.rasa.com/u/zeroangel)\
**Post date:** [July 12, 2020, 8:46pm UTC](https://forum.rasa.com/t/context-switching/20589/7 "2020-07-12T20:46:01Z")

</div>

I was not a part of the team that coded the dialogue manager and I have moved onto another project at this point (mercifully TBH, I did not agree with the solution). I believe it was if/else/then but I am not certain.

---

<div class="post-metadata">

**Author:** ![noman](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/noman/32/10071_2.png) [@noman](https://forum.rasa.com/u/noman)\
**Post date:** [July 12, 2020, 10:28pm UTC](https://forum.rasa.com/t/context-switching/20589/8 "2020-07-12T22:28:22Z")

</div>

@v5out not many if-then statements. We have devised some rules for the handling the conversation gracefully. like if a form action for order food has been triggered and in between filling this form, user changes its mind and wants to book a flight, we show him a yes-no button to the user that asks if he really wants to end the current inquiry? if he says yes then it means he don’t want to proceed with the order, at this point we end the form. while if he start asking FAQs during order food we allow him for two times but for the 3rd time we ask him if he wants to continue with the order food or not? if he says yes we put the user back to the form otherwise exit the form. and to handle all of this we are using mapping policy
