Class: AgentRuby::Agent

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

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model = nil) ⇒ Agent

Returns a new instance of Agent.



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

def initialize(model = nil)
  @chat = RubyLLM.chat(model:)
  @steps = []
end

Class Attribute Details

.actionsObject (readonly)

Returns the value of attribute actions.



6
7
8
# File 'lib/agent_ruby/agent.rb', line 6

def actions
  @actions
end

Instance Attribute Details

#chatObject

Returns the value of attribute chat.



14
15
16
# File 'lib/agent_ruby/agent.rb', line 14

def chat
  @chat
end

#stepsObject

Returns the value of attribute steps.



14
15
16
# File 'lib/agent_ruby/agent.rb', line 14

def steps
  @steps
end

Class Method Details

.action(klass) ⇒ Object



8
9
10
11
# File 'lib/agent_ruby/agent.rb', line 8

def action(klass)
  @actions ||= []
  @actions << klass
end

Instance Method Details

#hey(message, &block) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/agent_ruby/agent.rb', line 21

def hey(message, &block)
  creation = nil
  results = []
  while 1
    creation = Step::CreateTask.new(
      actions: self.class.actions.map(&:new),
      chat: @chat,
      message:, block:,
      results:,
    )
    created = creation.perform
    task = creation.task
    result = task.result
    results << result
    @steps << created
    if creation.[:continuation].to_s == "false"
      break
    end
  end
  summarize = Step::Summarize.new(
      chat: @chat,
      results:,
      block:,
    )
  summary = summarize.perform
  @steps << summary
  @steps.map(&:content)
end