Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/active_agent/generation_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,19 @@ class GenerationJob < ActiveJob::Base # :nodoc:

rescue_from StandardError, with: :handle_exception_with_agent_class

def perform(agent, agent_method, generation_method, args:, kwargs: nil, params: nil)
def perform(agent, agent_method, generation_method, args:, kwargs: nil, params: nil,
direct_generation_type: nil, direct_args: nil, direct_options: nil)
if direct_generation_type
generation = ActiveAgent::Parameterized::DirectGeneration.new(
agent.constantize,
direct_generation_type.to_sym,
params || {},
*Array(direct_args),
**(direct_options || {}).to_h.deep_symbolize_keys
)
return generation.send(generation_method)
end

agent_class = params ? agent.constantize.with(params) : agent.constantize
prompt = if kwargs
agent_class.public_send(agent_method, *args, **kwargs)
Expand Down
18 changes: 18 additions & 0 deletions test/features/parameterized_direct_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require "test_helper"

class ParameterizedDirectTest < ActiveSupport::TestCase
include ActiveJob::TestHelper

class TestAgent < ActiveAgent::Base
generate_with :mock, model: "mock-model", instructions: "You are a helpful assistant."
embed_with :mock, model: "mock-embedding-model"
Expand Down Expand Up @@ -107,6 +109,14 @@ def enqueue_options
assert_equal({ queue: :prompts, priority: :high }, generation.enqueue_options)
end

test "Agent.prompt(...).generate_later performs the job" do
assert_nothing_raised do
perform_enqueued_jobs only: ActiveAgent::GenerationJob do
TestAgent.prompt(message: "Background task").generate_later
end
end
end

test "Agent.embed returns a generation proxy" do
generation = TestAgent.embed(input: "Text to embed")

Expand Down Expand Up @@ -212,6 +222,14 @@ def enqueue_options
assert_equal({ queue: :embeddings, priority: :low }, generation.enqueue_options)
end

test "Agent.embed(...).embed_later performs the job" do
assert_nothing_raised do
perform_enqueued_jobs only: ActiveAgent::GenerationJob do
TestAgent.embed(input: "Background embedding").embed_later
end
end
end

test "prompt() works alongside existing with() method" do
# Original with() method still works
agent_class_with_action = Class.new(TestAgent) do
Expand Down