Class: Prescient::Agent::CLIAdapter

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

Overview

Adapts the bounded agent runtime to CLI streams and exit statuses.

Instance Method Summary collapse

Constructor Details

#initialize(output: $stdout, errors: $stderr) ⇒ CLIAdapter

Returns a new instance of CLIAdapter.



7
8
9
10
# File 'lib/prescient/agent/cli_adapter.rb', line 7

def initialize(output: $stdout, errors: $stderr)
  @output = output
  @errors = errors
end

Instance Method Details

#run(task:, client: nil, provider: nil, tool_names: [], max_loops: Configuration::DEFAULT_MAX_LOOPS, format: "text", provider_options: {}, generation_options: {}, telemetry: nil) ⇒ Integer

Run an agent task and render a text or JSON result.

Returns:

  • (Integer)

    Process exit status



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/prescient/agent/cli_adapter.rb', line 14

def run(task:, client: nil, provider: nil, tool_names: [], max_loops: Configuration::DEFAULT_MAX_LOOPS,
        format: "text", provider_options: {}, generation_options: {}, telemetry: nil)
  runtime = Runtime.new(
    client:, provider:, tool_names:, configuration: Configuration.new(max_loops:, telemetry:),
    provider_options:, generation_options:
  )
  result = runtime.run(task)
  format == "json" ? @output.puts(JSON.generate(result.to_h)) : @output.puts(result.response)
  0
rescue Prescient::Error, ArgumentError => e
  @errors.puts "prescient: #{e.message}"
  1
end