Class: RubyLlmMesh::SovereignMesh

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_llm_mesh/sovereign_mesh.rb,
sig/ruby_llm_mesh.rbs

Overview

Sovereign mesh orchestrator — native P2P node + cloud failover strategies.

Constant Summary collapse

STRATEGIES =
%i[auto p2p_mesh cloud openai anthropic local_node local_mesh].freeze

Instance Method Summary collapse

Constructor Details

#initialize(config: RubyLlmMesh.configuration, router: nil) ⇒ SovereignMesh

Returns a new instance of SovereignMesh.



10
11
12
13
# File 'lib/ruby_llm_mesh/sovereign_mesh.rb', line 10

def initialize(config: RubyLlmMesh.configuration, router: nil)
  @config = config
  @router = router || Router.new(config: config)
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/ruby_llm_mesh/sovereign_mesh.rb', line 23

def alive?
  NativeCore.node_alive?
end

#boot!(port: @config.mesh_port) ⇒ Boolean

Parameters:

  • port: (Integer) (defaults to: @config.mesh_port)

Returns:

  • (Boolean)


15
16
17
# File 'lib/ruby_llm_mesh/sovereign_mesh.rb', line 15

def boot!(port: @config.mesh_port)
  NativeCore.start_node(port)
end

#execute(intent:, strategy: :auto, **options) ⇒ Response

Execute an intent with a routing strategy.

Strategies:

  • :auto — native mesh when alive (or auto-boot), else cloud ladder
  • :p2p_mesh — native chimera_core only
  • :cloud — real HTTP via fallback_providers / default_providers
  • :openai / :anthropic / :local_node / :local_mesh — single-provider cloud/local

Parameters:

  • intent: (String)
  • strategy: (Symbol) (defaults to: :auto)
  • (Object)

Returns:

Raises:

  • (ArgumentError)


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ruby_llm_mesh/sovereign_mesh.rb', line 34

def execute(intent:, strategy: :auto, **options)
  raise ArgumentError, "intent is required" if intent.nil? || intent.to_s.strip.empty?

  strategy = strategy.to_sym
  unless STRATEGIES.include?(strategy)
    raise ArgumentError, "Unknown strategy: #{strategy.inspect} (expected one of #{STRATEGIES.join(', ')})"
  end

  started = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  result = case strategy
           when :p2p_mesh
             execute_p2p(intent)
           when :cloud
             execute_cloud(intent, **options)
           when :openai, :anthropic, :local_node, :local_mesh
             execute_cloud(intent, providers: [strategy], **options)
           else # :auto
             execute_auto(intent, **options)
           end

  latency_ms = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - started) * 1000).round
  normalize_result(result, latency_ms: latency_ms, strategy: strategy)
end

#shutdown!Object



19
20
21
# File 'lib/ruby_llm_mesh/sovereign_mesh.rb', line 19

def shutdown!
  NativeCore.stop_node
end