Module: SwarmSDK::Agent::ChatHelpers::SystemReminders

Included in:
SwarmSDK::Agent::Chat
Defined in:
lib/swarm_sdk/agent/chat_helpers/system_reminders.rb

Overview

System reminder collection and injection

Extracted from Chat to reduce class size and centralize reminder logic.

Instance Method Summary collapse

Instance Method Details

#collect_plugin_reminders(prompt, is_first_message:) ⇒ Array<String>

Collect reminders from all plugins



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/swarm_sdk/agent/chat_helpers/system_reminders.rb', line 15

def collect_plugin_reminders(prompt, is_first_message:)
  return [] unless @agent_name

  PluginRegistry.all.flat_map do |plugin|
    plugin.on_user_message(
      agent_name: @agent_name,
      prompt: prompt,
      is_first_message: is_first_message,
    )
  end.compact
end

#collect_system_reminders(prompt, is_first) ⇒ Array<String>

Collect all system reminders for this message

Returns an array of reminder strings that should be injected as ephemeral content. These are sent to the LLM but not stored in message history.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/swarm_sdk/agent/chat_helpers/system_reminders.rb', line 35

def collect_system_reminders(prompt, is_first)
  reminders = []

  if is_first
    # Add toolset reminder on first message
    reminders << build_toolset_reminder

    # Add todo list reminder if agent has TodoWrite tool
    reminders << SystemReminderInjector::AFTER_FIRST_MESSAGE_REMINDER if has_tool?(:TodoWrite)

    # Collect plugin reminders
    reminders.concat(collect_plugin_reminders(prompt, is_first_message: true))
  else
    # Add periodic TodoWrite reminder if needed
    if has_tool?(:TodoWrite) && SystemReminderInjector.should_inject_todowrite_reminder?(self, @last_todowrite_message_index)
      reminders << SystemReminderInjector::TODOWRITE_PERIODIC_REMINDER
      @last_todowrite_message_index = SystemReminderInjector.find_last_todowrite_index(self)
    end

    # Collect plugin reminders
    reminders.concat(collect_plugin_reminders(prompt, is_first_message: false))
  end

  reminders
end