Skip to content

Terminal outputs

A terminal output describes information that your application can use when a graph finishes: content to display, a link to offer or a destination to open. You attach the output to a terminal node, and ExecKernel includes it in the payload when the session reaches that node.

The terminal determines where navigation ends. Its outputs describe what the application receives there. A terminal can have several outputs or none, and it can also have its own title and description through node metadata.

We will use the learning-path graph from Anatomy of a graph. Edge 101 selects the guide and reaches terminal 20. Edge 102 selects browser practice and reaches terminal 30 when practiceEnabled is true. The complete definition contains both results.

Choose what the application should receive

Section titled “Choose what the application should receive”

ExecKernel provides four built-in output types:

Type Required result data How your application can use it
content content Display a message or other returned content.
url url Offer a link that the person can choose to open.
redirect url Navigate to the returned destination according to the application’s flow.
mixed content and url Present content and a related destination from one output.

content and url must contain non-empty strings where the type requires them. The type tells the application how to interpret the result. Your application builds the interface and performs any navigation.

A label can supply the text for a link or action. It is optional; the application can provide its own wording when it is absent. open_behavior is another optional field carrying an opening preference. The application decides how to apply that preference.

The guide terminal declares two English outputs, in the order the application will receive them:

{
"outputs": [
{
"node_id": 20,
"type": "content",
"lang": "en",
"content": "Read the guide at your own pace."
},
{
"node_id": 20,
"type": "url",
"lang": "en",
"url": "https://example.org/learning/guide",
"label": "Open the guide"
}
]
}

node_id binds both records to terminal 20. The first provides the instruction; the second provides a destination and action text. The URL uses example.org to illustrate a destination: replace it with a real route in your application.

To obtain that result, the application requests edge 101. In this fragment, $graph is the loaded example, $engine is the configured engine and $state is a session at root node 10:

$finished = $engine->choose($graph, $state, 101, 'en');
$outputs = $finished->payload['outputs'];

The accepted choice moves the returned state to terminal 20. The payload contains the terminal’s metadata and the selected outputs. This extract shows the fields relevant to the view, omitting unused fields:

{
"type": "terminal",
"node_id": 20,
"title": "Guide selected",
"outputs": [
{
"type": "content",
"lang": "en",
"content": "Read the guide at your own pace."
},
{
"type": "url",
"lang": "en",
"url": "https://example.org/learning/guide",
"label": "Open the guide"
}
]
}

The application can put the title above the result, display the content as a paragraph and turn the URL into an “Open the guide” link. It handles the user’s click with its usual navigation code.

Terminal 30 declares a redirect output:

{
"outputs": [
{
"node_id": 30,
"type": "redirect",
"url": "https://example.org/learning/practice"
}
]
}

After the application successfully requests edge 102, the resulting payload contains this destination. The application can use it to move to its practice screen. ExecKernel returns the instruction as data; navigation happens when the application’s code acts on it.

This record omits lang, so it is language-neutral. The payload returns lang: null, and the same destination can accompany either the English or Spanish terminal title.

The following views illustrate the distinction between offering a link and using a navigation destination:

Illustrative application behaviour. At terminal 20, content supplies a paragraph and url supplies an Open the guide link. At terminal 30, redirect supplies the practice destination and the application performs navigation.

If a message and a URL belong to one result, mixed carries both in a single record. For example, the following record can replace the two English outputs of terminal 20:

{
"node_id": 20,
"type": "mixed",
"lang": "en",
"content": "Read the guide at your own pace.",
"url": "https://example.org/learning/guide",
"label": "Open the guide"
}

The terminal payload then contains one output with type: "mixed" and those content and URL fields. The application can render them together as a result card. Separate content and url records are also valid when the application should process them independently.

Within a terminal, selected outputs keep their declaration order. In the complete example, requesting English at terminal 20 returns its English content followed by its English URL; requesting Spanish returns “Lee la guía a tu ritmo.” followed by “Abrir la guía”.

Language selection works on the terminal’s group of localized outputs. ExecKernel uses the requested language if that group exists, otherwise the graph’s default language if present, otherwise the first available localized language. Language-neutral outputs are included alongside the selected group, in their original positions.

This has a practical consequence for incomplete translations. If you declare Spanish content for terminal 20 but omit its Spanish URL, a Spanish request returns that content alone. It does not add the English URL to complete the group. Declare the outputs needed for each language your application offers. Labels, metadata and languages explains the separate check for an allowed request language.

Remove the guide’s outputs and edge 101 still ends at terminal 20. Its payload has type: "terminal" and outputs: []; the node’s metadata can still describe the result.

Your application should recognise completion from the terminal type. It can present that metadata or its own completion view even when there is no output to process.

In Terminal outputs, choose an output type and compare the result with the SDK payload. Use Reset to try another type and EN/ES to inspect localization. The demo keeps navigation under your control: it opens a destination only when you choose to do so.

For the full returned structure, see Node and terminal payloads. To introduce a type specific to your application, continue with Custom terminal output types.