Advanced – many questions in one request
The Advanced node asks Laya many questions about the same text in one request: any mix of yes/no (noul), choice and score questions. Because all questions share one request, seven questions take hardly longer than one. In our demo, seven decisions per e-mail took about 30–40 ms in the robot.
At a glance
- Question types: noul choice score – mixed, up to 64 per request
- Questions written in: JSON or JavaScript, in Laya’s own format
- Values from the message:
{{field}}placeholders - Result: Laya’s answer unchanged, one entry per question
- Batch mode: supported
When to use Advanced
- You want to know several things about the same text: department, topic, urgency, sentiment, refund, cancellation …
- You want to check answers against each other. Example: ask for the topic and the department separately and only continue automatically if both fit together.
- The questions or choices are built dynamically from the message.
- You need a Laya feature that the simple nodes do not expose. Every option of Laya’s question format is passed through.
Settings
Input
| Field | Default | Description |
|---|---|---|
| Text | msg.text | The text or object all questions refer to. In batch mode a list or an object of records. |
Output
| Field | Default | Description |
|---|---|---|
| Result | msg.laya | Laya’s full answer with one entry per question in answers. See Result. |
Options
| Option | Default | Description |
|---|---|---|
| Batch | off | On: Text holds many records and every record gets all questions. See Batch mode. |
| Questions | example (commented out) | The questions. Double-click the node to open the large code editor. |
| Min Confidence (optional) | empty | Laya’s own threshold for all questions. Answers below it get "low_confidence": true. Not available in batch mode. |
Connection options: Model, Server URL, API Key, Timeout
| Option | Default | Description |
|---|---|---|
| Model | Auto | Laya model. Auto picks by language. |
| Server URL | http://127.0.0.1:8000 | Address of the Laya server. |
| API Key (optional) | empty | Vault item with the key, only if the server uses LAYA_API_KEY. |
| Timeout (sec) | 30 | Maximum wait for Laya. |
These options are the same for all Laya nodes. Details in the overview.
Writing the questions
Double-click the node to open the editor. A new node contains an example inside /* … */. To use it, delete the two lines with /* and */.
📷 Image placeholder: Screenshot of the Advanced node’s code editor with the example questions.
Format
The questions are an object. Each key is a name you choose. It appears again in the result. Each value describes one question in Laya’s format:
{ "department": { "type": "choice", "instructions": "Which department is responsible?", "criteria": { "Sales": "offers and prices", "Support": "technical problems and login", "Billing": "invoices, payments and refunds" } }, "urgency": { "type": "score", "instructions": "How urgent is the request?", "criteria": ["not at all", "slightly", "moderately", "very", "extremely"] }, "refund": { "type": "noul", "instructions": "Does the customer ask for a refund?" }}
| Key | Required | Meaning |
|---|---|---|
type | yes | noul (yes/no), choice (pick one) or score (rate on a scale) |
instructions | yes | The question text. |
criteria | for choice and score | choice: a list of names ["Sales", "Support"] or an object name → description.score: a list of levels from lowest to highest. |
Up to 64 questions per request. The node only checks type and instructions. Everything else is checked by Laya, which explains its reason if something is wrong. The rules from the single nodes apply here too: see Choice for good choices and Score for good levels.
Advanced does not add route to yes/no answers. Compare noul yourself, for example msg.laya.answers.refund.noul >= 0.85.
Placeholders: values from the message
Write {{field}} or {{msg.field}} anywhere in a text, like in Robomotion’s SQL nodes. Nested fields work with dots: {{customer.name}}.
{ "topic": { "type": "choice", "instructions": "What is the message about {{product}}?", "criteria": "{{categories}}" }}
| Placeholder is … | What happens | Field missing |
|---|---|---|
part of a text"… about {{product}}?" | The value is inserted: “What is the message about HX-200?” | becomes empty text |
the whole value"{{categories}}" | The original value is used, including lists and objects. | the node stops with an error |
JavaScript
The editor also accepts JavaScript, like the Function node. msg is available. You can either write an expression that results in the object, or a function body with return:
var q = { urgency: { type: "score", instructions: "How urgent is the request?", criteria: ["not at all", "slightly", "moderately", "very", "extremely"] }}; // add a refund question only for e-mails to the shop addressif (msg.email.to === "shop@example.com") { q.refund = { type: "noul", instructions: "Does the customer ask for a refund?" };} return q;
The code must finish within 2 seconds.
Result
Result is Laya’s full answer, unchanged. Access the answers by the names you chose:
msg.laya.answers.department.choice // "Billing"msg.laya.answers.urgency.score // 3.1msg.laya.answers.refund.noul // 0.98
Show the full answer
{ "model": "laya-rl-agent", "answers": { "department": { "type": "choice", "choice": "Billing", "probabilities": { "Sales": 0.0001, "Support": 0.0002, "Billing": 0.9997 }, "confidence": 0.997, "answer_confidence": 0.9997, "action": { "act_probability": 1.0 } }, "urgency": { "type": "score", "score": 3.1, "legend": { "0": "not at all", "1": "slightly", "2": "moderately", "3": "very", "4": "extremely" }, "probabilities": { "0": 0.01, "1": 0.05, "2": 0.17, "3": 0.36, "4": 0.41 }, "confidence": 0.4, "answer_confidence": 0.41, "action": { "act_probability": 1.0 } }, "refund": { "type": "noul", "noul": 0.98, "confidence": 0.98, "answer_confidence": 0.98, "action": { "act_probability": 1.0 } } }, "usage": { "input_tokens": 226, "truncated": false, "...": "…" }, "routing": { "model": "multilingual", "...": "…" }}
The meaning of each field is described in the Noul, Choice and Score articles.
Example: self-check with two questions
Ask for the topic and the department separately. Only if both fit together, the message is routed automatically. Otherwise a human decides.
This catches many wrong answers at almost no extra cost. In our demo with 1,000 e-mails, about half went through automatically, and 91 % of those were correct (72 % without the self-check).
// Function node after Advancedvar A = msg.laya.answers;var departmentOf = { "Double charge": "Billing", "Login problem": "Support", "Price quote": "Sales"}; if (departmentOf[A.topic.choice] === A.department.choice) { msg.route = A.department.choice;} else { msg.route = "Human review";} return msg;
Batch mode
With Batch on, every record in Text gets all questions. This is the fastest way to process many texts: our demo flow handled 1,000 e-mails with 7 questions each in about 17 seconds.
Step 1 – build one record per e-mail in a Function node before Advanced:
msg.records = {};msg.emails.forEach(function (e) { msg.records[String(e.id)] = { subject: e.subject, body: e.body };});return msg;
Step 2 – set Text to msg.records and turn on Batch.
Step 3 – read the results. They keep the IDs:
msg.laya["17"].answers.department.choice
Loop over the results in one Function node instead of looping over the Laya node. With a list as input, the result is a list in the same order. Up to 64 records go into one request, more are split automatically.
Min Confidence must be empty in batch mode. Compare answer_confidence yourself instead.
Errors
| Message | Cause and fix |
|---|---|
No questions entered. Double-click the node to open the editor. | The editor is empty or contains only comments, for example the unchanged example in /* … */. |
Error in code: … | Syntax error in the JSON or JavaScript. The message usually shows the position of the error. |
Expected an object: { "name": { "type": "noul", "instructions": "…" } } | The editor does not result in an object, for example a list or a number. |
Question …: Laya calls the question "instructions" (and options or levels "criteria") | The question uses question, options or levels. Rename them to instructions and criteria. |
Question …: "type" must be "noul", "choice" or "score" | Unknown or missing type. |
Question …: "instructions" is missing | The question text is empty. |
Placeholder {{…}}: this field does not exist in the message | A placeholder used as a whole value points to a missing field. |
Laya accepts at most 64 questions per request | Split the questions into two Advanced nodes. |
time limit of 2 seconds exceeded | The JavaScript runs too long, for example an endless loop. |
Laya returned no answer for … | Laya skipped a question. Check the Laya server log. |
Laya reported error 4xx: … | Laya rejected a question, for example a choice question without criteria. The message contains Laya’s reason. |
Connection, timeout, API key and batch errors are the same for all nodes. See Laya package – overview and setup.