Skip to content

Agent.prompt(...).generate_later (and embed_later) fails when the job executes #346

Description

@false200

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions