Class: AgentRuntime::State
- Inherits:
-
Object
- Object
- AgentRuntime::State
- Defined in:
- lib/agent_runtime/state.rb
Overview
Explicit, serializable state management with deep merge support.
This class manages the agent’s state throughout execution. State is stored as a hash and can be snapshotted for read-only access. Updates are applied using deep merge to preserve nested structures.
Instance Method Summary collapse
-
#apply!(result) ⇒ void
Apply a result hash to the state using deep merge.
-
#initialize(data = {}) ⇒ State
constructor
Initialize a new State instance.
-
#snapshot ⇒ Hash
Create a snapshot of the current state.
Constructor Details
#initialize(data = {}) ⇒ State
Initialize a new State instance.
25 26 27 |
# File 'lib/agent_runtime/state.rb', line 25 def initialize(data = {}) @data = data end |
Instance Method Details
#apply!(result) ⇒ void
This method returns an undefined value.
Apply a result hash to the state using deep merge.
Merges the result hash into the current state, preserving nested structures. If result is not a hash, this method does nothing.
56 57 58 59 60 |
# File 'lib/agent_runtime/state.rb', line 56 def apply!(result) return unless result.is_a?(Hash) deep_merge!(@data, result) end |
#snapshot ⇒ Hash
Create a snapshot of the current state.
Returns a shallow copy of the state data. Modifications to the snapshot will not affect the original state.
39 40 41 |
# File 'lib/agent_runtime/state.rb', line 39 def snapshot @data.dup end |