Context¶
The Context Object is a JSON object that persists throughout the entire chat or call session. If a user disconnects from Cognigy.AI, the Context object can be retrieved upon reconnection with the same session ID. By default, the Context object is empty. You need to set a Default Context or configure what data is stored in this object.
Nodes can access the Context object and store information in it, for example, user messages, Slots, Intents, or any other data available throughout the session.
Limitations¶
- You can store up to 1.5 MB in the Context object. For dedicated SaaS and on-premises installations, you can configure the limit using the
MAX_MEMORY_OBJECT_SIZE
variable in thevalues.yaml
file. Increasing the object size could lead to performance issues.
Working with the Context Object¶
Interaction Panel
You can view the Context object by navigating to Info > Context in the Interaction Panel. In the Context tab, you can save, cancel, or reset the Context object by clicking the respective buttons at the bottom of the Interaction Panel. The changes to the values in the Context object apply only to the current session.
You can copy the exact JSON path of a Context object value by right-clicking it and selecting Copy JSON Path.
Flow Editor
In the Flow editor, you can set a Default Context in the Settings tab.
You can inject data into and reset the Context object of a session with the Cognigy.AI API.
Default Context¶
The Default Context is the Flow's Context object when the user triggers the Flow execution for the first time. By default, the Default Context is empty, and you can customize it in the Settings tab of the Flow editor.
A session inherits the Default Context from the Flow in which this session starts. If the user switches to another Flow during the session, the Context object remains the same. However, you can apply the Default Context of the target Flow with the Go To Node. To do so, activate the Absorb Context parameter in the Go To Node settings that switches to the target Flow.
Storing Information in the Context Object¶
Nodes, such as the Add To Context, AI Agent, Question, and others, include different parameters to store information in the Context object.
Accessing the Context object¶
Use Nodes to dynamically access Context properties with CognigyScript, for example, {{context.property}}
, or Tokens. The CognigyScript expression used to access the Context object follows the dot notation property.child.child
.
Example¶
Consider the following Context object:
Context Object Example
{
"order": {
"id": "ORD-2023-1234",
"items": [
{
"name": "Margherita Pizza",
"category": "food",
"size": "large",
"quantity": 1,
"price": 15.99
},
{
"name": "Caesar Salad",
"category": "food",
"size": "regular",
"quantity": 1,
"price": 8.99
},
{
"name": "Coca Cola",
"category": "drink",
"size": "medium",
"quantity": 2,
"price": 2.99
}
],
"subtotal": 30.96,
"tax": 2.48,
"deliveryFee": 5.00,
"total": 38.44,
"deliveryAddress": "123 Main St, Apt 4B",
"orderTime": "2023-10-25T19:30:00Z",
"status": "preparing"
}
}
{{context.order.items[0].price}}
returns the price of the first item in the order.{{context.order.items[1].name}}
returns the name of the second item in the order.{{context.order.items[2].quantity}}
returns the quantity of the third item in the order.