Class: ActiveAgent::Generation
- Inherits:
-
Object
- Object
- ActiveAgent::Generation
- Defined in:
- lib/active_agent/generation.rb
Overview
Deferred agent action ready for synchronous or asynchronous execution.
Returned when calling agent actions. Provides methods to execute immediately or queue for background processing, plus access to prompt properties before execution.
Direct Known Subclasses
Instance Method Summary collapse
- #actions ⇒ Array
-
#embed_later(options = {}) ⇒ Object
Queues embedding generation for background execution.
-
#embed_now ⇒ ActiveAgent::Providers::Response
Executes embedding generation synchronously.
-
#initialize(agent_class, action_name, *args, **kwargs) ⇒ Generation
constructor
A new instance of Generation.
- #instructions ⇒ Object
-
#message ⇒ ActiveAgent::Providers::Common::Messages::Base?
Returns the last message with consistent ‘.content` access.
- #messages ⇒ Array
-
#options ⇒ Hash
Configuration options excluding messages and actions.
- #processed? ⇒ Boolean
-
#prompt_later(options = {}) ⇒ Object
(also: #generate_later)
Queues for background execution.
-
#prompt_now ⇒ ActiveAgent::Providers::Response
(also: #generate_now)
Executes prompt generation synchronously.
-
#prompt_now! ⇒ ActiveAgent::Providers::Response
(also: #generate_now!)
Executes prompt generation synchronously with immediate processing.
-
#prompt_options ⇒ Hash
Accesses prompt options by processing the agent if needed.
-
#prompt_preview ⇒ String
(also: #preview_prompt)
Generates a preview of the prompt without executing generation.
Constructor Details
#initialize(agent_class, action_name, *args, **kwargs) ⇒ Generation
Returns a new instance of Generation.
29 30 31 |
# File 'lib/active_agent/generation.rb', line 29 def initialize(agent_class, action_name, *args, **kwargs) self.agent_class, self.action_name, self.args, self.kwargs = agent_class, action_name, args, kwargs end |
Instance Method Details
#actions ⇒ Array
76 77 78 |
# File 'lib/active_agent/generation.rb', line 76 def actions [:actions] || [] end |
#embed_later(options = {}) ⇒ Object
Queues embedding generation for background execution.
129 130 131 |
# File 'lib/active_agent/generation.rb', line 129 def ( = {}) enqueue_generation :embed_now, end |
#embed_now ⇒ ActiveAgent::Providers::Response
Executes embedding generation synchronously.
120 121 122 |
# File 'lib/active_agent/generation.rb', line 120 def agent. end |
#instructions ⇒ Object
53 54 55 |
# File 'lib/active_agent/generation.rb', line 53 def instructions agent.prompt_view_instructions([:instructions]) end |
#message ⇒ ActiveAgent::Providers::Common::Messages::Base?
Returns the last message with consistent ‘.content` access.
Wraps various message formats (String, Hash, objects) using the common MessageType for uniform access patterns.
68 69 70 71 72 73 |
# File 'lib/active_agent/generation.rb', line 68 def = .last return nil unless .cast() end |
#messages ⇒ Array
58 59 60 |
# File 'lib/active_agent/generation.rb', line 58 def [:messages] || [] end |
#options ⇒ Hash
Returns configuration options excluding messages and actions.
49 50 51 |
# File 'lib/active_agent/generation.rb', line 49 def .except(:messages, :actions) end |
#processed? ⇒ Boolean
34 35 36 |
# File 'lib/active_agent/generation.rb', line 34 def processed? !!@agent end |
#prompt_later(options = {}) ⇒ Object Also known as: generate_later
Queues for background execution.
101 102 103 |
# File 'lib/active_agent/generation.rb', line 101 def prompt_later( = {}) enqueue_generation :prompt_now, end |
#prompt_now ⇒ ActiveAgent::Providers::Response Also known as: generate_now
Executes prompt generation synchronously.
91 92 93 |
# File 'lib/active_agent/generation.rb', line 91 def prompt_now agent.process_prompt end |
#prompt_now! ⇒ ActiveAgent::Providers::Response Also known as: generate_now!
Executes prompt generation synchronously with immediate processing.
83 84 85 |
# File 'lib/active_agent/generation.rb', line 83 def prompt_now! agent.process_prompt! end |
#prompt_options ⇒ Hash
Accesses prompt options by processing the agent if needed.
Lazily processes the agent on first access, allowing inspection of prompt properties before executing generation.
44 45 46 |
# File 'lib/active_agent/generation.rb', line 44 def agent. end |
#prompt_preview ⇒ String Also known as: preview_prompt
Generates a preview of the prompt without executing generation.
Processes the agent action and renders the prompt configuration as markdown for debugging and inspection.
112 113 114 |
# File 'lib/active_agent/generation.rb', line 112 def prompt_preview agent.preview_prompt end |