Class: Rixie::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/rixie/task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#agentObject (readonly)

Returns the value of attribute agent.



7
8
9
# File 'lib/rixie/task.rb', line 7

def agent
  @agent
end

#contextObject (readonly)

Returns the value of attribute context.



7
8
9
# File 'lib/rixie/task.rb', line 7

def context
  @context
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/rixie/task.rb', line 7

def id
  @id
end

#outputObject (readonly)

Returns the value of attribute output.



7
8
9
# File 'lib/rixie/task.rb', line 7

def output
  @output
end

#runsObject (readonly)

Returns the value of attribute runs.



7
8
9
# File 'lib/rixie/task.rb', line 7

def runs
  @runs
end

#statusObject (readonly)

Returns the value of attribute status.



7
8
9
# File 'lib/rixie/task.rb', line 7

def status
  @status
end

#strategyObject (readonly)

Returns the value of attribute strategy.



7
8
9
# File 'lib/rixie/task.rb', line 7

def strategy
  @strategy
end

#user_inputObject (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

Returns:

  • (Boolean)


41
42
43
# File 'lib/rixie/task.rb', line 41

def completed?
  @status == "completed"
end

#executeObject



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

Returns:

  • (Boolean)


45
46
47
# File 'lib/rixie/task.rb', line 45

def failed?
  @status == "failed"
end

#to_historyObject



49
50
51
# File 'lib/rixie/task.rb', line 49

def to_history
  @runs.select(&:completed?).map(&:to_history)
end