- A main orchestration workflow that uses an Intent Classification Agent to route messages
- A knowledge base Q&A handler that answers mortgage questions from uploaded documents
- A data collection handler that extracts and stores user financial data
- A personalized offer generator using hybrid AI extraction + business rule calculations
- A small talk responder and fallback handler
Architecture overview
The app uses an Intent Classification Agent node to classify each user message and route it to the right handler. Each intent maps to a separate output branch on the node, eliminating the need for a separate Condition node.Data model
Each workflow has its own data model. Define these keys in the corresponding workflow.mainChat data model
| Key | Type | Description |
|---|---|---|
humanMessage | STRING | Current user message from chat |
chatSessionId | STRING | Unique session identifier |
action | STRING | Chat action type (e.g., SEND_MESSAGE) |
uiFlowSessionId | STRING | UI flow session identifier |
agentMessage | STRING | Final response to send to chat UI |
responseKey | OBJECT | Intermediate response from handler subworkflows |
answerPersonalisedOffer data model
| Key | Type | Description |
|---|---|---|
clientProfile | OBJECT | Client financial data (extracted by AI from message) |
clientProfile.age | NUMBER | User age |
clientProfile.income | NUMBER | Monthly income |
clientProfile.loan_amount | NUMBER | Requested loan amount |
clientProfile.loan_duration | NUMBER | Loan term in years |
filteredProducts | OBJECT | Output from AI product filtering |
calculationResults | OBJECT | Output from business rule calculations (DTI, max loan, PMT) |
rankedProducts | OBJECT[] | Scored and ranked product recommendations |
agentMessage | STRING | Generated report text (set as Output Parameter) |
Set
agentMessage as an Output Parameter in the answerPersonalisedOffer data model. This is what flows back to mainChat through the subworkflow node.Prerequisites
Before starting, make sure you have:- Access to a FlowX Designer workspace with AI Platform enabled
- Familiarity with creating workflows in FlowX
- A Knowledge Base data source with mortgage-related documents uploaded (see Step 3)
Step 1: Build the main orchestration workflow
Create a workflow namedmainChat. This is the central workflow that receives every user message, classifies it using an Intent Classification Agent, and routes it to the appropriate handler.

Add the Intent Classification Agent
From the node palette, drag an Intent Classification Agent node (under AI Agents) onto the canvas and connect it to the Start node. Configure the node: User Message:${humanMessage}
Intents:
| # | Intent description |
|---|---|
| 1 | Greetings and small talk |
| 2 | Product offer or mortgage recommendation request |
| 3 | Knowledge base questions about mortgage products or policies |
| 4 | User providing or updating personal data like income, age, or loan details |
responseKey
If No Intent Matches: enabled (creates a fallback output branch)
Each intent creates a separate output port on the node. When the agent classifies a message, the workflow continues along the matching branch — no Condition node needed.
Connect handler nodes to each branch
Add the following nodes and connect each to its corresponding intent output:| Intent branch | Handler node | Type |
|---|---|---|
| Intent 1 (Greetings) | answerSmalltalk | Subworkflow (Response Key: responseKey) |
| Intent 2 (Offer) | answerPersonalisedOffer | Subworkflow (Response Key: agentMessage) |
| Intent 3 (Knowledge QA) | knowledgeBaseQA | Subworkflow (Response Key: responseKey) |
| Intent 4 (Data Input) | handleDataInput | Script node (inline) |
| No Match | answer nonsense | Script node (inline) |
Add the response formatter
After all branches, add a Script node (JavaScript) that all handler outputs converge into. This node normalizes the response from different handler types — some returnresponseKey.output.response (text), while the offer handler returns agentMessage directly.
Add the End Flow node
Connect theprocess text node to an End Flow node with body:
Step 2: Build the handler workflows
answerSmalltalk (Text Generation)
Create a workflow namedanswerSmalltalk with a single Text Generation node.
Operation Prompt:
responseKey
Each handler workflow needs an End Flow node with body: {"output": ${responseKey}}
Fallback handler (Script)
For the No Match branch in the mainChat workflow, use a Script node namedanswer nonsense:
Step 3: Build the data input handler
This handler is a Script node namedhandleDataInput directly in the mainChat workflow (on the Intent 4 branch). It processes messages where the user provides financial data.
Since the Intent Classification Agent already routed the message here, we know the user is providing personal data. The script uses simple string matching to extract values from the message.
The FlowX script runtime uses a subset of Python. Avoid
enumerate(), .get() with defaults, and import statements — use basic loops and in checks instead.The age/duration disambiguation checks whether the word after a number + “years” is “old”. For example, “30 years old” sets
age = 30, while “25 years” sets loan_duration = 25.Step 4: Build the knowledge base QA handler
Create a workflow namedknowledgeBaseQA with a single Custom Agent node connected to a Knowledge Base.
Set up the Knowledge Base
Create a Knowledge Base data source
In the Integration Designer, add a new Knowledge Base data source. Name it something descriptive like
MortgageKnowledgeBase.Upload mortgage documents
Upload PDF documents covering:
- Mortgage product sheets (rates, terms, eligibility criteria)
- FAQ documents (common questions about mortgages, DTI, LTV)
- Regulatory guides (required documents, application process)
For detailed Knowledge Base setup, see the Knowledge Base integration documentation.
Configure the Custom Agent node
In theknowledgeBaseQA workflow, add a Custom Agent node and enable the Knowledge Base tool. Select your MortgageKnowledgeBase data source.
Retrieval parameters:
| Parameter | Value |
|---|---|
| Max. Number of Results | 4 |
| Min. Relevance Score | 50 |
| Content Source Filter | All content sources |
responseKey
For more details on this pattern, see Knowledge base RAG.
Step 5: Build the personalized offer handler
This is the most complex handler. It implements the Hybrid AI + business rules pattern — alternating between AI nodes and deterministic Script nodes. Create a workflow namedanswerPersonalisedOffer with the following pipeline:

