Class: Kodo::Tools::SetReminder

Inherits:
RubyLLM::Tool
  • Object
show all
Extended by:
PromptContributor
Defined in:
lib/kodo/tools/set_reminder.rb

Constant Summary collapse

MAX_PER_TURN =
3
MAX_CONTENT_LENGTH =
500

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PromptContributor

capability_name, capability_primary, disabled_guidance, enabled_guidance

Constructor Details

#initialize(reminders:, audit:) ⇒ SetReminder

Returns a new instance of SetReminder.



26
27
28
29
30
31
32
33
# File 'lib/kodo/tools/set_reminder.rb', line 26

def initialize(reminders:, audit:)
  super()
  @reminders = reminders
  @audit = audit
  @turn_count = 0
  @channel_id = nil
  @chat_id = nil
end

Instance Attribute Details

#channel_id=(value) ⇒ Object (writeonly)

Sets the attribute channel_id

Parameters:

  • value —

    the value to set the attribute channel_id to.



24
25
26
# File 'lib/kodo/tools/set_reminder.rb', line 24

def channel_id=(value)
  @channel_id = value
end

#chat_id=(value) ⇒ Object (writeonly)

Sets the attribute chat_id

Parameters:

  • value —

    the value to set the attribute chat_id to.



24
25
26
# File 'lib/kodo/tools/set_reminder.rb', line 24

def chat_id=(value)
  @chat_id = value
end

Instance Method Details

#execute(content:, due_at:) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/kodo/tools/set_reminder.rb', line 39

def execute(content:, due_at:)
  if content.length > MAX_CONTENT_LENGTH
    return "Content too long (#{content.length} chars). Maximum is #{MAX_CONTENT_LENGTH}."
  end

  if Memory::Redactor.sensitive?(content)
    return "Cannot store sensitive data in reminders."
  end

  @turn_count += 1
  if @turn_count > MAX_PER_TURN
    return "Rate limit reached (max #{MAX_PER_TURN} reminders per message). Try again next message."
  end

  parsed_time = parse_time(due_at)
  return parsed_time if parsed_time.is_a?(String) # error message

  if parsed_time <= Time.now
    return "Cannot set a reminder in the past. Please provide a future time."
  end

  reminder = @reminders.add(
    content: content,
    due_at: parsed_time,
    channel_id: @channel_id,
    chat_id: @chat_id
  )

  @audit.log(
    event: "reminder_set",
    detail: "id:#{reminder['id']} due:#{reminder['due_at']} content:#{content.slice(0, 60)}"
  )

  "Reminder set for #{reminder['due_at']}: #{content} (id: #{reminder['id']})"
rescue Kodo::Error => e
  e.message
end

#name ⇒ Object



77
78
79
# File 'lib/kodo/tools/set_reminder.rb', line 77

def name
  "set_reminder"
end

#reset_turn_count! ⇒ Object



35
36
37
# File 'lib/kodo/tools/set_reminder.rb', line 35

def reset_turn_count!
  @turn_count = 0
end