Class: Rixie::Context::History
- Inherits:
-
Object
- Object
- Rixie::Context::History
- Defined in:
- lib/rixie/context/history.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(input:, thoughts:, output:) ⇒ History
constructor
A new instance of History.
- #to_message ⇒ Object
- #to_store ⇒ Object
Constructor Details
#initialize(input:, thoughts:, output:) ⇒ History
Returns a new instance of History.
6 7 8 9 10 |
# File 'lib/rixie/context/history.rb', line 6 def initialize(input:, thoughts:, output:) @input = input @thoughts = thoughts @output = output end |
Class Method Details
.from_store(entry) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rixie/context/history.rb', line 29 def self.from_store(entry) thoughts = (entry["thoughts"] || []).map { |t| tool_calls = t["tool_calls"].map { |tc| LLM::ToolCall.new(id: tc["id"], name: tc["name"], arguments: tc["arguments"]) } tool_results = t["tool_results"].map { |r| ToolExecutor::Result.new(tool_call_id: r["tool_call_id"], content: r["content"], error: nil) } Agent::Thought.new(type: :tool_call, content: t["content"], tool_calls: tool_calls, tool_results: tool_results) } new(input: entry["input"], thoughts: thoughts, output: entry["output"]) end |
Instance Method Details
#to_message ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rixie/context/history.rb', line 12 def = [Message::User.new(content: @input)] @thoughts.each do |thought| next unless thought.tool_call? next if thought.tool_calls.nil? || thought.tool_calls.empty? << Message::Assistant.new(content: thought.content, tool_calls: thought.tool_calls) thought.tool_results.each do |r| << Message::Tool.new(tool_call_id: r.tool_call_id, content: r.content) end end << Message::Assistant.new(content: @output, tool_calls: []) end |
#to_store ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rixie/context/history.rb', line 42 def to_store { "type" => "history", "input" => @input, "thoughts" => @thoughts.select(&:tool_call?).map { |t| { "content" => t.content, "tool_calls" => t.tool_calls.map { |tc| {"id" => tc.id, "name" => tc.name, "arguments" => tc.arguments} }, "tool_results" => t.tool_results.map { |r| {"tool_call_id" => r.tool_call_id, "content" => r.content} } } }, "output" => @output } end |