Class: LanguageOperator::Dsl::MainDefinition
- Inherits:
-
Object
- Object
- LanguageOperator::Dsl::MainDefinition
- Includes:
- Loggable
- Defined in:
- lib/language_operator/dsl/main_definition.rb
Overview
Main execution block for agents (DSL v1)
Defines the imperative entry point for agent execution. The main block receives agent inputs and returns agent outputs. Within the block, agents can call tasks using execute_task(), use standard Ruby control flow (if/else, loops), and handle errors with standard Ruby exceptions.
This replaces the declarative workflow/step model with an imperative programming model centered on organic functions (tasks).
Instance Attribute Summary collapse
-
#execute_block ⇒ Object
readonly
Returns the value of attribute execute_block.
Instance Method Summary collapse
-
#call(inputs, context) ⇒ Object
Execute the main block with given inputs.
-
#defined? ⇒ Boolean
Check if main block is defined.
-
#execute {|inputs| ... } ⇒ void
Define the main execution block.
-
#initialize ⇒ MainDefinition
constructor
Initialize a new main definition.
Methods included from Loggable
Constructor Details
#initialize ⇒ MainDefinition
Initialize a new main definition
50 51 52 |
# File 'lib/language_operator/dsl/main_definition.rb', line 50 def initialize @execute_block = nil end |
Instance Attribute Details
#execute_block ⇒ Object (readonly)
Returns the value of attribute execute_block.
47 48 49 |
# File 'lib/language_operator/dsl/main_definition.rb', line 47 def execute_block @execute_block end |
Instance Method Details
#call(inputs, context) ⇒ Object
Execute the main block with given inputs
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/language_operator/dsl/main_definition.rb', line 79 def call(inputs, context) raise 'Main block not defined. Use execute { |inputs| ... } to define it.' unless @execute_block raise ArgumentError, "inputs must be a Hash, got #{inputs.class}" unless inputs.is_a?(Hash) logger.info('Executing main block', inputs_keys: inputs.keys) result = logger.timed('Main execution') do # Execute block in context to provide access to execute_task context.instance_exec(inputs, &@execute_block) end logger.info('Main block completed') result rescue StandardError => e logger.error('Main block execution failed', error: e.class.name, message: e., backtrace: e.backtrace&.first(5)) raise end |
#defined? ⇒ Boolean
Check if main block is defined
103 104 105 |
# File 'lib/language_operator/dsl/main_definition.rb', line 103 def defined? !@execute_block.nil? end |
#execute {|inputs| ... } ⇒ void
This method returns an undefined value.
Define the main execution block
65 66 67 68 69 70 |
# File 'lib/language_operator/dsl/main_definition.rb', line 65 def execute(&block) raise ArgumentError, 'Main block is required' unless block @execute_block = block logger.debug('Main block defined', arity: block.arity) end |