@@ -127,7 +127,7 @@ async def summarize_session(session_service: InMemorySessionService, app_name: s
127127 print (f" - Compression ratio: { summary .get_compression_ratio ():.1f} %" )
128128
129129
130- SUMMARIZER_COUNT = 3 # Run summarization every SUMMARIZER_COUNT turns (e.g. 3 => every 3 turns)
130+ SUMMARIZER_COUNT = 2 # Keep the example short: summarize after a couple of turns.
131131
132132
133133def create_summarizer_manager (model : OpenAIModel ) -> SummarizerSessionManager :
@@ -154,8 +154,8 @@ def create_summarizer_manager(model: OpenAIModel) -> SummarizerSessionManager:
154154 # set_summarizer_time_interval_threshold(10),
155155 # )
156156 ],
157- max_summary_length = 600 , # Max summary length kept; default 1000; beyond shows ...
158- keep_recent_count = 4 , # How many recent turns to keep; default 10
157+ max_summary_length = 300 , # Max summary length kept; default 1000; beyond shows ...
158+ keep_recent_count = 2 , # Keep only the latest turns so compression is easy to observe.
159159 )
160160 # Create SummarizerSessionManager
161161 summarizer_manager = SummarizerSessionManager (
@@ -169,7 +169,7 @@ def create_summarizer_manager(model: OpenAIModel) -> SummarizerSessionManager:
169169async def llm_agent_summarizer ():
170170 """Demo LlmAgent integrated with SummarizerSessionManager."""
171171 print ("=" * 60 )
172- print ("Example 2 : LlmAgent + SummarizerSessionManager demo" )
172+ print ("Example: LlmAgent + SummarizerSessionManager demo" )
173173 print ("=" * 60 )
174174 app_name = "llm_summarizer_manager_demo"
175175
@@ -183,22 +183,13 @@ async def llm_agent_summarizer():
183183 current_session_id = str (uuid .uuid4 ())
184184 print (f"📊 Session: { app_name } /{ user_id } /{ current_session_id } " )
185185
186- # Demo conversation turns
186+ # Short demo conversation. Four turns are enough to trigger automatic
187+ # summarization while keeping the example quick to run.
187188 conversations = [
188189 "Hello! I want to learn Python programming. Can you help me?" ,
189190 "What is a variable? Can you give an example?" ,
190- "Got it! What data types are there?" ,
191- "What does control flow mean?" ,
192- "I understand those ideas. I'd like a small project to practice." ,
193- "OK! How do I build this calculator?" ,
194- "The calculator looks good—I ran it successfully. I'd like to learn more advanced Python." ,
195- "I'd like to start with functions—I think they're central to programming." ,
196- "I see—functions make code modular and reusable. I'd like to learn OOP next." ,
197- "I get OOP now. I'd like to learn exception handling." ,
198- "I've learned these advanced topics. I'd like a bigger project that ties them together." ,
199- "Yes! How do I implement this library system?" ,
200- "The structure looks good. How do I persist data to files?" ,
201- "Great! I've covered basics and advanced topics including files. I'd like a recap of what I learned." ,
191+ "Please give me a tiny calculator example." ,
192+ "Can you recap what I learned so far?" ,
202193 ]
203194
204195 print (f"\n 💬 Multi-turn dialogue ({ len (conversations )} turns)..." )
@@ -230,18 +221,18 @@ async def llm_agent_summarizer():
230221 # elif part.text:
231222 # print(f"\n✅ {part.text}")
232223
233- # After every SUMMARIZER_COUNT turns, inspect session state
234- if index % SUMMARIZER_COUNT == 0 : # summarizer should fire around this cadence
235- if session :
236- print ( f" \n 📊 Session state after turn { index + 1 } :" )
237- summary = await session_service . summarizer_manager . get_session_summary ( session )
224+ # Inspect the summary after the threshold cadence.
225+ if ( index + 1 ) % SUMMARIZER_COUNT == 0 and session :
226+ print ( f" \n 📊 Session state after turn { index + 1 } :" )
227+ summary = await session_service . summarizer_manager . get_session_summary ( session )
228+ if summary :
238229 print (f" - Summary text: { summary .summary_text [:100 ]} ..." )
239230 print (f" - Original event count: { summary .original_event_count } " )
240231 print (f" - Compressed event count: { summary .compressed_event_count } " )
241232 print (f" - Compression ratio: { summary .get_compression_ratio ()} " )
233+ else :
234+ print (" - Summary not created yet." )
242235 print ("\n " + "-" * 40 )
243- # Manual forced summary test
244- await summarize_session (session_service , app_name , user_id , current_session_id )
245236
246237
247238if __name__ == "__main__" :
0 commit comments