Class: LangGraphRB::Node
- Inherits:
-
Object
- Object
- LangGraphRB::Node
- Defined in:
- lib/langgraph_rb/node.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#call(state, context: nil) ⇒ Object
Execute the node with the given state and context Returns either a Hash (state delta), Command, or Send object.
-
#initialize(name, callable = nil, &block) ⇒ Node
constructor
A new instance of Node.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, callable = nil, &block) ⇒ Node
Returns a new instance of Node.
5 6 7 8 9 10 |
# File 'lib/langgraph_rb/node.rb', line 5 def initialize(name, callable = nil, &block) @name = name.to_sym @callable = callable || block raise NodeError, "Node '#{name}' must have a callable or block" unless @callable end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
3 4 5 |
# File 'lib/langgraph_rb/node.rb', line 3 def block @block end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/langgraph_rb/node.rb', line 3 def name @name end |
Instance Method Details
#call(state, context: nil) ⇒ Object
Execute the node with the given state and context Returns either a Hash (state delta), Command, or Send object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/langgraph_rb/node.rb', line 14 def call(state, context: nil) case @callable.arity when 0 @callable.call when 1 @callable.call(state) else @callable.call(state, context) end rescue => e raise NodeError, "Error executing node '#{@name}': #{e.}" end |
#inspect ⇒ Object
31 32 33 |
# File 'lib/langgraph_rb/node.rb', line 31 def inspect to_s end |
#to_s ⇒ Object
27 28 29 |
# File 'lib/langgraph_rb/node.rb', line 27 def to_s "#<Node:#{@name}>" end |