Class: Elelem::Agent

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, toolbox) ⇒ Agent

Returns a new instance of Agent.



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

def initialize(client, toolbox)
  @conversation = Conversation.new
  @client = client
  @toolbox = toolbox
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/elelem/agent.rb', line 5

def client
  @client
end

#conversationObject (readonly)

Returns the value of attribute conversation.



5
6
7
# File 'lib/elelem/agent.rb', line 5

def conversation
  @conversation
end

#toolboxObject (readonly)

Returns the value of attribute toolbox.



5
6
7
# File 'lib/elelem/agent.rb', line 5

def toolbox
  @toolbox
end

Instance Method Details

#replObject



13
14
15
16
17
18
19
20
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
49
50
# File 'lib/elelem/agent.rb', line 13

def repl
  mode = Set.new([:read])

  loop do
    input = ask?("User> ")
    break if input.nil?
    if input.start_with?("/")
      case input
      when "/mode auto"
        mode = Set[:read, :write, :execute]
        puts "  → Mode: auto (all tools enabled)"
      when "/mode build"
        mode = Set[:read, :write]
        puts "  → Mode: build (read + write)"
      when "/mode plan"
        mode = Set[:read]
        puts "  → Mode: plan (read-only)"
      when "/mode verify"
        mode = Set[:read, :execute]
        puts "  → Mode: verify (read + execute)"
      when "/mode"
        puts "  Mode: #{mode.to_a.inspect}"
        puts "  Tools: #{toolbox.tools_for(mode).map { |t| t.dig(:function, :name) }}"
      when "/exit" then exit
      when "/clear"
        conversation.clear
        puts "  → Conversation cleared"
      when "/context" then puts conversation.dump(mode)
      else
        puts help_banner
      end
    else
      conversation.add(role: :user, content: input)
      result = execute_turn(conversation.history_for(mode), tools: toolbox.tools_for(mode))
      conversation.add(role: result[:role], content: result[:content])
    end
  end
end