Skip to content

Context, session state and history

A session’s state describes its progress through a graph. It includes the current node, the context used to evaluate choices, and the history of nodes and edges already visited. These parts answer different questions: where is the session, what data does the engine have for its decisions, and how did it get here?

Keeping those questions separate helps your application continue a process correctly. A new value can change whether a choice is allowed without changing the session’s current position. Only an accepted choice moves it along an edge.

We will use the workshop example introduced in Graph-based execution model. Someone has chosen in-person attendance and reached node 200, where they can select the Valencia venue through edge 201. For this illustration, that edge requires the context value placesAvailable to be true.

This extract shows the relevant fields of a session at that step:

{
"current_node": 200,
"context": {
"placesAvailable": false
},
"history": {
"nodes": [100, 200],
"edges": [101]
}
}

The current node tells your application that the session is at the venue-selection step. The context says that places are unavailable, so the Valencia choice does not currently satisfy its condition. The history records how the session arrived: it started at node 100 and followed edge 101 to node 200.

The context contains values supplied to the execution. A condition can use a boolean such as placesAvailable, a quantity or another relevant value to decide whether an edge can be followed. Your application obtains those values and gives them to the engine; their names and meaning belong to your process.

The history serves a different purpose. It records the route, including the starting node. It can help your application show the steps taken or understand how a session reached its current position. It does not keep earlier versions of the context: the route alone will not tell you every value that changed along the way.

Checking proposed data before making a choice

Section titled “Checking proposed data before making a choice”

Suppose your application checks venue availability again and now finds a place. It can ask the engine what choices would be available with placesAvailable: true before requesting a move.

For that evaluation, the engine combines the proposed values with the existing context. In this example, the Valencia condition passes with the new value. The original state still says node 200, placesAvailable: false, and history [100, 200]. The check has answered a question about a possible choice; it has not taken it.

Current state at node 200 with placesAvailable false. A preview evaluates the proposed true value and finds edge 201 available while leaving the current state intact. Choosing edge 201 with that value returns a new state at node 300 and extends the history.

If your application decides to continue, it supplies the new value with the choice of edge 201. The engine evaluates the choice and, if it accepts it, returns a new state containing the updated context and the extended route:

{
"current_node": 300,
"context": {
"placesAvailable": true
},
"history": {
"nodes": [100, 200, 300],
"edges": [101, 201]
}
}

The three changes belong to that accepted step: the position is now terminal 300, the context contains the value used for the choice, and the history includes the edge and destination.

A preview does not save its proposed values for a later choice. If your application checks with placesAvailable: true and then makes the choice using only the original context, the engine still sees false and rejects that choice. Supply the intended values when you request the move.

An accepted operation returns a new state; it does not rewrite the original state object. Your application or its integration must retain the result to continue from the new position. If the choice is rejected, the original state remains the starting point.

Execution lifecycle and confirmed state explains when that result is saved and who coordinates the operation. For the calls used to supply context in an application, see Context updates.