Starting and navigating sessions
A session is one execution of a graph. Your application starts it, presents the current step and sends the edge selected by the user or by its own logic. ExecKernel checks that choice and returns the resulting state together with the data needed to present it.
This guide follows that exchange using the PHP engine directly. You need a configured ExecKernel instance in $engine and a loaded Graph in $graph. Loaders and repositories explains how to obtain the graph; here we will concentrate on what your application does with a running session.
The process we will navigate
Section titled “The process we will navigate”We will reuse the learning choice from Anatomy of a graph. It starts at node 10. Edge 101 selects a reading guide and reaches terminal node 20. Edge 102 selects browser practice and reaches terminal node 30; it requires practiceEnabled: true in the session context.
The complete graph definition contains both English and Spanish presentation text. The complete navigation example loads that definition and assembles the calls below in an application with ExecKernel installed. Its only setup is the Composer autoloader, graph loader and engine factory.
Start with the values the application knows
Section titled “Start with the values the application knows”To start, provide the graph, a supported presentation language and the initial context:
use ExecKernel\Domain\Session\Context;
$started = $engine->start( $graph, 'en', new Context(['practiceEnabled' => true]),);
$state = $started->state;$payload = $started->payload;start() returns an EngineResult. Its state is the session’s execution state: the current node, context, history, timestamps and graph revision. Its payload describes what your application can present at that point. Keeping those roles separate lets your application render a screen without treating the screen data as the session itself.
Here, the current node is 10. The history already contains that root node and no selected edges. The payload has type: "node" and two entries in edges, identified by 101 and 102. With this initial context, both have availability: "available".
Your application can turn the labels into buttons, menu entries or another interaction. It must keep the associated edge ID: choosing a label means sending the ID of the edge, not its destination node.
Refresh the options at the same position
Section titled “Refresh the options at the same position”Your application may need to render the current step again, for example after reopening a panel. It can ask for a new payload from the state it already has:
$payload = $engine->getPayload($graph, $state, 'en');This returns a payload array. It does not select an edge or return a replacement session state. The current node, history and context in $state remain unchanged.
A fresh payload is useful because availability is evaluated for the current inputs and time. The previous display is not a reservation of an edge. Condition evaluation and edge availability explains the available, blocked and pending values and what your interface can infer from them.
Choose the edge and adopt the returned state
Section titled “Choose the edge and adopt the returned state”Suppose the user selects Read the guide. Your application sends edge 101 with the state from which that option was presented:
$chosen = $engine->choose($graph, $state, 101, 'en');
$state = $chosen->state;$payload = $chosen->payload;The assignments happen after choose() returns successfully. ExecKernel checks the current position and the applicable rules before producing the next state. For this choice, that state is at node 20, its selected-edge history is [101] and its visited-node history is [10, 20]. The original state object remains unchanged.
If choose() throws, these assignments do not run. Handle the cause using Rejected transitions and error recovery, where a rejected calculation is distinguished from a failure while saving or delivering its result.
Use the terminal result in your application
Section titled “Use the terminal result in your application”The returned payload now has type: "terminal". The graph’s guide terminal provides two outputs: explanatory content and a URL with a label. Your application decides how to present them, such as a completion panel with an Open the guide link.
A terminal ends navigation for that session. There are no further choices from that node, and trying to choose another edge is rejected. Reaching it does not itself open a browser, send a message or run an application action. Terminal outputs explains how to interpret those output records.
If your product offers a new attempt, start another session deliberately. Calling resume() on the completed one keeps its terminal position.
Recover the session you already have
Section titled “Recover the session you already have”Between requests, your integration needs to retain the session state. The engine calls above calculate results; they do not choose a storage backend or save the state for you. Your application or session service associates the state with its session identifier and handles persistence.
For a simple trusted server-side snapshot, the state can be represented as an array:
$snapshot = $state->toArray();Later, after your application retrieves that snapshot, it can restore the state and ask the engine to present it again:
use ExecKernel\Domain\Session\SessionState;
$restoredState = SessionState::fromArray($snapshot);$resumed = $engine->resume($graph, $restoredState, 'en');
$state = $resumed->state;$payload = $resumed->payload;In this example, the restored state is still at node 20, with edge 101 in its history. resume() checks the session and graph compatibility and rebuilds the presentation. It does not replay the choice or restart at the root.
The example assumes that $snapshot came from your own server-side storage. An integration using a session store or an integrity policy should recover through that integration’s validation path; do not reconstruct execution state from fields posted by a browser. State serialization and integrity covers that boundary.
Saving and confirming a result is also a separate step from calculating it. If the application must publish effects only after a successful save, use the confirmation boundary explained in Execution lifecycle and confirmed state. An in-memory variable assignment alone does not establish that the result will survive the next request.
Watch the exchange in the browser
Section titled “Watch the exchange in the browser”The Graph basics demo lets you navigate another small graph. Select an option and observe how the current node and highlighted edges change. The useful connection is the same as in this guide: the application sends a choice, and the engine returns the next state and its presentation data.
To collect new values during that exchange, continue with Context updates and candidate values.