Overview
AI nodes in FlowX workflows are stateless — each invocation starts fresh with no memory of previous turns. For multi-turn conversations such as chatbots, advisors, or guided flows, you need a strategy to persist and reload conversation history between interactions. This pattern uses a FlowX Database data source to store session state, loading it at the start of each turn and saving the updated history after the AI response.When to use
- Multi-turn chatbots or conversational assistants
- Guided workflows where the AI needs context from earlier steps
- Any scenario where the user returns to a conversation after a delay
- Task-oriented workflows requiring custom memory strategies
Architecture
The session state management pattern follows a read-process-write cycle on every turn:- Load — Query the
ChatSessionsdata source bysessionIdto retrieve existing conversation history. - Inject — Insert the retrieved history into the AI node’s operation prompt as context.
- Process — The AI node generates a response informed by the full conversation context.
- Append — Add both the user message and the AI response to the
messagesarray. - Save — Write the updated session back to the data source.
Data model
Create a FlowX Database data source namedChatSessions with the following schema:
| Field | Type | Description |
|---|---|---|
| sessionId | STRING | Unique identifier for the conversation session |
| messages | OBJECT[] | Array of message objects storing the conversation history |
messages array follows this structure:
| Field | Type | Description |
|---|---|---|
| role | STRING | The message author — user or assistant |
| content | STRING | The text content of the message |
Implementation
Create the ChatSessions data source
In the Integration Designer, add a new FlowX Database data source named
ChatSessions. Define the sessionId (STRING) and messages (OBJECT array) fields.Load session history at workflow start
Add a Query node at the beginning of your workflow that reads from
ChatSessions, filtering by the incoming sessionId. If no session exists, initialize an empty messages array.Inject history into the AI node prompt
In the AI node’s operation prompt, include the loaded conversation history as context. Format the messages array into a readable block:Use a Data Operations node before the AI node to transform the
messages array into this string format and map it to the prompt input.Append the new exchange to history
After the AI node produces a response, use a Data Operations node to append two new entries to the
messages array:Context window management
Long conversations can exceed the AI model’s context window or degrade response quality. Use these strategies to keep history manageable:Summarization
For conversations exceeding a threshold (for example, 20 turns), use a separate AI node to generate a summary of older messages. Replace the full history with:Token counting
Track approximate token usage for the history block. When it approaches 60-70% of the model’s context window, trigger summarization. This leaves sufficient room for the system prompt, current message, and the AI response.Real-world example
The Mortgage advisor chatbot tutorial demonstrates this pattern end to end — from session creation through multi-turn advising to session cleanup. It includes handling for session expiry and context summarization. For the complete walkthrough, see the Mortgage advisor tutorial.Variations
Sliding window
Keep only the last N turns (for example, 10) in the prompt context. Older messages remain stored in the database for audit purposes but are not injected into the prompt. This is the simplest approach and works well for short, focused conversations.Topic-based memory
Partition conversation history by topic. When the user switches subjects, start a new topic segment while retaining a brief summary of previous topics. This works well for advisor-style bots that cover multiple domains in one session.Cross-session memory
Maintain a persistent user profile that carries context across separate conversations. Store preferences, decisions, and key facts in a dedicated data source keyed by user ID rather than session ID. Inject a profile summary at the start of each new session so the AI can reference prior interactions.Available starting with FlowX.AI 5.6.0FlowX 5.6+ introduces built-in session memory for conversational workflows, which automates the read-inject-append-save cycle described in this pattern. For task-oriented workflows or custom memory strategies (sliding window, topic-based, cross-session), the manual approach described here still applies.For details, see the Conversational workflows documentation.

