Class: ActionAI::Interaction
- Inherits:
-
Delegator
- Object
- Delegator
- ActionAI::Interaction
- Defined in:
- lib/action_ai/interaction.rb
Overview
Action AI Interaction
The ActionAI::Interaction class is used by ActionAI::Agent when creating a new agent. Interaction is a wrapper (Delegator subclass) around a lazy created RubyLLM::Message. You can get direct access to the RubyLLM::Message or schedule the job to be executed through Active Job.
Generator.code(task) # an ActionAI::Interaction object
Generator.code(task).content # executes and returns the result
Generator.code(task).later # enqueue execution as a job through Active Job
Generator.code(task). # a RubyLLM::Message object
Direct Known Subclasses
Instance Method Summary collapse
-
#__getobj__ ⇒ Object
Method calls are delegated to the RubyLLM::Message that’s ready to execute.
-
#__setobj__(message) ⇒ Object
Unused except for delegator internals (dup, marshalling).
-
#initialize(agent_class, action, *args) ⇒ Interaction
constructor
:nodoc:.
-
#later ⇒ Object
Enqueues the action to be executed through Active Job.
-
#message ⇒ Object
Returns the resulting RubyLLM::Message.
-
#processed? ⇒ Boolean
Was the delegate loaded, causing the action to be processed?.
- #run ⇒ Object
Constructor Details
#initialize(agent_class, action, *args) ⇒ Interaction
:nodoc:
20 21 22 23 24 25 26 27 |
# File 'lib/action_ai/interaction.rb', line 20 def initialize(agent_class, action, *args) # :nodoc: @agent_class, @action, @args = agent_class, action, args # The AI interaction is only processed if we try to call any methods on it. # Typical usage will leave it unloaded and call +later+. @processed_agent = nil @message = nil end |
Instance Method Details
#__getobj__ ⇒ Object
Method calls are delegated to the RubyLLM::Message that’s ready to execute.
31 32 33 34 35 36 37 |
# File 'lib/action_ai/interaction.rb', line 31 def __getobj__ # :nodoc: @message ||= processed_agent.handle_exceptions do processed_agent.run_callbacks(:execution) do processed_agent. end end.presence end |
#__setobj__(message) ⇒ Object
Unused except for delegator internals (dup, marshalling).
40 41 42 |
# File 'lib/action_ai/interaction.rb', line 40 def __setobj__() # :nodoc: @message = end |
#later ⇒ Object
Enqueues the action to be executed through Active Job.
Generator.code(task).later
Generator.code(task).later(wait: 1.hour)
Generator.code(task).later(wait_until: 10.hours.from_now)
Generator.code(task).later(priority: 10)
Options:
-
:wait- Enqueue the action to be executed with a delay. -
:wait_until- Enqueue the action to be executed at (after) a specific date / time. -
:queue- Enqueue the action on the specified queue. -
:priority- Enqueues the action with the specified priority
By default, the action will be enqueued using ActionAI::ExecutionJob on the default queue. Agent classes can customize the queue name used for the default job by assigning a execute_later_queue_name class variable, or provide a custom job by assigning a execution_job. When a custom job is used, it controls the queue name.
class CostlyAgent < ApplicationAI
self.execution_job = CostlyExecutionJob
end
78 |
# File 'lib/action_ai/interaction.rb', line 78 def later(...) = enqueue_execution(...) |
#message ⇒ Object
Returns the resulting RubyLLM::Message
45 46 47 |
# File 'lib/action_ai/interaction.rb', line 45 def __getobj__ end |
#processed? ⇒ Boolean
Was the delegate loaded, causing the action to be processed?
50 51 52 |
# File 'lib/action_ai/interaction.rb', line 50 def processed? @processed_agent || @message end |
#run ⇒ Object
54 |
# File 'lib/action_ai/interaction.rb', line 54 def run = |