Context in Conversational Interaction
How contexts function and are used as the memory of a conversation to provide precise responses and tailor interactions
Contexts serve as the ‘memory’ of a conversation. Information is recorded in the form of labelled tags that store specific details, such as a name or a location, for use later in the conversation. This enables the AI chatbot to provide personalised and conclusive responses, even when users submit incomplete queries.
Once information has been stored in the context, it can be retrieved at any point within the moinAI Hub, for example, by AI agents, in forms or via webhooks, and used to personalise the conversation flow.
1. Provide contextual information
To enable the AI chatbot to access contextual information, this must be provided in one of the following ways:
-
Via the website (Widget API): Information such as name, login status or the currently visited subpage is passed directly to the AI chatbot via a code snippet when the chat begins.
-
Via the conversation (forms): Details that users actively enter into a form are automatically saved in the context and are available for subsequent steps.
-
Via external systems (webhooks): Data from third-party systems (e.g. an order number from a CRM) can be loaded into the context via a webhook.
Types of contextual knowledge
Contexts enable users to be guided more precisely across various application areas by using information specifically to control processes. Typical categories of contextual data include:
-
User attributes: name, customer number, login status or order history.
-
Product information: details of the product page currently being viewed, items in the shopping basket or specific cancellation deadlines.
-
Location & system: The current subpage, the country, the branch or technical data such as the
uniqueUserID.
This data serves to personalise the interaction flow without having to request information that is already available.
Contexts act as a memory for the duration of a session. As soon as the session expires, this information is deleted.
2. Set up contexts
Data is provided in various ways, depending on when the information is required during the conversation.
It is recommended that context variables be named consistently and in lower case (e.g. user_name instead of User_Name) to avoid errors when referencing them.
Via forms (Automatic)
Information requested within a form is automatically incorporated into the context. After creating a form in the Forms section, the desired query fields (e.g. a multiple-choice question asking for a category) are defined. Each user input is then saved as context and can be processed further in subsequent steps, e.g. by an AI agent.
How to create forms is described in this article.
Via Webhooks (External)
Data can be retrieved from external databases or CRM systems and stored in the context. To do this, first configure a webhook under Integrations → Webhooks. Specifying a context name determines the label under which the external system’s response is stored. The received data (e.g. an order_id) is then available for further use.
The use of a webhook is described in this article.
Via the Widget API (Programmatically)
If information needs to be available at the start of or during a visit to the website, it can be passed to the AI chatbot using the addContext method.
addContext must be executed using a chatWidgetReady hook. Further information on this can be found in the ‘Getting Started’ section of this technical documentation.
Once the chat widget’s integration code has been incorporated into the page’s source code, snippets can be used to pass data such as the name. After defining the required variables (e.g. user_name) on the website, a corresponding code snippet is embedded into the page’s source code:
// Example of dynamically passing a variable
window.moin.addContext({ user_name: nameVariable });
The set value is then available to the AI chatbot for the duration of the entire session.
As this involves technical changes to the website, it is advisable to pass this information on to the relevant IT department. Detailed technical information on the Widget API can be found in the Developer Documentation.
You can find out more about practical widget integration in this article.
3. Use in the moinAI Hub
Once data is available in the context, it can be utilised in various places within the moinAI Hub.
Use in texts and responses
The data is embedded using Handlebars syntax with double curly brackets. For example, a greeting such as ‘Hello {{user_name}}’ can be personalised for each user.
Use for AI agents and AI actions
AI agents access the context to generate more precise responses. The AI agent’s instructions specifically refer to the context variables for this purpose (e.g. “Take the user’s branch into account when responding”). When executing an AI action, such as a CSV-based search, the AI agent uses the available context data to narrow down the results precisely.