Class: Regent::Agent
- Inherits:
-
Object
- Object
- Regent::Agent
- Includes:
- Concerns::Identifiable, Concerns::Toolable
- Defined in:
- lib/regent/agent.rb
Constant Summary collapse
- DEFAULT_MAX_ITERATIONS =
10
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#inline_tools ⇒ Object
readonly
Returns the value of attribute inline_tools.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#sessions ⇒ Object
readonly
Returns the value of attribute sessions.
-
#tools ⇒ Object
readonly
Returns the value of attribute tools.
Instance Method Summary collapse
-
#initialize(context, model:, tools: [], engine: Regent::Engine::React, **options) ⇒ Agent
constructor
A new instance of Agent.
- #run(task) ⇒ Object
- #running? ⇒ Boolean
- #session ⇒ Object
Methods included from Concerns::Toolable
Methods included from Concerns::Identifiable
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, **) super() @context = context @model = model.is_a?(String) ? Regent::LLM.new(model) : model @engine = engine @sessions = [] @tools = build_toolchain(tools) @max_iterations = [:max_iterations] || DEFAULT_MAX_ITERATIONS end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
21 22 23 |
# File 'lib/regent/agent.rb', line 21 def context @context end |
#inline_tools ⇒ Object (readonly)
Returns the value of attribute inline_tools.
21 22 23 |
# File 'lib/regent/agent.rb', line 21 def inline_tools @inline_tools end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
21 22 23 |
# File 'lib/regent/agent.rb', line 21 def model @model end |
#sessions ⇒ Object (readonly)
Returns the value of attribute sessions.
21 22 23 |
# File 'lib/regent/agent.rb', line 21 def sessions @sessions end |
#tools ⇒ Object (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
32 33 34 |
# File 'lib/regent/agent.rb', line 32 def running? session&.active? || false end |
#session ⇒ Object
36 37 38 |
# File 'lib/regent/agent.rb', line 36 def session @sessions.last end |