Class: Botiasloop::Agent

Inherits:
Object
  • Object
show all
Defined in:
lib/botiasloop/agent.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAgent

Initialize the agent



25
26
27
# File 'lib/botiasloop/agent.rb', line 25

def initialize
  setup_ruby_llm
end

Class Attribute Details

.instanceAgent

Returns Singleton instance of the agent.

Returns:

  • (Agent)

    Singleton instance of the agent



11
12
13
# File 'lib/botiasloop/agent.rb', line 11

def instance
  @instance ||= new
end

Class Method Details

.chat(message, conversation: nil, verbose_callback: nil) ⇒ Agent

Returns Singleton instance of the agent (alias for instance).

Returns:

  • (Agent)

    Singleton instance of the agent (alias for instance)



16
17
18
# File 'lib/botiasloop/agent.rb', line 16

def chat(message, conversation: nil, verbose_callback: nil)
  instance.chat(message, conversation: conversation, verbose_callback: verbose_callback)
end

Instance Method Details

#chat(message, conversation: nil, verbose_callback: nil) ⇒ String

Send a message and get a response

Parameters:

  • message (String)

    User message

  • conversation (Conversation, nil) (defaults to: nil)

    Existing conversation

  • verbose_callback (Proc, nil) (defaults to: nil)

    Callback for verbose messages

Returns:

  • (String)

    Assistant response



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/botiasloop/agent.rb', line 35

def chat(message, conversation: nil, verbose_callback: nil)
  conversation ||= Conversation.new

  registry = create_registry
  provider, model = create_provider_and_model
  loop = Loop.new(provider, model, registry, max_iterations: Config.instance.max_iterations)

  loop.run(conversation, message, verbose_callback)
rescue MaxIterationsExceeded => e
  e.message
end