Class: RSmolagent::Memory

Inherits:
Object
  • Object
show all
Defined in:
lib/rsmolagent/memory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMemory

Returns a new instance of Memory.



5
6
7
8
# File 'lib/rsmolagent/memory.rb', line 5

def initialize
  @messages = []
  @history = []
end

Instance Attribute Details

#historyObject (readonly)

Returns the value of attribute history.



3
4
5
# File 'lib/rsmolagent/memory.rb', line 3

def history
  @history
end

#messagesObject (readonly)

Returns the value of attribute messages.



3
4
5
# File 'lib/rsmolagent/memory.rb', line 3

def messages
  @messages
end

Instance Method Details

#add_assistant_message(content) ⇒ Object



18
19
20
# File 'lib/rsmolagent/memory.rb', line 18

def add_assistant_message(content)
  add_message("assistant", content)
end

#add_final_answer(answer) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/rsmolagent/memory.rb', line 38

def add_final_answer(answer)
  step = {
    type: "final_answer",
    answer: answer,
    timestamp: Time.now
  }
  @history << step
  step
end

#add_system_message(content) ⇒ Object



10
11
12
# File 'lib/rsmolagent/memory.rb', line 10

def add_system_message(content)
  add_message("system", content)
end

#add_tool_call(tool_name, arguments, result) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rsmolagent/memory.rb', line 26

def add_tool_call(tool_name, arguments, result)
  step = {
    type: "tool_call",
    tool_name: tool_name,
    arguments: arguments,
    result: result,
    timestamp: Time.now
  }
  @history << step
  step
end

#add_tool_message(name, content) ⇒ Object



22
23
24
# File 'lib/rsmolagent/memory.rb', line 22

def add_tool_message(name, content)
  @messages << { role: "tool", name: name, content: content }
end

#add_user_message(content) ⇒ Object



14
15
16
# File 'lib/rsmolagent/memory.rb', line 14

def add_user_message(content)
  add_message("user", content)
end

#to_openai_messagesObject



48
49
50
51
52
53
54
55
56
# File 'lib/rsmolagent/memory.rb', line 48

def to_openai_messages
  @messages.map do |msg|
    if msg[:role] == "tool"
      { role: "tool", tool_call_id: "call_#{msg[:name]}", content: msg[:content].to_s }
    else
      { role: msg[:role], content: msg[:content] }
    end
  end
end