Skip to content

Commit 731fbaa

Browse files
committed
docs(conversation-flow-architecture): enhance dynamic architecture overview with detailed sequence diagram and clarify state transition mechanics
1 parent 14ac73c commit 731fbaa

1 file changed

Lines changed: 111 additions & 2 deletions

File tree

‎docs/conversation-flow-architecture.md‎

Lines changed: 111 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ sequenceDiagram
205205
STT->>TMR: Schedule after delay
206206
TMR-->>STT: timerID
207207
STT->>SM: Set DataKeyStateTransitionTimerID=timerID
208-
TMR-->>STT: On fire -> executeImmediateTransition()
209-
STT->>SM: Set DataKeyConversationState=target; Clear timerID
208+
TMR-->>STT: On fire triggers executeImmediateTransition()
209+
STT->>SM: Set DataKeyConversationState=target (clear timerID)
210210
end
211211
CF-->>User: Reply from MOD
212212
Note over CF,MOD: Next message will be routed to the new module per state
@@ -218,6 +218,115 @@ Common handoffs:
218218
- Coordinator/Intake → Feedback: After a prompt is sent and the user reports an outcome (or when the model decides to gather outcomes), Feedback tracks results and updates profile.
219219
- Feedback → Coordinator: After processing feedback or after a timeout/follow-up window, return to Coordinator.
220220

221+
## Dynamic architecture overview (end-to-end)
222+
223+
The following sequence shows a typical dynamic arc across modules, tools, timers, and messaging: Coordinator bootstraps, hands off to Intake for profile building, returns to Coordinator to generate/schedule prompts, then hands to Feedback to process outcomes, finally returning to Coordinator.
224+
225+
```mermaid
226+
sequenceDiagram
227+
autonumber
228+
participant User
229+
participant WA as WhatsApp
230+
participant RH as ResponseHandler
231+
participant CF as ConversationFlow
232+
participant SM as StateManager
233+
participant CM as Coordinator
234+
participant IM as Intake
235+
participant FM as Feedback
236+
participant GA as GenAI
237+
participant PST as ProfileSaveTool
238+
participant PGT as PromptGeneratorTool
239+
participant SCH as SchedulerTool
240+
participant STT as StateTransitionTool
241+
participant TMR as Timer
242+
participant MSG as MessagingService
243+
244+
Note over CF,SM: DataKeyConversationState defaults to COORDINATOR if empty
245+
246+
User->>WA: Message
247+
WA->>RH: Event
248+
RH->>CF: ProcessResponse(participantID,text)
249+
CF->>SM: GetCurrentState + GetStateData(conversationState, history)
250+
CF->>CM: Dispatch (COORDINATOR)
251+
252+
CM->>GA: GenerateWithTools(history + system prompts)
253+
GA-->>CM: Tool call: save_user_profile(...)
254+
CM->>PST: save_user_profile(args)
255+
PST->>SM: SetStateData(userProfile)
256+
PST-->>CM: ok
257+
258+
alt Profile incomplete
259+
CM->>STT: transition_state(target=INTAKE)
260+
STT->>SM: SetStateData(conversationState=INTAKE)
261+
else Profile sufficient
262+
CM-->>CF: Return assistant text
263+
end
264+
CF->>SM: Save updated conversationHistory
265+
CF-->>RH: Assistant text
266+
RH-->>User: Send reply
267+
268+
%% Next user message routes to Intake
269+
User->>WA: Follow-up
270+
WA->>RH: Event
271+
RH->>CF: ProcessResponse
272+
CF->>SM: Read conversationState = INTAKE
273+
CF->>IM: ExecuteIntakeBot
274+
IM->>GA: GenerateWithTools
275+
GA-->>IM: Tool call: save_user_profile(...)
276+
IM->>PST: save_user_profile(args)
277+
PST->>SM: Update userProfile
278+
IM-->>STT: transition_state(target=COORDINATOR)
279+
STT->>SM: Set conversationState=COORDINATOR
280+
IM-->>CF: Assistant text (e.g., confirmation)
281+
CF->>SM: Save history
282+
CF-->>RH: Reply
283+
RH-->>User: Send reply
284+
285+
%% Coordinator generates and schedules prompts
286+
CF->>CM: Dispatch (COORDINATOR)
287+
CM->>PGT: ExecutePromptGenerator
288+
PGT->>GA: Generate personalized prompt
289+
GA-->>PGT: Prompt text
290+
PGT-->>CM: Prompt text
291+
CM-->>CF: Assistant prompt text
292+
CF-->>RH: Reply to user
293+
RH-->>User: Send prompt
294+
295+
CM->>SCH: scheduler(action=create, ...)
296+
SCH->>TMR: Schedule prep & recurring timers
297+
SCH->>SM: Save schedule metadata (scheduleRegistry)
298+
SCH-->>CM: Confirmation
299+
CM->>STT: transition_state(target=FEEDBACK[, delay_minutes])
300+
alt delayed
301+
STT->>TMR: Schedule delayed transition
302+
TMR-->>STT: timerID
303+
STT->>SM: Set stateTransitionTimerID
304+
TMR-->>STT: On fire triggers executeImmediateTransition
305+
STT->>SM: Set conversationState=FEEDBACK (clear timerID)
306+
else immediate
307+
STT->>SM: Set conversationState=FEEDBACK
308+
end
309+
310+
%% User reports outcome -> Feedback module processes
311+
User->>WA: Outcome / feedback
312+
WA->>RH: Event
313+
RH->>CF: ProcessResponse
314+
CF->>SM: Read conversationState = FEEDBACK
315+
CF->>FM: ExecuteFeedback
316+
FM->>GA: GenerateWithTools
317+
GA-->>FM: Tool call(s): save_user_profile / scheduler
318+
FM->>PST: save_user_profile(args)
319+
PST->>SM: Update profile (success counts, barriers, tweaks)
320+
FM->>STT: transition_state(target=COORDINATOR)
321+
STT->>SM: Set conversationState=COORDINATOR
322+
FM-->>CF: Assistant text (personalized feedback)
323+
CF->>SM: Save history
324+
CF-->>RH: Reply
325+
RH-->>User: Send reply
326+
327+
Note over SCH,TMR: Timers continue to fire sending scheduled prompts via MessagingService
328+
```
329+
221330
## Module responsibilities (3-bot model)
222331

223332
- Coordinator

0 commit comments

Comments
 (0)