Class: Rixie::Run

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#agentObject (readonly)

Returns the value of attribute agent.



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

def agent
  @agent
end

#contextObject (readonly)

Returns the value of attribute context.



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

def context
  @context
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#outputObject (readonly)

Returns the value of attribute output.



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

def output
  @output
end

#statusObject (readonly)

Returns the value of attribute status.



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

def status
  @status
end

#stepsObject (readonly)

Returns the value of attribute steps.



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

def steps
  @steps
end

#thoughtsObject (readonly)

Returns the value of attribute thoughts.



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

def thoughts
  @thoughts
end

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

Returns:

  • (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))
  messages = 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

Returns:

  • (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

#to_historyObject



56
57
58
# File 'lib/rixie/run.rb', line 56

def to_history
  Context::History.new(input: user_input, thoughts: thoughts, output: output)
end