Class: Regent::Agent

Inherits:
Object
  • Object
show all
Includes:
Concerns::Identifiable, Concerns::Toolable
Defined in:
lib/regent/agent.rb

Constant Summary collapse

DEFAULT_MAX_ITERATIONS =
10

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Concerns::Toolable

included

Methods included from Concerns::Identifiable

included

Constructor Details

#initialize(context, model:, tools: [], engine: Regent::Engine::React, **options) ⇒ Agent

Returns a new instance of Agent.



10
11
12
13
14
15
16
17
18
19
# File 'lib/regent/agent.rb', line 10

def initialize(context, model:, tools: [], engine: Regent::Engine::React, **options)
  super()

  @context = context
  @model = model.is_a?(String) ? Regent::LLM.new(model) : model
  @engine = engine
  @sessions = []
  @tools = build_toolchain(tools)
  @max_iterations = options[:max_iterations] || DEFAULT_MAX_ITERATIONS
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



21
22
23
# File 'lib/regent/agent.rb', line 21

def context
  @context
end

#inline_toolsObject (readonly)

Returns the value of attribute inline_tools.



21
22
23
# File 'lib/regent/agent.rb', line 21

def inline_tools
  @inline_tools
end

#modelObject (readonly)

Returns the value of attribute model.



21
22
23
# File 'lib/regent/agent.rb', line 21

def model
  @model
end

#sessionsObject (readonly)

Returns the value of attribute sessions.



21
22
23
# File 'lib/regent/agent.rb', line 21

def sessions
  @sessions
end

#toolsObject (readonly)

Returns the value of attribute tools.



21
22
23
# File 'lib/regent/agent.rb', line 21

def tools
  @tools
end

Instance Method Details

#run(task) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/regent/agent.rb', line 23

def run(task)
  raise ArgumentError, "Task cannot be empty" if task.to_s.strip.empty?

  start_session
  reason(task)
ensure
  complete_session
end

#running?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/regent/agent.rb', line 32

def running?
  session&.active? || false
end

#sessionObject



36
37
38
# File 'lib/regent/agent.rb', line 36

def session
  @sessions.last
end