Skip to content

πŸ† Levels and Game Flow

Peter Marsh edited this page Feb 19, 2024 · 1 revision

Since each level follows the same shape (chat to chat bot, find out secret information, email it), we can reuse the same functionality on the frontend and backend on every level. So then what's different between levels?

Switching between Levels

The browser is responsible for keeping track of the currentLevel in local storage. When the user selects a new level, we update this value. A copy is kept in the component state as well. This currentLevel is passed to the backend whenever we make a request, which is how it knows what level the user is on and can act accordingly.

Now, the backend is responsible for keeping track of the state of every level. This is kept in session storage, in an array of LevelStates (see sessionRoutes.ts). One LevelState holds the chat history, sent emails and configured defences for one level.

When the user selects a different level, the frontend must request the level state for that level so that the chat history, sent email and configured defences can be shown on the UI.

The Win Condition

The user wins a level if they send an email to the correct email address containing the right word, phrase or value. In the backend, once an email has been sent, we use checkLevelWinCondition which checks the currentLevel value that was given in the 'send message' request body. If the email satisfies the win condition for the current level, then we return wonLevel: true in the response body to the front end.

The System Role

The system role guides the model's behaviour throughout the conversation. It is essentially the model's initial instruction, which sets the scene for he conversation and lets the bot know if it should adopt a persona, what kind of answers to give and how to behave. See some system role examples here. In our app, we have a different system role for each level, which allows us to modify each level's difficulty. The system roles we use are defined in promptTemplate.ts.

The Available Documents

We provide a set of documents to the bot for querying (see Langchain/Querying Documents for technical details). The documents contain information about our fictional company ScottBrew, as well as the secret information that the user must uncover to win the level.

The documents are kept in backend/resources/documents. For each level there is a folder containing documents specific for that level, and there is also the common folder containing documents that are available across all levels.

Applying Defences

When the user sends the bot a chat message, defences are only applied on level 3 and the sandbox. In handleChatToGPT (chatController.ts) we check the currentLevel value in the request body to determine whether we get a response via handleChatWithoutDefenceDetection or handleChatWithDefenceDetection.