Queued Generation
Generate later
Queued generation allows you to handle prompt generation asynchronously, which is particularly useful for long-running tasks or when you want to improve the responsiveness of your application.
Generation can be performed using Active Job to handle the prompt-generation and perform actions asynchronously. This is the most common way to handle generation in production applications, as it allows for better scalability and responsiveness.
To perform queued generation, you can use the generate_later
method, which enqueues the generation job to be processed later by Active Job.
ruby
prompt = ApplicationAgent.with(message: "Process this later").prompt_context
# Enqueue the generation job
assert_enqueued_with(job: ActiveAgent::GenerationJob) do
prompt.generate_later
end
Custom Queue Configuration
You can specify custom queue names and priorities:
ruby
prompt = ApplicationAgent.with(message: "Priority task").prompt_context
# Enqueue with specific queue and priority
assert_enqueued_with(
job: ActiveAgent::GenerationJob,
queue: "high_priority"
) do
prompt.generate_later(queue: "high_priority", priority: 10)
end