Class: DeepAgents::DeepAgentState
- Inherits:
-
Object
- Object
- DeepAgents::DeepAgentState
- Defined in:
- lib/deepagents/state.rb
Overview
Deep agent state class
Instance Attribute Summary collapse
-
#files ⇒ Object
Returns the value of attribute files.
-
#messages ⇒ Object
Returns the value of attribute messages.
-
#todos ⇒ Object
Returns the value of attribute todos.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #get(key, default = nil) ⇒ Object
-
#initialize ⇒ DeepAgentState
constructor
A new instance of DeepAgentState.
- #to_h ⇒ Object
- #update(todos: nil, files: nil, messages: nil) ⇒ Object
Constructor Details
#initialize ⇒ DeepAgentState
Returns a new instance of DeepAgentState.
47 48 49 50 51 |
# File 'lib/deepagents/state.rb', line 47 def initialize @todos = [] @files = {} = [] end |
Instance Attribute Details
#files ⇒ Object
Returns the value of attribute files.
45 46 47 |
# File 'lib/deepagents/state.rb', line 45 def files @files end |
#messages ⇒ Object
Returns the value of attribute messages.
45 46 47 |
# File 'lib/deepagents/state.rb', line 45 def end |
#todos ⇒ Object
Returns the value of attribute todos.
45 46 47 |
# File 'lib/deepagents/state.rb', line 45 def todos @todos end |
Instance Method Details
#[](key) ⇒ Object
100 101 102 |
# File 'lib/deepagents/state.rb', line 100 def [](key) get(key) end |
#[]=(key, value) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/deepagents/state.rb', line 104 def []=(key, value) case key.to_s when "todos" self.todos = value when "files" self.files = value when "messages" self. = value else raise ArgumentError, "Unknown state key: #{key}" end end |
#get(key, default = nil) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/deepagents/state.rb', line 67 def get(key, default = nil) case key.to_s when "todos" @todos when "files" @files when "messages" else default end end |
#to_h ⇒ Object
117 118 119 120 121 122 123 |
# File 'lib/deepagents/state.rb', line 117 def to_h { todos: @todos.map(&:to_h), files: @files, messages: } end |
#update(todos: nil, files: nil, messages: nil) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/deepagents/state.rb', line 80 def update(todos: nil, files: nil, messages: nil) begin if todos @todos = validate_todos(todos) end if files raise ArgumentError, "Files must be a hash" unless files.is_a?(Hash) @files.merge!(files) end if raise ArgumentError, "Messages must be an array" unless .is_a?(Array) += end rescue => e raise StateError, "Failed to update state: #{e.message}" end end |