Delegation Router
RouterAgent directs incoming tasks to specialized subagents using gemini-3.8-flash. The system performs tool-free triage by evaluating the task against the natural-language description field of each declared specialist.
syndicate_name: "Delegation Router Workflow"
variables:
# Example variables
domain: "general knowledge"
orchestrator:
name: "RouterAgent"
model: "gemini-3.8-flash"
instruction: |
You are a triage router.
You do NOT answer questions directly if they require specialized knowledge.
Instead, you examine the user's request and delegate to the appropriate specialist:
- If the user asks a coding or programming question, delegate to CodeExpert.
- If the user asks a math or calculation question, delegate to MathExpert.
- If it's a general greeting or unrelated to those domains, answer it yourself concisely.
subagents:
- name: "CodeExpert"
model: "gemini-3.8-flash"
description: "Expert in programming, software development, and debugging."
instruction: |
You are an expert programmer. Provide clean, correct, and well-documented code answers.
- name: "MathExpert"
model: "gemini-3.8-flash"
description: "Expert in mathematics, formulas, and calculations."
instruction: |
You are a math expert. Solve equations and explain the steps clearly.
Recorded trace
Captured directly from the engine with in-memory sessions and telemetry turned off. The diagram above replays the execution path across each participating star.
RouterAgent received the prompt and routed the query to CodeExpert. Running on gemini-3.8-flash, the execution completed in 9.6 seconds.
- you
Why does JavaScript sort put 10 before 9 when sorting numbers, and what is the fix?
- α RouterAgent to β CodeExpert
Why does JavaScript sort put 10 before 9 when sorting numbers, and what is the fix?
- β CodeExpert back to α RouterAgent
### Why This Happens By default, JavaScript's `Array.prototype.sort()` converts all array elements to **strings** and sorts them in **lexicographical (alphabetical) order** based on UTF-16 code unit values. When sorting `[10, 9]`: 1. The numbers are converted to strings: `"10"` and `"9"`. 2. The comparison starts at the first character: `"1"` vs `"9"`. 3. Because the character code for `"1"` (`0x31` / `49`) is smal…
### Why This Happens By default, JavaScript's `Array.prototype.sort()` converts all array elements to **strings** and sorts them in **lexicographical (alphabetical) order** based on UTF-16 code unit values. When sorting `[10, 9]`: 1. The numbers are converted to strings: `"10"` and `"9"`. 2. The comparison starts at the first character: `"1"` vs `"9"`. 3. Because the character code for `"1"` (`0x31` / `49`) is smaller than the character code for `"9"` (`0x39` / `57`), JavaScript considers `"10"` to be smaller than `"9"`. --- ### The Fix To sort numbers numerically, you must pass a **compare function** (`compareFn`) to `.sort()`. The compare function takes two arguments, `a` and `b`: * If it returns a value **less than 0**, `a` is placed before `b`. * If it returns **0**, their relative order remains unchanged. * If it returns a value **greater than 0**, `b` is placed before `a`. …
- α RouterAgent
### Why This Happens By default, JavaScript's `Array.prototype.sort()` converts all array elements to **strings** and sorts them in **lexicographical (alphabetical) order** based on UTF-16 code unit values. When sorting `[10, 9]`: 1. The numbers are converted to strings: `"10"` and `"9"`. 2. The comparison starts at the first character: `"1"` vs `"9"`. 3. Because the character code for `"1"` (`49`) is smaller than `"9"` (`57`), JavaScript places `"10"` before `"9"`. --- ### The Fix To sort numbers numerically, provide a **comparison function** to `.sort()`. The function takes two elements, `a` and `b`: * Returning a **negative value** places `a` before `b`. * Returning **0** keeps their order unchanged. * Returning a **positive value** places `b` before `a`. #### Ascending Order (Smallest to Largest) Subtract `b` from `a`: ```javascript const numbers = [10, 9, 2, 35, 1]; numbers.sort((a, b) => a - b); console.log(numbers); // Output: [1, 2, 9, 10, 35] ``` #### Descending Order (Largest to Smallest) Subtract `a` from `b`: ```javascript const numbers = [10, 9, 2, 35, 1]; numbers.sort((a, b) => b - a); console.log(numbers); // Output: [35, 10, 9, 2, 1] ``` --- ### Note on Mutability `Array.prototype.sort()` sorts the array …
### Why This Happens By default, JavaScript's `Array.prototype.sort()` converts all array elements to **strings** and sorts them in **lexicographical (alphabetical) order** based on UTF-16 code unit values. When sorting `[10, 9]`: 1. The numbers are converted to strings: `"10"` and `"9"`. 2. The comparison starts at the first character: `"1"` vs `"9"`. 3. Because the character code for `"1"` (`49`) is smaller than `"9"` (`57`), JavaScript places `"10"` before `"9"`. --- ### The Fix To sort numbers numerically, provide a **comparison function** to `.sort()`. The function takes two elements, `a` and `b`: * Returning a **negative value** places `a` before `b`. * Returning **0** keeps their order unchanged. * Returning a **positive value** places `b` before `a`. #### Ascending Order (Smallest to Largest) Subtract `b` from `a`: ```javascript const numbers = [10, 9, 2, 35, 1]; numbers.sort((a, b) => a - b); console.log(numbers); // Output: [1, 2, 9, 10, 35] ``` #### Descending Order (Largest to Smallest) Subtract `a` from `b`: ```javascript const numbers = [10, 9, 2, 35, 1]; numbers.sort((a, b) => b - a); console.log(numbers); // Output: [35, 10, 9, 2, 1] ``` --- ### Note on Mutability `Array.prototype.sort()` sorts the array **in place** (mutating the original). If you want a new array without modifying the original: * **ES2023+:** Use `toSorted()`: ```javascript const sorted = numbers.toSorted((a, b) => a - b); ``` * **Earlier versions:** Copy the array first: ```javascript const sorted = [...numbers].sort((a, b) => a - b); ```