11# intro.py
22"""Introduction and session setup for Pytalon."""
33
4- from config import last_response_patterns , identity_patterns
4+ from config import last_response_patterns , identity_patterns , DEFER_PATTERNS
55from conversation_context import ConversationContext
66from validators import detect_conversation_intent
77from utils import show_topic_menu
@@ -43,8 +43,10 @@ def get_initial_topic_choice(context):
4343 Run the conversational opening loop.
4444 Returns the user's first topic_choice (string number) or 'exit'.
4545 """
46+ context .set_state ("greeting" )
4647 opening_prompt = "\n Hi there! 😄 What's on your mind? Ask me anything or pick a topic to start!"
4748 print (opening_prompt )
49+ context .set_state ("menu" )
4850
4951 retry_count = 0
5052 MAX_RETRIES = 2
@@ -93,6 +95,7 @@ def get_initial_topic_choice(context):
9395 if topic_name and topic_name in TOPIC_NAME_TO_NUMBER :
9496 print (f"\n 🎯 Let's jump straight into { topic_name } !" )
9597 topic_choice = TOPIC_NAME_TO_NUMBER [topic_name ]
98+ context .set_state ("topic" )
9699 else :
97100 print (f"\n 🤖 I'm not sure about that topic. Here's what I can teach you:" )
98101 break
@@ -139,6 +142,16 @@ def get_initial_topic_choice(context):
139142 context .add_message_to_history ('Pytalon' , uncertain_response )
140143 continue
141144
145+ elif intent ['intent' ] == 'defer' :
146+ defer_response = (
147+ "\n 🤖 No problem! Take your time — I'll be here when you're ready.\n "
148+ " • Type 'continue', 'ready', or \" let's go\" to resume\n "
149+ " • Or type 'show topics' to browse again"
150+ )
151+ print (defer_response )
152+ context .add_message_to_history ('Pytalon' , defer_response )
153+ continue
154+
142155 elif intent ['intent' ] == 'clarification' :
143156
144157 # Check if it's an identity question for more detailed response
@@ -155,8 +168,12 @@ def get_initial_topic_choice(context):
155168 continue
156169
157170 elif intent ['intent' ] == 'repeat_request' :
158- print ("\n 🤖 Sure! Here's what I said:" )
159- print (opening_prompt .strip ())
171+ last_response = context .get_pytalon_last_response ()
172+ if last_response :
173+ print ("\n 🤖 Sure! Here's what I said:" )
174+ print (last_response )
175+ else :
176+ print ("\n 🤖 I haven't said anything yet! Ask me something or pick a topic to start!" )
160177 continue
161178
162179 elif intent ['intent' ] in ('help_request' , 'practice_request' ):
@@ -173,12 +190,15 @@ def get_initial_topic_choice(context):
173190
174191 # If topic was directly requested, skip the menu
175192 if topic_choice :
193+ context .set_state ("topic" )
176194 return topic_choice
177195
178196 # Otherwise show menu
197+ context .set_state ("menu" )
179198 topic_choice = show_topic_menu (TOPICS , "Which topic would you like to start with?" )
180199 if topic_choice == 'exit' :
181200 print ("\n 👋 Ok, goodbye! Come back whenever you need me" )
182201 sys .exit (0 )
183202
203+ context .set_state ("topic" )
184204 return topic_choice
0 commit comments