You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Only inject if enabled, session is not named yet, and we have messages
729
748
if !self.enable_naming_reminders || !self.session_name.is_empty() || messages.is_empty(){
730
749
return messages;
731
750
}
732
751
733
-
// Find the last user message and add system reminder
734
-
ifletSome(last_msg) = messages.last_mut(){
735
-
ifmatches!(last_msg.role,MessageRole::User){
736
-
let reminder_text = "\n\n<system-reminder>\nThis is an automatic reminder from the system. Please use the `name_session` tool first, provided the user has already given you a clear task or question. You can chain additional tools after using the `name_session` tool.\n</system-reminder>";
737
-
738
-
trace!("Injecting session naming reminder");
739
-
740
-
match&mut last_msg.content{
741
-
MessageContent::Text(text) => {
742
-
text.push_str(reminder_text);
743
-
}
752
+
// Find the last actual user message (not tool results) and add system reminder
753
+
// Iterate backwards through messages to find the last user message with actual content
754
+
for msg in messages.iter_mut().rev(){
755
+
ifmatches!(msg.role,MessageRole::User){
756
+
let is_actual_user_message = match&msg.content{
757
+
MessageContent::Text(_) => true,// Text content is always actual user input
744
758
MessageContent::Structured(blocks) => {
745
-
blocks.push(ContentBlock::Text{
746
-
text: reminder_text.to_string(),
747
-
});
759
+
// Check if this message contains tool results
760
+
// If it contains only ToolResult blocks, it's not an actual user message
let reminder_text = "<system-reminder>\nThis is an automatic reminder from the system. Please use the `name_session` tool first, provided the user has already given you a clear task or question. You can chain additional tools after using the `name_session` tool.\n</system-reminder>";
769
+
770
+
trace!("Injecting session naming reminder to actual user message");
771
+
772
+
match&mut msg.content{
773
+
MessageContent::Text(original_text) => {
774
+
// Convert from Text to Structured with two ContentBlocks
0 commit comments