Class: Flux::Runtime::Agent

Inherits:
Object
  • Object
show all
Defined in:
lib/superinstance/flux-runtime/runtime/agent.rb

Overview

Agent shell that wraps a FluxVM and provides method_missing for PLATO-based capability lookup

Examples:

agent = Flux::Runtime::Agent.new
agent.load(bytecode)
agent.run

with PLATO

client = PLATO::Client.new
agent = Flux::Runtime::Agent.new(plato_client: client, vessel_id: 'my-agent')

# Unknown method triggers PLATO lookup
result = agent.learned_capability(arg1, arg2)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plato_client: nil, vessel_id: nil) ⇒ Agent

Returns a new instance of Agent.



25
26
27
28
29
30
# File 'lib/superinstance/flux-runtime/runtime/agent.rb', line 25

def initialize(plato_client: nil, vessel_id: nil)
  @vm = FluxVM.new
  @plato = plato_client
  @vessel_id = vessel_id
  @capabilities = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object

Delegate unknown methods to VM if they exist there Otherwise, look up in PLATO



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/superinstance/flux-runtime/runtime/agent.rb', line 73

def method_missing(method_name, *args, &block)
  # Check if it's a VM method
  if @vm.respond_to?(method_name)
    @vm.send(method_name, *args, &block)
  else
    # Look up capability in PLATO
    capability = lookup_capability(method_name)

    if capability
      execute_capability(capability, *args, &block)
    else
      super
    end
  end
end

Instance Attribute Details

#vessel_idObject (readonly)

Returns the value of attribute vessel_id.



23
24
25
# File 'lib/superinstance/flux-runtime/runtime/agent.rb', line 23

def vessel_id
  @vessel_id
end

#vmObject (readonly)

Returns the value of attribute vm.



23
24
25
# File 'lib/superinstance/flux-runtime/runtime/agent.rb', line 23

def vm
  @vm
end

Instance Method Details

#load(bytecode) ⇒ Object

Load bytecode into the VM



33
34
35
36
# File 'lib/superinstance/flux-runtime/runtime/agent.rb', line 33

def load(bytecode)
  @vm.load(bytecode)
  self
end

#regsObject

Get register values



62
63
64
# File 'lib/superinstance/flux-runtime/runtime/agent.rb', line 62

def regs
  @vm.regs
end

#resetObject

Reset the VM



51
52
53
54
# File 'lib/superinstance/flux-runtime/runtime/agent.rb', line 51

def reset
  @vm.reset
  self
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Proper introspection support

Returns:

  • (Boolean)


90
91
92
93
94
# File 'lib/superinstance/flux-runtime/runtime/agent.rb', line 90

def respond_to_missing?(method_name, include_private = false)
  @vm.respond_to?(method_name, include_private) ||
    lookup_capability(method_name) ||
    super
end

#run(max_cycles: nil) ⇒ Object

Run the VM



39
40
41
42
# File 'lib/superinstance/flux-runtime/runtime/agent.rb', line 39

def run(max_cycles: nil)
  @vm.run(max_cycles: max_cycles)
  self
end

#stateObject

Get current state



57
58
59
# File 'lib/superinstance/flux-runtime/runtime/agent.rb', line 57

def state
  @vm.state
end

#statsObject

Get execution stats



67
68
69
# File 'lib/superinstance/flux-runtime/runtime/agent.rb', line 67

def stats
  @vm.stats
end

#stepObject

Step one instruction



45
46
47
48
# File 'lib/superinstance/flux-runtime/runtime/agent.rb', line 45

def step
  @vm.step
  self
end