The Text Understanding node extracts client data directly from
{{humanMessage}} and evaluates products in a single step. This makes the subworkflow self-contained — it does not depend on data collected in previous conversation turns.Step 5a: AI understanding (extract and filter)
Add a Text Understanding node that extracts the client’s financial profile from their message and filters the product catalog. Operation Prompt:filteredProducts
Step 5b: Business rules (financial calculations)
Add a Script node (JavaScript) for deterministic financial calculations. These must be auditable and reproducible.The alternating AI-then-rules structure creates a natural audit trail. For any final recommendation, you can trace exactly which AI filtered the products and which formula computed the financial results.
Step 5c: Business rules (scoring, ranking, and report)
Add a second Script node (JavaScript) that scores products, ranks them, and generates the recommendation report text. This node also writes toagentMessage, which is the Output Parameter that flows back to mainChat.
The report is generated as plain text in the Script node rather than using a separate Text Generation node. This avoids issues with newline characters in the End Flow node’s JSON serialization. For richer formatting, you can use a Text Generation node and strip newlines before returning.
Step 6: Connect to the chat UI
Create a UI Flow
Go to UI Flows in the project sidebar and create a new UI Flow (e.g.,
chat). Add a Page to it.Add a Chat component
From the component palette, drag a Chat component onto the page. In the Chat component settings, set the Workflow property to
mainChat.For details on configuring chat experiences with built-in session memory, see Conversational workflows. For the Chat component reference, see Chat component.
Testing
Test knowledge base Q&A
Open the Verify the response is grounded in your uploaded documents, not generic LLM knowledge.
knowledgeBaseQA workflow and use Run Workflow with:Test the full chat flow
Run the

mainChat workflow via the Chat UI. Since data does not persist across conversation turns, include all financial details in a single message when requesting an offer:| Turn | Message | Expected behavior |
|---|---|---|
| 1 | ”Hi there!” | Greeting response, nudge toward mortgage |
| 2 | ”I am 30 years old and my income is 5000” | Acknowledges data (age, income recorded) |
| 3 | ”My age is 30, income 5000 EUR per month. I want a mortgage of 200000 EUR for 25 years. Give me product recommendations.” | Recommendation report with eligibility assessment and ranked products |

What you learned
In this tutorial, you built a full-featured conversational AI app that demonstrates:- Intent classification and routing — using an Intent Classification Agent to classify messages and route to handler branches automatically (pattern)
- Knowledge base RAG — grounding answers in uploaded documents using a Custom Agent with Knowledge Base (pattern)
- Hybrid AI + business rules — combining AI qualitative filtering with deterministic financial calculations for auditable recommendations (pattern)
- Workflow composition — using Subworkflow nodes to build modular, reusable AI pipelines

