Class: RSmolagent::Memory
- Inherits:
-
Object
- Object
- RSmolagent::Memory
- Defined in:
- lib/rsmolagent/memory.rb
Instance Attribute Summary collapse
-
#history ⇒ Object
readonly
Returns the value of attribute history.
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
Instance Method Summary collapse
- #add_assistant_message(content) ⇒ Object
- #add_final_answer(answer) ⇒ Object
- #add_system_message(content) ⇒ Object
- #add_tool_call(tool_name, arguments, result) ⇒ Object
- #add_tool_message(name, content) ⇒ Object
- #add_user_message(content) ⇒ Object
-
#initialize ⇒ Memory
constructor
A new instance of Memory.
- #to_openai_messages ⇒ Object
Constructor Details
#initialize ⇒ Memory
Returns a new instance of Memory.
5 6 7 8 |
# File 'lib/rsmolagent/memory.rb', line 5 def initialize = [] @history = [] end |
Instance Attribute Details
#history ⇒ Object (readonly)
Returns the value of attribute history.
3 4 5 |
# File 'lib/rsmolagent/memory.rb', line 3 def history @history end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
3 4 5 |
# File 'lib/rsmolagent/memory.rb', line 3 def end |
Instance Method Details
#add_assistant_message(content) ⇒ Object
18 19 20 |
# File 'lib/rsmolagent/memory.rb', line 18 def (content) ("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 (content) ("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 (name, content) << { role: "tool", name: name, content: content } end |
#add_user_message(content) ⇒ Object
14 15 16 |
# File 'lib/rsmolagent/memory.rb', line 14 def (content) ("user", content) end |
#to_openai_messages ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/rsmolagent/memory.rb', line 48 def .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 |