Class: Riffer::Agents::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/riffer/agents/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.

Raises:

  • (ArgumentError)


27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/riffer/agents/base.rb', line 27

def initialize
  @messages = []
  @model_string = self.class.model
  @instructions_text = self.class.instructions

  provider_name, model_name = @model_string.split("/", 2)

  raise ArgumentError, "Invalid model string: #{@model_string}" unless [provider_name, model_name].all? { |part| part.is_a?(String) && !part.strip.empty? }

  @provider_name = provider_name
  @model_name = model_name
end

Instance Attribute Details

#messagesObject (readonly)

Returns the value of attribute messages.



25
26
27
# File 'lib/riffer/agents/base.rb', line 25

def messages
  @messages
end

Class Method Details

.instructions(instructions_text = nil) ⇒ Object

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
# File 'lib/riffer/agents/base.rb', line 15

def instructions(instructions_text = nil)
  return @instructions if instructions_text.nil?

  raise ArgumentError, "instructions must be a String" unless instructions_text.is_a?(String)
  raise ArgumentError, "instructions cannot be empty" if instructions_text.strip.empty?

  @instructions = instructions_text
end

.model(model_string = nil) ⇒ Object

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
# File 'lib/riffer/agents/base.rb', line 6

def model(model_string = nil)
  return @model if model_string.nil?

  raise ArgumentError, "model must be a String" unless model_string.is_a?(String)
  raise ArgumentError, "model cannot be empty" if model_string.strip.empty?

  @model = model_string
end

Instance Method Details

#generate(prompt) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/riffer/agents/base.rb', line 40

def generate(prompt)
  initialize_messages(prompt)

  loop do
    response = call_llm
    @messages << response

    break unless has_tool_calls?(response)

    execute_tool_calls(response)
  end

  extract_final_response
end