Class: RubyCode::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/rubycode/client.rb,
lib/rubycode/client/approval_handler.rb,
lib/rubycode/client/response_handler.rb,
lib/rubycode/client/display_formatter.rb

Overview

Main client that provides the public API for the agent

Defined Under Namespace

Classes: ApprovalHandler, DisplayFormatter, ResponseHandler

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tty_prompt: nil) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rubycode/client.rb', line 10

def initialize(tty_prompt: nil)
  @config = RubyCode.config
  @adapter = build_adapter
  @memory = Memory.new
  @memory.clear # Clear memory at start of each session to prevent payload size issues
  @read_files = Set.new
  @tty_prompt = tty_prompt
  @approval_handler = Client::ApprovalHandler.new(
    tty_prompt: @tty_prompt,
    config: @config
  )
end

Instance Attribute Details

#approval_handler ⇒ Object (readonly)

Returns the value of attribute approval_handler.



8
9
10
# File 'lib/rubycode/client.rb', line 8

def approval_handler
  @approval_handler
end

#memory ⇒ Object (readonly)

Returns the value of attribute memory.



8
9
10
# File 'lib/rubycode/client.rb', line 8

def memory
  @memory
end

Instance Method Details

#ask(prompt:) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rubycode/client.rb', line 23

def ask(prompt:)
  @memory.add_message(role: "user", content: prompt)
  system_prompt = build_system_prompt

  AgentLoop.new(
    adapter: @adapter,
    memory: @memory,
    config: @config,
    system_prompt: system_prompt,
    options: {
      read_files: @read_files,
      tty_prompt: @tty_prompt,
      approval_handler: @approval_handler
    }
  ).run
end

#clear_memory ⇒ Object



40
41
42
43
# File 'lib/rubycode/client.rb', line 40

def clear_memory
  @memory.clear
  @read_files.clear
end