Class: Inquirex::LLM::DSL::LlmStepBuilder

Inherits:
Object
  • Object
show all
Includes:
DSL::RuleHelpers
Defined in:
lib/inquirex/llm/dsl/llm_step_builder.rb

Overview

Builds an LLM::Node from a step DSL block. Handles the LLM-specific methods (from, prompt, schema, model, temperature, max_tokens, fallback) while inheriting transition and skip_if from the core StepBuilder.

Examples:

clarify :business_extracted do
  from :business_description
  prompt "Extract structured business info."
  schema industry: :string, employee_count: :integer
  model :claude_sonnet
  temperature 0.2
  transition to: :next_step
end

Instance Method Summary collapse

Constructor Details

#initialize(verb) ⇒ LlmStepBuilder

Returns a new instance of LlmStepBuilder.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 22

def initialize(verb)
  @verb = verb.to_sym
  @prompt = nil
  @schema_fields = {}
  @from_steps = []
  @from_all = false
  @model = nil
  @temperature = nil
  @max_tokens = nil
  @fallback = nil
  @transitions = []
  @skip_if = nil
  @question = nil
  @text = nil
end

Instance Method Details

#build(id) ⇒ LLM::Node

Builds the LLM::Node.

Parameters:

  • id (Symbol)

Returns:

Raises:



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 134

def build(id)
  validate!(id)

  schema_obj = @schema_fields.empty? ? nil : Schema.new(**@schema_fields)

  LLM::Node.new(
    id:,
    verb:        @verb,
    prompt:      @prompt,
    schema:      schema_obj,
    from_steps:  @from_steps,
    from_all:    @from_all,
    model:       @model,
    temperature: @temperature,
    max_tokens:  @max_tokens,
    fallback:    @fallback,
    question:    @question,
    text:        @text,
    transitions: @transitions,
    skip_if:     @skip_if
  )
end

#fallback {|Hash| ... } ⇒ Object

Server-side fallback block, invoked when the LLM call fails. Stripped from JSON serialization.

Yields:

  • (Hash)

    answers collected so far

Returns:

  • (Object)

    fallback value to store as the answer



94
95
96
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 94

def fallback(&block)
  @fallback = block
end

#from(*step_ids) ⇒ Object

Adds source step id(s) whose answers feed the LLM prompt.

Parameters:

  • step_ids (Symbol, Array<Symbol>)

    one or more step ids



57
58
59
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 57

def from(*step_ids)
  @from_steps.concat(step_ids.flatten)
end

#from_all(value = true) ⇒ Object

Passes all collected answers to the LLM prompt.

Parameters:

  • value (Boolean) (defaults to: true)


64
65
66
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 64

def from_all(value = true)
  @from_all = !!value
end

#max_tokens(value) ⇒ Object

Optional maximum output tokens.

Parameters:

  • value (Integer)


85
86
87
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 85

def max_tokens(value)
  @max_tokens = value.to_i
end

#model(name) ⇒ Object

Optional model hint for the adapter.

Parameters:

  • name (Symbol)

    e.g. :claude_sonnet, :claude_haiku



71
72
73
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 71

def model(name)
  @model = name.to_sym
end

#prompt(text) ⇒ Object

Sets the LLM prompt template. Use {field_name} for interpolation placeholders that the adapter resolves at runtime.

Parameters:

  • text (String)


42
43
44
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 42

def prompt(text)
  @prompt = text
end

#question(content) ⇒ Object

Optional display text (used by describe/summarize for user-visible labels).

Parameters:

  • content (String)


118
119
120
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 118

def question(content)
  @question = content
end

#schema(**fields) ⇒ Object

Declares the expected output schema. Each key is a field name, each value is an Inquirex data type symbol.

Parameters:

  • fields (Hash{Symbol => Symbol})


50
51
52
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 50

def schema(**fields)
  @schema_fields.merge!(fields)
end

#skip_if(rule) ⇒ Object

Sets a rule that skips this step entirely when true.

Parameters:

  • rule (Rules::Base)


111
112
113
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 111

def skip_if(rule)
  @skip_if = rule
end

#temperature(value) ⇒ Object

Optional sampling temperature.

Parameters:

  • value (Float)


78
79
80
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 78

def temperature(value)
  @temperature = value.to_f
end

#text(content) ⇒ Object

Optional display text for context.

Parameters:

  • content (String)


125
126
127
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 125

def text(content)
  @text = content
end

#transition(to:, if_rule: nil, requires_server: true) ⇒ Object

Adds a conditional transition. Inherited concept from core DSL. All LLM transitions are implicitly requires_server: true.

Parameters:

  • to (Symbol)

    target step id

  • if_rule (Rules::Base, nil) (defaults to: nil)
  • requires_server (Boolean) (defaults to: true)


104
105
106
# File 'lib/inquirex/llm/dsl/llm_step_builder.rb', line 104

def transition(to:, if_rule: nil, requires_server: true)
  @transitions << Inquirex::Transition.new(target: to, rule: if_rule, requires_server:)
end