Class: RCrewAI::Flow::State

Inherits:
Object
  • Object
show all
Defined in:
lib/rcrewai/flow/state.rb

Overview

Mutable, schemaless flow state with a stable unique id. Access attributes as methods (state.foo, state.foo = 1) or via [] / to_h. Mirrors CrewAI's unstructured (dict-based) flow state, with an automatic UUID.

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ State

Returns a new instance of State.



11
12
13
14
15
# File 'lib/rcrewai/flow/state.rb', line 11

def initialize(attributes = {})
  @attributes = {}
  attributes.each { |k, v| @attributes[k.to_sym] = v }
  @attributes[:id] ||= SecureRandom.uuid
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/rcrewai/flow/state.rb', line 37

def method_missing(name, *args)
  key = name.to_s
  if key.end_with?('=')
    @attributes[key[0..-2].to_sym] = args.first
  else
    @attributes[name]
  end
end

Instance Method Details

#[](key) ⇒ Object



21
22
23
# File 'lib/rcrewai/flow/state.rb', line 21

def [](key)
  @attributes[key.to_sym]
end

#[]=(key, value) ⇒ Object



25
26
27
# File 'lib/rcrewai/flow/state.rb', line 25

def []=(key, value)
  @attributes[key.to_sym] = value
end

#idObject



17
18
19
# File 'lib/rcrewai/flow/state.rb', line 17

def id
  @attributes[:id]
end

#respond_to_missing?(_name, _include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/rcrewai/flow/state.rb', line 33

def respond_to_missing?(_name, _include_private = false)
  true
end

#to_hObject



29
30
31
# File 'lib/rcrewai/flow/state.rb', line 29

def to_h
  @attributes.dup
end