Skip to content

Commit e942f48

Browse files
authored
Add state to runnable (#17)
1 parent 0e73d77 commit e942f48

File tree

6 files changed

+21
-5
lines changed

6 files changed

+21
-5
lines changed

lib/mars/agent.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ module Mars
44
class Agent < Runnable
55
attr_reader :name
66

7-
def initialize(name:, options: {}, tools: [], schema: nil, instructions: nil)
7+
def initialize(name:, options: {}, tools: [], schema: nil, instructions: nil, **kwargs)
8+
super(**kwargs)
9+
810
@name = name
911
@tools = Array(tools)
1012
@schema = schema

lib/mars/aggregator.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ module Mars
44
class Aggregator < Runnable
55
attr_reader :name, :operation
66

7-
def initialize(name = "Aggregator", operation: nil)
7+
def initialize(name = "Aggregator", operation: nil, **kwargs)
8+
super(**kwargs)
9+
810
@name = name
911
@operation = operation || ->(inputs) { inputs.join("\n") }
1012
end

lib/mars/gate.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ module Mars
44
class Gate < Runnable
55
attr_reader :name
66

7-
def initialize(name:, condition:, branches:)
7+
def initialize(name:, condition:, branches:, **kwargs)
8+
super(**kwargs)
9+
810
@name = name
911
@condition = condition
1012
@branches = branches

lib/mars/runnable.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
module Mars
44
class Runnable
5+
attr_accessor :state
6+
7+
def initialize(state: {})
8+
@state = state
9+
end
10+
511
def run(input)
612
raise NotImplementedError
713
end

lib/mars/workflows/parallel.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ module Workflows
55
class Parallel < Runnable
66
attr_reader :name
77

8-
def initialize(name, steps:, aggregator: nil)
8+
def initialize(name, steps:, aggregator: nil, **kwargs)
9+
super(**kwargs)
10+
911
@name = name
1012
@steps = steps
1113
@aggregator = aggregator || Aggregator.new("#{name} Aggregator")

lib/mars/workflows/sequential.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ module Workflows
55
class Sequential < Runnable
66
attr_reader :name
77

8-
def initialize(name, steps:)
8+
def initialize(name, steps:, **kwargs)
9+
super(**kwargs)
10+
911
@name = name
1012
@steps = steps
1113
end

0 commit comments

Comments
 (0)