Class: ActiveHarness::Pipeline::Step

Inherits:
Object
  • Object
show all
Defined in:
lib/active_harness/pipeline/step.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, agent_class = nil, &block) ⇒ Step

Returns a new instance of Step.



6
7
8
9
10
11
# File 'lib/active_harness/pipeline/step.rb', line 6

def initialize(name, agent_class = nil, &block)
  @name        = name
  @agent_class = agent_class
  @stop_if     = nil
  instance_eval(&block) if block_given?
end

Instance Attribute Details

#agent_classObject (readonly)

Returns the value of attribute agent_class.



4
5
6
# File 'lib/active_harness/pipeline/step.rb', line 4

def agent_class
  @agent_class
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/active_harness/pipeline/step.rb', line 4

def name
  @name
end

Instance Method Details

#extract_payload(result) ⇒ Object

Extract the new payload value from result. Uses the user-defined transform block when present; falls back to result.output.



53
54
55
# File 'lib/active_harness/pipeline/step.rb', line 53

def extract_payload(result)
  @transform_block ? @transform_block.call(result) : result.output
end

#stop_if(lam = nil) ⇒ Object

DSL (inside block): stop_if ->(result) { … } Getter (external): step.stop_if → lambda or nil



20
21
22
# File 'lib/active_harness/pipeline/step.rb', line 20

def stop_if(lam = nil)
  lam ? @stop_if = lam : @stop_if
end

#transform(&block) ⇒ Object

DSL: define how to extract the new payload from a result. When provided, the step always updates the payload — even if stop_if is also set. The block receives the Result and must return the new payload value.

step :laundry do
  use PromptLaundryPipeline
  transform { |result| result.output }
  stop_if   ->(result) { result.processed["stopped"] == true }
end


33
34
35
36
# File 'lib/active_harness/pipeline/step.rb', line 33

def transform(&block)
  @transform_block = block if block
  @transform_block
end

#transform?Boolean

Returns true when this step should update the pipeline payload after execution. A step transforms when:

- an explicit transform block is defined (overrides default), OR
- no stop_if and not a tribunal (legacy default)

Returns:

  • (Boolean)


47
48
49
# File 'lib/active_harness/pipeline/step.rb', line 47

def transform?
  @transform_block ? true : (!tribunal? && @stop_if.nil?)
end

#tribunal?Boolean

True if agent_class is a Tribunal subclass — tribunal steps do not update payload.

Returns:

  • (Boolean)


39
40
41
# File 'lib/active_harness/pipeline/step.rb', line 39

def tribunal?
  @agent_class.is_a?(Class) && @agent_class <= ActiveHarness::Tribunal
end

#use(klass) ⇒ Object

DSL: use TranslationAgent



14
15
16
# File 'lib/active_harness/pipeline/step.rb', line 14

def use(klass)
  @agent_class = klass
end