Class: Insika::ContextBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/insika/context/builder.rb

Overview

Stage 2 of the pipeline: the Runtime NEVER builds the prompt — it asks the Builder for the package. Implements selection -> fan-out production -> collection/estimation -> budgeting with eviction -> canonical assembly.

Instance Method Summary collapse

Constructor Details

#initialize(providers:, event_stream:, hooks: Hooks.new, estimator: TokenEstimator) ⇒ ContextBuilder

Returns a new instance of ContextBuilder.



19
20
21
22
23
24
# File 'lib/insika/context/builder.rb', line 19

def initialize(providers:, event_stream:, hooks: Hooks.new, estimator: TokenEstimator)
  @providers = providers
  @event_stream = event_stream
  @hooks = hooks # prompt pair; empty Hooks = no-op
  @estimator = estimator
end

Instance Method Details

#call(request) ⇒ Object

The :prompt pair is wrapped HERE, not in the Executor: before_prompt can rewrite the ContextRequest (providers run with the modified one); after_prompt can rewrite the assembled ContextPackage. IMPORTANT: the Executor calls only builder.call(request) — do NOT wrap it with around(:prompt) again (double-wrapping would fire the hooks twice).



31
32
33
# File 'lib/insika/context/builder.rb', line 31

def call(request)
  @hooks.around(:prompt, request) { |req| build_package(req) }
end