Class: ActiveAgent::Parameterized::DirectGeneration Private

Inherits:
Generation show all
Defined in:
lib/active_agent/concerns/parameterized.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A specialized generation class for direct prompt/embed calls without actions.

This class handles cases where you want to call Agent.prompt(…).generate_now or Agent.embed(…).generate_now without defining an action method.

Instance Method Summary collapse

Methods inherited from Generation

#actions, #embed_later, #embed_now, #instructions, #message, #messages, #options, #processed?, #prompt_later, #prompt_now, #prompt_now!, #prompt_options, #prompt_preview

Constructor Details

#initialize(agent_class, generation_type, params, *args, **options) ⇒ DirectGeneration

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of DirectGeneration.

Parameters:

  • agent_class (Class)

    the agent class

  • generation_type (Symbol)

    either :prompt or :embed

  • params (Hash)

    the parameters to set on the agent instance

  • args (Array)

    messages for prompt or input for embed

  • options (Hash)

    additional options (temperature, model, etc.)



202
203
204
205
206
207
208
209
# File 'lib/active_agent/concerns/parameterized.rb', line 202

def initialize(agent_class, generation_type, params, *args, **options)
  @generation_type = generation_type
  @direct_args = args
  @direct_options = options

  # Use a synthetic action name that won't conflict with real methods
  super(agent_class, :"__direct_#{generation_type}__", params)
end

Instance Method Details

#generate_nowObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Override generate_now to route to correct method based on generation type



212
213
214
215
216
217
218
219
# File 'lib/active_agent/concerns/parameterized.rb', line 212

def generate_now
  case @generation_type
  when :prompt
    prompt_now
  when :embed
    embed_now
  end
end

#generate_now!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Override generate_now! to route to correct method based on generation type



222
223
224
225
226
227
228
229
230
# File 'lib/active_agent/concerns/parameterized.rb', line 222

def generate_now!
  case @generation_type
  when :prompt
    prompt_now!
  when :embed
    # For embed, we don't have a separate embed_now! method, so use embed_now
    embed_now
  end
end

#previewString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Generates a preview based on generation type.

Returns:

  • (String)

    markdown-formatted preview for prompt generations

Raises:

  • (NotImplementedError)

    for embed generations (not yet supported)



236
237
238
239
240
241
242
243
# File 'lib/active_agent/concerns/parameterized.rb', line 236

def preview
  case @generation_type
  when :prompt
    prompt_preview
  when :embed
    raise NotImplementedError, "Embed previewing is not supported"
  end
end