Class: RLM::Runtime
- Inherits:
-
Object
- Object
- RLM::Runtime
- Defined in:
- lib/rlm/runtime.rb,
lib/rlm/runtime/bridge.rb,
lib/rlm/runtime/signature_registry.rb
Overview
rubocop:disable Metrics/ClassLength
Defined Under Namespace
Classes: Bridge, SignatureRegistry
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(signature:, input:, lm:, sandbox:, limits:, sub_lm: nil, context: nil, tools: [], skills: [], validators: [], signatures: [], depth: 0, trace_store: nil) ⇒ Runtime
constructor
A new instance of Runtime.
- #predict_subcall(signature, input, depth:) ⇒ Object
- #record_submitted_output(output) ⇒ Object
- #record_tool_attempt! ⇒ Object
Constructor Details
#initialize(signature:, input:, lm:, sandbox:, limits:, sub_lm: nil, context: nil, tools: [], skills: [], validators: [], signatures: [], depth: 0, trace_store: nil) ⇒ Runtime
Returns a new instance of Runtime.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rlm/runtime.rb', line 20 def initialize( signature:, input:, lm:, sandbox:, limits:, sub_lm: nil, context: nil, tools: [], skills: [], validators: [], signatures: [], depth: 0, trace_store: nil ) @signature = signature @input = input || {} @lm = lm @sub_lm = sub_lm || lm @sandbox = sandbox @limits = limits || Limits.new @context = context || build_context(@input) @tools = Array(tools) @skills = Array(skills) @validators = Array(validators) @signatures = SignatureRegistry.build(signature, signatures) @depth = depth @trace_store = trace_store @trace = Trace.new @iterations = 0 @llm_calls = 0 @sub_lm_calls = 0 @tool_calls = 0 @last_submitted_output = nil end |
Instance Method Details
#call ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/rlm/runtime.rb', line 56 def call raise ProviderError, "root LM is required" if lm.nil? start_run bridge = prepare_sandbox run_loop(bridge) rescue BudgetExceededError => e budget_exceeded_result(e) rescue ToolError => e finish(:tool_error, error: e) rescue ProviderError => e finish(:provider_error, error: e) rescue SandboxError => e finish(:sandbox_error, error: e) rescue ValidationError => e validation_failure([e.], e) rescue ParseError, ConfigurationError => e finish(:aborted, error: e) ensure sandbox&.cleanup end |
#predict_subcall(signature, input, depth:) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/rlm/runtime.rb', line 78 def predict_subcall(signature, input, depth:) raise BudgetExceededError, "max_recursion_depth exceeded" if depth > limits.max_recursion_depth raise ProviderError, "sub LM is required" if sub_lm.nil? parsed = call_sub_lm(signature, input, depth) raise ValidationError, "sub LM must return <rlm-final> in v0.2 mock runtime" unless parsed.final? output = Signature.coerce_output(signature, parsed.content) validate_output!(signature, output) output end |
#record_submitted_output(output) ⇒ Object
97 98 99 |
# File 'lib/rlm/runtime.rb', line 97 def record_submitted_output(output) @last_submitted_output = output end |
#record_tool_attempt! ⇒ Object
90 91 92 93 94 95 |
# File 'lib/rlm/runtime.rb', line 90 def record_tool_attempt! trace.record(:budget_checked, budget: :tool_calls, current: @tool_calls, limit: limits.max_tool_calls) raise BudgetExceededError, "max_tool_calls exceeded" if @tool_calls >= limits.max_tool_calls @tool_calls += 1 end |