Class: Rixie::Task
- Inherits:
-
Object
- Object
- Rixie::Task
- Defined in:
- lib/rixie/task.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.
-
#runs ⇒ Object
readonly
Returns the value of attribute runs.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#strategy ⇒ Object
readonly
Returns the value of attribute strategy.
-
#user_input ⇒ Object
readonly
Returns the value of attribute user_input.
Instance Method Summary collapse
- #completed? ⇒ Boolean
- #execute ⇒ Object
- #failed? ⇒ Boolean
-
#initialize(user_input:, agent:, context:, strategy:, subscribers: [], session_id: nil) ⇒ Task
constructor
A new instance of Task.
- #to_history ⇒ Object
Constructor Details
#initialize(user_input:, agent:, context:, strategy:, subscribers: [], session_id: nil) ⇒ Task
Returns a new instance of Task.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/rixie/task.rb', line 9 def initialize(user_input:, agent:, context:, strategy:, subscribers: [], session_id: nil) @id = SecureRandom.uuid @session_id = session_id @user_input = user_input @agent = agent @context = context @strategy = strategy @subscribers = subscribers @runs = [] @status = "running" @output = nil end |
Instance Attribute Details
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
7 8 9 |
# File 'lib/rixie/task.rb', line 7 def agent @agent end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
7 8 9 |
# File 'lib/rixie/task.rb', line 7 def context @context end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/rixie/task.rb', line 7 def id @id end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
7 8 9 |
# File 'lib/rixie/task.rb', line 7 def output @output end |
#runs ⇒ Object (readonly)
Returns the value of attribute runs.
7 8 9 |
# File 'lib/rixie/task.rb', line 7 def runs @runs end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
7 8 9 |
# File 'lib/rixie/task.rb', line 7 def status @status end |
#strategy ⇒ Object (readonly)
Returns the value of attribute strategy.
7 8 9 |
# File 'lib/rixie/task.rb', line 7 def strategy @strategy end |
#user_input ⇒ Object (readonly)
Returns the value of attribute user_input.
7 8 9 |
# File 'lib/rixie/task.rb', line 7 def user_input @user_input end |
Instance Method Details
#completed? ⇒ Boolean
41 42 43 |
# File 'lib/rixie/task.rb', line 41 def completed? @status == "completed" end |
#execute ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rixie/task.rb', line 22 def execute listener = EventListener.new(session_id: @session_id, task_id: @id) listener.on(Event::ToolCallsCompleted) { |envelope| e = envelope.event runs.last.add_step(tool_calls: e.tool_calls, tool_results: e.tool_results) } @subscribers.each { |s| s.subscribe(listener) } listener.emit(Event::TaskStart.new(user_input: @user_input, strategy: @strategy)) result = @strategy.run(task: self, listener:) @output = result @status = "completed" listener.emit(Event::TaskEnd.new(output: @output, status: @status)) rescue @status = "failed" listener&.emit(Event::TaskEnd.new(output: nil, status: @status)) raise end |
#failed? ⇒ Boolean
45 46 47 |
# File 'lib/rixie/task.rb', line 45 def failed? @status == "failed" end |
#to_history ⇒ Object
49 50 51 |
# File 'lib/rixie/task.rb', line 49 def to_history @runs.select(&:completed?).map(&:to_history) end |