Class: Mistri::Reminder

Inherits:
Object
  • Object
show all
Defined in:
lib/mistri/reminder.rb

Overview

A periodic reminder for long agentic runs: models drift from their instructions as turns accumulate, and a short reminder at the tail of the context, where attention is strongest, pulls them back. It rides transform_context, so it appears fresh on the wire each time it is due and never persists to the session.

agent = Mistri.agent("claude-opus-4-8", tools: tools,
                   transform_context: Mistri::Reminder.every(
                     3, "Stay on gifting. Verify with tools before claiming.",
                   ))

Due is counted in completed assistant turns: the first reminder lands once after turns have finished (default: one full interval), then every interval turns.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(interval:, text:, after: nil) ⇒ Reminder

Returns a new instance of Reminder.



23
24
25
26
27
# File 'lib/mistri/reminder.rb', line 23

def initialize(interval:, text:, after: nil)
  @interval = [interval.to_i, 1].max
  @after = (after || @interval).to_i
  @body = "<system-reminder>\n#{text}\n</system-reminder>"
end

Class Method Details

.every(interval, text, after: nil) ⇒ Object



19
20
21
# File 'lib/mistri/reminder.rb', line 19

def self.every(interval, text, after: nil)
  new(interval: interval, text: text, after: after)
end

Instance Method Details

#call(messages) ⇒ Object



29
30
31
32
33
34
# File 'lib/mistri/reminder.rb', line 29

def call(messages)
  turns = messages.count(&:assistant?)
  return messages unless turns >= @after && ((turns - @after) % @interval).zero?

  messages + [Message.user(@body)]
end