Class: Rixie::Run
- Inherits:
-
Object
- Object
- Rixie::Run
- Defined in:
- lib/rixie/run.rb
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
-
#thoughts ⇒ Object
readonly
Returns the value of attribute thoughts.
-
#user_input ⇒ Object
readonly
Returns the value of attribute user_input.
Instance Method Summary collapse
- #add_step(tool_calls:, tool_results:) ⇒ Object
- #completed? ⇒ Boolean
- #execute(listener:) ⇒ Object
- #failed? ⇒ Boolean
- #find_tool_call(name) ⇒ Object
-
#initialize(user_input:, agent:, context:) ⇒ Run
constructor
A new instance of Run.
- #to_history ⇒ Object
Constructor Details
#initialize(user_input:, agent:, context:) ⇒ Run
Returns a new instance of Run.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/rixie/run.rb', line 9 def initialize(user_input:, agent:, context:) @id = SecureRandom.uuid @user_input = user_input @agent = agent @context = context @thoughts = [] @steps = [] @status = "running" @output = nil end |
Instance Attribute Details
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
7 8 9 |
# File 'lib/rixie/run.rb', line 7 def agent @agent end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
7 8 9 |
# File 'lib/rixie/run.rb', line 7 def context @context end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/rixie/run.rb', line 7 def id @id end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
7 8 9 |
# File 'lib/rixie/run.rb', line 7 def output @output end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
7 8 9 |
# File 'lib/rixie/run.rb', line 7 def status @status end |
#steps ⇒ Object (readonly)
Returns the value of attribute steps.
7 8 9 |
# File 'lib/rixie/run.rb', line 7 def steps @steps end |
#thoughts ⇒ Object (readonly)
Returns the value of attribute thoughts.
7 8 9 |
# File 'lib/rixie/run.rb', line 7 def thoughts @thoughts end |
#user_input ⇒ Object (readonly)
Returns the value of attribute user_input.
7 8 9 |
# File 'lib/rixie/run.rb', line 7 def user_input @user_input end |
Instance Method Details
#add_step(tool_calls:, tool_results:) ⇒ Object
40 41 42 |
# File 'lib/rixie/run.rb', line 40 def add_step(tool_calls:, tool_results:) @steps << {tool_calls: tool_calls, tool_results: tool_results} end |
#completed? ⇒ Boolean
44 45 46 |
# File 'lib/rixie/run.rb', line 44 def completed? @status == "completed" end |
#execute(listener:) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rixie/run.rb', line 20 def execute(listener:) listener.run_id = @id listener.emit(Event::RunStart.new(user_input: user_input)) = PromptBuilder.new.build( user_input: user_input, instructions: agent.instructions, context: context ) result = agent.think(messages:, listener:) @output = result.content @thoughts = result.thoughts @status = "completed" listener.emit(Event::RunEnd.new(output: @output, status: @status)) rescue @status = "failed" listener.emit(Event::RunEnd.new(output: nil, status: @status)) raise end |
#failed? ⇒ Boolean
48 49 50 |
# File 'lib/rixie/run.rb', line 48 def failed? @status == "failed" end |
#find_tool_call(name) ⇒ Object
52 53 54 |
# File 'lib/rixie/run.rb', line 52 def find_tool_call(name) thoughts.select(&:tool_call?).flat_map(&:tool_calls).find { it.name == name } end |