Class: Silas::Agent

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

Overview

The parsed agent definition: app/agent/agent.yml (data-only config, eve's keys) over Silas.config defaults.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Agent

Returns a new instance of Agent.



13
14
15
# File 'lib/silas/agent.rb', line 13

def initialize(attrs = {})
  @attrs = attrs
end

Class Method Details

.load(root: Rails.root, dir: nil) ⇒ Object



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

def self.load(root: Rails.root, dir: nil)
  dir ||= root.join("app/agent")
  path = Pathname(dir).join("agent.yml")
  new(path.exist? ? YAML.safe_load(path.read) || {} : {})
end

Instance Method Details

#descriptionObject



18
19
20
21
# File 'lib/silas/agent.rb', line 18

def description = @attrs["description"].to_s
# Optional JSON schema for the turn's final answer (raw Hash, passed to
# RubyLLM's with_schema). Model-visible state: folded into the definitions
# digest when present, so a mid-turn change fails loudly.

#final_answerObject

Optional JSON schema for the turn's final answer (raw Hash, passed to RubyLLM's with_schema). Model-visible state: folded into the definitions digest when present, so a mid-turn change fails loudly.



22
# File 'lib/silas/agent.rb', line 22

def final_answer = @attrs["final_answer"]

#limitsObject



23
# File 'lib/silas/agent.rb', line 23

def limits      = @attrs["limits"] || {}

#max_costObject

dollars per turn



26
# File 'lib/silas/agent.rb', line 26

def max_cost    = limits["max_cost"]               # dollars per turn

#max_input_tokensObject

cumulative input tokens per turn



25
# File 'lib/silas/agent.rb', line 25

def max_input_tokens = limits["max_input_tokens"]  # cumulative input tokens per turn

#max_stepsObject



24
# File 'lib/silas/agent.rb', line 24

def max_steps   = limits["max_steps"] || Silas.config.max_steps

#modelObject



17
# File 'lib/silas/agent.rb', line 17

def model       = @attrs["model"] || Silas.config.default_model

#start(input:, metadata: {}, channel: nil, continuation_token: nil) ⇒ Object

Start a session with its first turn. channel/continuation_token let a channel bind the session to an external thread (backward-compatible).



31
32
33
34
35
# File 'lib/silas/agent.rb', line 31

def start(input:, metadata: {}, channel: nil, continuation_token: nil)
  session = Session.create!(metadata: , channel: channel, continuation_token: continuation_token)
  session.continue(input: input)
  session
end

#timeoutObject

wall-clock seconds per turn



27
# File 'lib/silas/agent.rb', line 27

def timeout     = limits["timeout"]                # wall-clock seconds per turn