Class: Elelem::Agent
- Inherits:
-
Object
- Object
- Elelem::Agent
- Defined in:
- lib/elelem/agent.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#conversation ⇒ Object
readonly
Returns the value of attribute conversation.
-
#toolbox ⇒ Object
readonly
Returns the value of attribute toolbox.
Instance Method Summary collapse
-
#initialize(client, toolbox) ⇒ Agent
constructor
A new instance of Agent.
- #repl ⇒ Object
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
#client ⇒ Object (readonly)
Returns the value of attribute client.
5 6 7 |
# File 'lib/elelem/agent.rb', line 5 def client @client end |
#conversation ⇒ Object (readonly)
Returns the value of attribute conversation.
5 6 7 |
# File 'lib/elelem/agent.rb', line 5 def conversation @conversation end |
#toolbox ⇒ Object (readonly)
Returns the value of attribute toolbox.
5 6 7 |
# File 'lib/elelem/agent.rb', line 5 def toolbox @toolbox end |
Instance Method Details
#repl ⇒ Object
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 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 |