mars_rb 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +38 -0
- data/README.md +183 -12
- data/examples/complex_llm_workflow/diagram.md +32 -0
- data/examples/complex_llm_workflow/generator.rb +112 -0
- data/examples/complex_workflow/diagram.md +47 -0
- data/examples/complex_workflow/generator.rb +108 -0
- data/examples/parallel_workflow/diagram.md +21 -0
- data/examples/parallel_workflow/generator.rb +33 -0
- data/examples/simple_workflow/diagram.md +26 -0
- data/examples/simple_workflow/generator.rb +48 -0
- data/lib/mars/agent_step.rb +15 -0
- data/lib/mars/aggregator.rb +24 -0
- data/lib/mars/execution_context.rb +35 -0
- data/lib/mars/formatter.rb +13 -0
- data/lib/mars/gate.rb +52 -0
- data/lib/mars/hooks.rb +35 -0
- data/lib/mars/rendering/graph/agent_step.rb +18 -0
- data/lib/mars/rendering/graph/aggregator.rb +17 -0
- data/lib/mars/rendering/graph/base.rb +32 -0
- data/lib/mars/rendering/graph/builder.rb +43 -0
- data/lib/mars/rendering/graph/gate.rb +22 -0
- data/lib/mars/rendering/graph/node.rb +22 -0
- data/lib/mars/rendering/graph/parallel_workflow.rb +34 -0
- data/lib/mars/rendering/graph/runnable.rb +18 -0
- data/lib/mars/rendering/graph/sequential_workflow.rb +39 -0
- data/lib/mars/rendering/graph/subgraph.rb +17 -0
- data/lib/mars/rendering/graph.rb +16 -0
- data/lib/mars/rendering/html.rb +37 -0
- data/lib/mars/rendering/mermaid.rb +71 -0
- data/lib/mars/runnable.rb +26 -2
- data/lib/mars/version.rb +2 -2
- data/lib/mars/workflows/aggregate_error.rb +14 -0
- data/lib/mars/workflows/parallel.rb +61 -0
- data/lib/mars/workflows/sequential.rb +26 -8
- data/lib/mars.rb +12 -3
- data/lib/mars_rb.rb +3 -0
- data/sig/mars.rbs +1 -1
- metadata +81 -8
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module MARS
|
|
4
|
+
module Workflows
|
|
5
|
+
class Parallel < Runnable
|
|
6
|
+
def initialize(name, steps:, aggregator: nil, **kwargs)
|
|
7
|
+
super(name: name, **kwargs)
|
|
8
|
+
|
|
9
|
+
@steps = steps
|
|
10
|
+
@aggregator = aggregator || Aggregator.new("#{name} Aggregator")
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def run(context)
|
|
14
|
+
context = ensure_context(context)
|
|
15
|
+
child_contexts = []
|
|
16
|
+
results = execute_steps(context, child_contexts)
|
|
17
|
+
|
|
18
|
+
context.merge(child_contexts)
|
|
19
|
+
context.current_input = results
|
|
20
|
+
aggregator.run(context)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
attr_reader :steps, :aggregator
|
|
26
|
+
|
|
27
|
+
def execute_steps(context, child_contexts)
|
|
28
|
+
Sync do |workflow|
|
|
29
|
+
tasks = steps.map do |step|
|
|
30
|
+
child_ctx = context.fork(state: step.state)
|
|
31
|
+
child_contexts << child_ctx
|
|
32
|
+
|
|
33
|
+
workflow.async do
|
|
34
|
+
workflow_step(step, child_ctx)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
tasks.map(&:wait)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def workflow_step(step, child_ctx)
|
|
43
|
+
step.run_before_hooks(child_ctx)
|
|
44
|
+
|
|
45
|
+
step_input = step.formatter.format_input(child_ctx)
|
|
46
|
+
child_ctx.current_input = step_input
|
|
47
|
+
|
|
48
|
+
result = step.run(child_ctx)
|
|
49
|
+
|
|
50
|
+
formatted = step.formatter.format_output(result)
|
|
51
|
+
child_ctx.record(step.name, formatted)
|
|
52
|
+
step.run_after_hooks(child_ctx, formatted)
|
|
53
|
+
formatted
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def ensure_context(input)
|
|
57
|
+
input.is_a?(ExecutionContext) ? input : ExecutionContext.new(input: input)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -1,21 +1,39 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
module Mars
|
|
3
|
+
module MARS
|
|
6
4
|
module Workflows
|
|
7
5
|
class Sequential < Runnable
|
|
8
|
-
def initialize(name, steps
|
|
9
|
-
|
|
6
|
+
def initialize(name, steps:, **kwargs)
|
|
7
|
+
super(name: name, **kwargs)
|
|
8
|
+
|
|
10
9
|
@steps = steps
|
|
11
10
|
end
|
|
12
11
|
|
|
13
|
-
def run(
|
|
12
|
+
def run(context)
|
|
13
|
+
context = ensure_context(context)
|
|
14
|
+
|
|
14
15
|
@steps.each do |step|
|
|
15
|
-
|
|
16
|
+
step.run_before_hooks(context)
|
|
17
|
+
|
|
18
|
+
step_input = step.formatter.format_input(context)
|
|
19
|
+
context.current_input = step_input
|
|
20
|
+
|
|
21
|
+
result = step.run(context)
|
|
22
|
+
|
|
23
|
+
formatted = step.formatter.format_output(result)
|
|
24
|
+
context.record(step.name, formatted)
|
|
25
|
+
step.run_after_hooks(context, formatted)
|
|
16
26
|
end
|
|
17
27
|
|
|
18
|
-
|
|
28
|
+
context.current_input
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
attr_reader :steps
|
|
34
|
+
|
|
35
|
+
def ensure_context(input)
|
|
36
|
+
input.is_a?(ExecutionContext) ? input : ExecutionContext.new(input: input)
|
|
19
37
|
end
|
|
20
38
|
end
|
|
21
39
|
end
|
data/lib/mars.rb
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require "zeitwerk"
|
|
4
|
+
require "async"
|
|
5
|
+
require "ruby_llm"
|
|
6
|
+
require "ruby_llm/schema"
|
|
4
7
|
|
|
5
|
-
|
|
8
|
+
loader = Zeitwerk::Loader.for_gem
|
|
9
|
+
loader.inflector.inflect("mars" => "MARS")
|
|
10
|
+
loader.ignore("#{__dir__}/mars_rb.rb")
|
|
11
|
+
loader.setup
|
|
12
|
+
|
|
13
|
+
module MARS
|
|
6
14
|
class Error < StandardError; end
|
|
7
|
-
# Your code goes here...
|
|
8
15
|
end
|
|
16
|
+
|
|
17
|
+
MARS::Rendering::Graph.include_extensions
|
data/lib/mars_rb.rb
ADDED
data/sig/mars.rbs
CHANGED
metadata
CHANGED
|
@@ -1,20 +1,62 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mars_rb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Santiago Bartesaghi
|
|
8
8
|
- Andres Garcia
|
|
9
9
|
- Ignacio Perez
|
|
10
10
|
- Santiago Diaz
|
|
11
|
-
autorequire:
|
|
11
|
+
autorequire:
|
|
12
12
|
bindir: exe
|
|
13
13
|
cert_chain: []
|
|
14
|
-
date:
|
|
15
|
-
dependencies:
|
|
14
|
+
date: 2026-07-29 00:00:00.000000000 Z
|
|
15
|
+
dependencies:
|
|
16
|
+
- !ruby/object:Gem::Dependency
|
|
17
|
+
name: async
|
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
|
19
|
+
requirements:
|
|
20
|
+
- - "~>"
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: '2.34'
|
|
23
|
+
type: :runtime
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
+
requirements:
|
|
27
|
+
- - "~>"
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '2.34'
|
|
30
|
+
- !ruby/object:Gem::Dependency
|
|
31
|
+
name: ruby_llm
|
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
|
33
|
+
requirements:
|
|
34
|
+
- - "~>"
|
|
35
|
+
- !ruby/object:Gem::Version
|
|
36
|
+
version: '1.12'
|
|
37
|
+
type: :runtime
|
|
38
|
+
prerelease: false
|
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
40
|
+
requirements:
|
|
41
|
+
- - "~>"
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: '1.12'
|
|
44
|
+
- !ruby/object:Gem::Dependency
|
|
45
|
+
name: zeitwerk
|
|
46
|
+
requirement: !ruby/object:Gem::Requirement
|
|
47
|
+
requirements:
|
|
48
|
+
- - "~>"
|
|
49
|
+
- !ruby/object:Gem::Version
|
|
50
|
+
version: '2.7'
|
|
51
|
+
type: :runtime
|
|
52
|
+
prerelease: false
|
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
54
|
+
requirements:
|
|
55
|
+
- - "~>"
|
|
56
|
+
- !ruby/object:Gem::Version
|
|
57
|
+
version: '2.7'
|
|
16
58
|
description: MARS (Multi-Agent Ruby SDK) provides a comprehensive framework for developers
|
|
17
|
-
to
|
|
59
|
+
to implementmulti-agent solutions using pure Ruby. It offers a simple API for orchestrating
|
|
18
60
|
multiple agents.
|
|
19
61
|
email:
|
|
20
62
|
- sbartesaghi@hotmail.com
|
|
@@ -32,10 +74,40 @@ files:
|
|
|
32
74
|
- LICENSE.txt
|
|
33
75
|
- README.md
|
|
34
76
|
- Rakefile
|
|
77
|
+
- examples/complex_llm_workflow/diagram.md
|
|
78
|
+
- examples/complex_llm_workflow/generator.rb
|
|
79
|
+
- examples/complex_workflow/diagram.md
|
|
80
|
+
- examples/complex_workflow/generator.rb
|
|
81
|
+
- examples/parallel_workflow/diagram.md
|
|
82
|
+
- examples/parallel_workflow/generator.rb
|
|
83
|
+
- examples/simple_workflow/diagram.md
|
|
84
|
+
- examples/simple_workflow/generator.rb
|
|
35
85
|
- lib/mars.rb
|
|
86
|
+
- lib/mars/agent_step.rb
|
|
87
|
+
- lib/mars/aggregator.rb
|
|
88
|
+
- lib/mars/execution_context.rb
|
|
89
|
+
- lib/mars/formatter.rb
|
|
90
|
+
- lib/mars/gate.rb
|
|
91
|
+
- lib/mars/hooks.rb
|
|
92
|
+
- lib/mars/rendering/graph.rb
|
|
93
|
+
- lib/mars/rendering/graph/agent_step.rb
|
|
94
|
+
- lib/mars/rendering/graph/aggregator.rb
|
|
95
|
+
- lib/mars/rendering/graph/base.rb
|
|
96
|
+
- lib/mars/rendering/graph/builder.rb
|
|
97
|
+
- lib/mars/rendering/graph/gate.rb
|
|
98
|
+
- lib/mars/rendering/graph/node.rb
|
|
99
|
+
- lib/mars/rendering/graph/parallel_workflow.rb
|
|
100
|
+
- lib/mars/rendering/graph/runnable.rb
|
|
101
|
+
- lib/mars/rendering/graph/sequential_workflow.rb
|
|
102
|
+
- lib/mars/rendering/graph/subgraph.rb
|
|
103
|
+
- lib/mars/rendering/html.rb
|
|
104
|
+
- lib/mars/rendering/mermaid.rb
|
|
36
105
|
- lib/mars/runnable.rb
|
|
37
106
|
- lib/mars/version.rb
|
|
107
|
+
- lib/mars/workflows/aggregate_error.rb
|
|
108
|
+
- lib/mars/workflows/parallel.rb
|
|
38
109
|
- lib/mars/workflows/sequential.rb
|
|
110
|
+
- lib/mars_rb.rb
|
|
39
111
|
- sig/mars.rbs
|
|
40
112
|
homepage: https://github.com/rootstrap/mars
|
|
41
113
|
licenses:
|
|
@@ -44,7 +116,8 @@ metadata:
|
|
|
44
116
|
homepage_uri: https://github.com/rootstrap/mars
|
|
45
117
|
source_code_uri: https://github.com/rootstrap/mars
|
|
46
118
|
changelog_uri: https://github.com/rootstrap/mars/releases
|
|
47
|
-
|
|
119
|
+
rubygems_mfa_required: 'true'
|
|
120
|
+
post_install_message:
|
|
48
121
|
rdoc_options: []
|
|
49
122
|
require_paths:
|
|
50
123
|
- lib
|
|
@@ -59,8 +132,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
59
132
|
- !ruby/object:Gem::Version
|
|
60
133
|
version: '0'
|
|
61
134
|
requirements: []
|
|
62
|
-
rubygems_version: 3.
|
|
63
|
-
signing_key:
|
|
135
|
+
rubygems_version: 3.5.23
|
|
136
|
+
signing_key:
|
|
64
137
|
specification_version: 4
|
|
65
138
|
summary: Multi-Agent Ruby SDK - A framework for building multi-agent solutions in
|
|
66
139
|
pure Ruby
|