Class: ActiveAgent::GenerationJob

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
lib/active_agent/generation_job.rb

Overview

Active Agent GenerationJob

The ActiveAgent::GenerationJob class is used when you want to generate content outside of the request-response cycle. It supports sending messages with parameters.

Exceptions are rescued and handled by the agent class.

Instance Method Summary collapse

Instance Method Details

#perform(agent, agent_method, generation_method, args:, kwargs: nil, params: nil) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/active_agent/generation_job.rb', line 21

def perform(agent, agent_method, generation_method, args:, kwargs: nil, params: nil)
  agent_class = params ? agent.constantize.with(params) : agent.constantize
  prompt = if kwargs
    agent_class.public_send(agent_method, *args, **kwargs)
  else
    agent_class.public_send(agent_method, *args)
  end
  prompt.send(generation_method)
end