Class: OllamaAgent::LLM::CloudFallbackRouter

Inherits:
Object
  • Object
show all
Defined in:
lib/ollama_agent/llm/cloud_fallback_router.rb

Overview

Cloud escalation with deterministic depth / cost / wall-clock circuit breakers.

The clock_provider default uses Time.now.to_i only for breaker accounting (cost/time caps). Do not use this clock for saga orchestration stamps, kernel leases, or logical epochs.

Constant Summary collapse

OPUS_47_INPUT_USD_PER_MILLION =

Approximate public list pricing for claude-opus-4-7 (USD per million tokens). Replace with live billing data when available.

15.0
OPUS_47_OUTPUT_USD_PER_MILLION =
75.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(anthropic_client:, reentry_packet_builder:, cost_ledger: nil, max_escalation_depth: 1, cost_cap_usd: 5.00, time_cap_seconds: 600, clock_provider: -> { Time.now.to_i }) ⇒ CloudFallbackRouter

rubocop:disable Metrics/ParameterLists – explicit breaker + client configuration



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ollama_agent/llm/cloud_fallback_router.rb', line 18

def initialize(
  anthropic_client:,
  reentry_packet_builder:,
  cost_ledger: nil,
  max_escalation_depth: 1,
  cost_cap_usd: 5.00,
  time_cap_seconds: 600,
  clock_provider: -> { Time.now.to_i }
)
  @client = anthropic_client
  @reentry_packet_builder = reentry_packet_builder
  @cost_ledger = cost_ledger
  @max_escalation_depth = Integer(max_escalation_depth)
  @cost_cap_usd = cost_cap_usd.to_f
  @time_cap_seconds = Integer(time_cap_seconds)
  @clock = clock_provider
end

Instance Attribute Details

#reentry_packet_builderObject (readonly)

Returns the value of attribute reentry_packet_builder.



15
16
17
# File 'lib/ollama_agent/llm/cloud_fallback_router.rb', line 15

def reentry_packet_builder
  @reentry_packet_builder
end

Instance Method Details

#escalate(packet:, depth:, accumulated_cost_usd:, started_at:, manifest_id: nil) ⇒ Hash

Returns :result, :depth, :cost_usd, :halted_reason.

Returns:

  • (Hash)

    :result, :depth, :cost_usd, :halted_reason



38
39
40
41
42
43
44
45
# File 'lib/ollama_agent/llm/cloud_fallback_router.rb', line 38

def escalate(packet:, depth:, accumulated_cost_usd:, started_at:, manifest_id: nil)
  mid = (manifest_id || packet.workspace_fingerprint).to_s
  prior_cost = resolved_prior_cost(mid, accumulated_cost_usd.to_f)
  halted = breaker_halt(depth, prior_cost, started_at)
  return halted if halted

  invoke_anthropic(packet, Integer(depth), prior_cost, mid)
end