Skip to main content
Back to how-to guides Use this pattern when the route depends on data your project already holds about the customer, such as account tier, open case, fraud risk, entitlement, or a remembered preference. The customer’s words do not decide the route.

Concept

A supervisor can route on data it loads before the first routing decision. Two sources work. Each HANDOFF has a WHEN condition. The platform evaluates a WHEN written as an expression before the model reasons. It checks the routes in the order you write them. The first route that matches takes the conversation. A PRIORITY value changes the order, and the lowest number runs first. A route with a quoted plain-language WHEN stays with the model. Use one as the last route for every customer that no expression matched. A comparison on a missing value is false. If the lookup fails, no expression route matches and the model chooses the plain-language route. You do not need to copy the tool result into session variables first. A route reads profile.tier directly.

Minimal working example

This example routes on a profile lookup. It sends high-risk customers to fraud review first, then customers with an open case, then premium customers. For everyone else, including customers the lookup could not find, the model chooses the standard route. The supervisor needs the specialist agents in the same project. The lookup tool needs an execution binding in your project, such as an HTTP endpoint. session.customerId is the customer identifier that the channel resolved when it authenticated the user.
These four stand-in agents let the project compile. Save each one in its own file and replace them with your real specialists.

How it works

  • ON_START runs the CALL before the first routing check. Indent WHEN under CALL. WHEN: session.customerId IS SET skips the lookup for anonymous sessions.
  • AS: profile stores the tool result. If the call fails or does not run, profile stays unset and all three expression routes are false.
  • On each customer message, the platform checks the expression routes in order before the model reasons. The fraud route comes first, so risk wins over tier.
  • profile.has_open_case == true matches only a boolean true. A tool that returns the string "true" does not match.
  • The last route has a quoted plain-language WHEN. The model chooses it when no expression route matched.
  • Write quoted text in plain lowercase words. The platform evaluates quoted text as an expression, not as guidance, when it contains uppercase AND, OR, or NOT. It does the same for a symbol such as == or >, and for the words contains, matches, startsWith, or endsWith.
  • The specialists use RETURN: false, so each one keeps the conversation after the transfer.
  • A HANDOFF entry without HISTORY gives the specialist the full conversation history. A project-level coordination default can change this value.
  • The tool is read-only. side_effects: false and confirm: never mark it as a lookup that never asks the customer for confirmation. hints.timeout is a number of milliseconds. The welcome and the first routing check wait for the tool, so keep it fast.

Common variations

Pass the lookup result to the specialist

Add PASS to a route when the specialist needs the profile. The specialist receives the profile object.
A dotted name such as profile.tier compiles to its root field profile. List the root field.

Route on remembered state

Use this variation when an earlier session or an integration stored the value. This example assumes that a REMEMBER rule or the memory API saved user.loyalty_tier for the customer.
The route conditions have the same shape as in the lookup example. A session with no stored value, such as an anonymous or first-time customer, leaves user.loyalty_tier empty. The gold route is then false and the model chooses the standard route. Declare the path with ACCESS: read and a RECALL entry. Without the RECALL, the compiler warns with INERT_PERSISTENT_MEMORY_DECLARATION.

Verification

Run one session for each outcome and inspect the trace.
  1. Start as a customer with a high fraud risk. Expect Fraud_Review_Agent.
  2. Start as a customer with an open case and a low fraud risk. Expect Existing_Case_Agent.
  3. Start as a premium customer with no open case. Expect Premium_Service_Agent.
  4. Start as any other customer. Expect Standard_Service_Agent.
  5. Start anonymously, with no session.customerId. Expect Standard_Service_Agent and no lookup call.
  6. Make the tool fail. Expect Standard_Service_Agent.
In the trace, check these events.
  • dsl_lifecycle_call_condition shows whether the lookup ran. tool_result shows what the tool returned.
  • deterministic_routing shows the matched expression route, with its condition, target, and priority.
  • handoff_condition_check shows a route the model chose. Read result, whenOutcome, and evaluatedContext to see why the platform allowed or refused it.
  • For the memory variation, memory_init shows that the session loaded the persistent value.

Production readiness checklist

  • The lookup tool is read-only, has a typed return that lists every field a route reads, and has a numeric hints.timeout.
  • Each field type matches its comparison. Booleans are booleans, not strings.
  • session.customerId comes from an authenticated channel. Use session.identityTier when a route must depend on a verified identity.
  • Every specialist route has an owner and a short SUMMARY.
  • A plain-language route handles every customer that no expression matched, including a failed or skipped lookup.
  • If every customer must reach a specialist, set BEHAVIOR with ROLE: router. Without a BEHAVIOR block, the supervisor can answer directly instead of choosing a route.
  • The highest-risk route is first.
  • Tests cover each route, an anonymous session, and a tool failure.
  • Stored memory values have a producer, such as a REMEMBER rule, that you can name.

Common mistakes

Troubleshooting