Agent.prompt(...).generate_later fails when the job runs
Agent.prompt(...).generate_later and Agent.embed(...).embed_later enqueue successfully but crash when a worker executes the job. Docs and examples use this pattern, so anyone on Sidekiq or Solid Queue hits it in production.
What happens
ActiveAgent::Parameterized::DirectGeneration passes direct_generation_type, direct_args, and direct_options into GenerationJob. The job perform method does not accept those keyword arguments.
# DirectGeneration enqueue (parameterized.rb)
agent_class.generation_job.set(job_options).perform_later(
agent_class.name,
action_name.to_s,
generation_method.to_s,
params: @params,
args: args,
kwargs: kwargs,
direct_generation_type: @generation_type,
direct_args: @direct_args,
direct_options: @direct_options
)
# GenerationJob (generation_job.rb)
def perform(agent, agent_method, generation_method, args:, kwargs: nil, params: nil)
# ...
end
The action name is also a synthetic __direct_prompt__ / __direct_embed__ method that does not exist on the agent.
Error
ArgumentError: unknown keywords: :direct_generation_type, :direct_args, :direct_options
Raised from ActiveAgent::GenerationJob#perform.
How to reproduce
ApplicationAgent.prompt(message: "Analyze this data").generate_later
Enqueue works. Performing the job fails.
Same for embeddings.
ApplicationAgent.embed(input: "Some text").embed_later
Expected
The background job should run the direct prompt or embed the same way generate_now / embed_now does.
Actual
The worker raises ArgumentError before any generation runs.
Tests
Existing coverage only checks that a job was enqueued. It mocks enqueue_generation and never performs the job.
Regression tests that call perform_enqueued_jobs fail with the error above.
test/features/parameterized_direct_test.rb
Agent.prompt(...).generate_later performs the job
Agent.embed(...).embed_later performs the job
Suggested fix
Teach GenerationJob#perform to handle the direct generation kwargs, or rebuild a DirectGeneration inside the job and call prompt_now / embed_now on it. Do not call the synthetic __direct_*__ action name as a real method.
Agent.prompt(...).generate_later fails when the job runs
Agent.prompt(...).generate_laterandAgent.embed(...).embed_laterenqueue successfully but crash when a worker executes the job. Docs and examples use this pattern, so anyone on Sidekiq or Solid Queue hits it in production.What happens
ActiveAgent::Parameterized::DirectGenerationpassesdirect_generation_type,direct_args, anddirect_optionsintoGenerationJob. The jobperformmethod does not accept those keyword arguments.The action name is also a synthetic
__direct_prompt__/__direct_embed__method that does not exist on the agent.Error
Raised from
ActiveAgent::GenerationJob#perform.How to reproduce
Enqueue works. Performing the job fails.
Same for embeddings.
Expected
The background job should run the direct prompt or embed the same way
generate_now/embed_nowdoes.Actual
The worker raises
ArgumentErrorbefore any generation runs.Tests
Existing coverage only checks that a job was enqueued. It mocks
enqueue_generationand never performs the job.Regression tests that call
perform_enqueued_jobsfail with the error above.Suggested fix
Teach
GenerationJob#performto handle the direct generation kwargs, or rebuild aDirectGenerationinside the job and callprompt_now/embed_nowon it. Do not call the synthetic__direct_*__action name as a real method.