Skip to content

Commit 025db2a

Browse files
authored
Fix examples (#33)
* Fix simple_workflow example * Fix parallel_workflow example * Fix complex_workflow example * Fix complex_llm_workflow example
1 parent b824349 commit 025db2a

9 files changed

Lines changed: 58 additions & 42 deletions

File tree

examples/complex_llm_workflow/diagram.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
flowchart LR
33
in((In))
44
out((Out))
5-
agent1[Agent1]
5+
agent1[agent1]
66
gate{Gate}
77
parallel_workflow_aggregator[Parallel workflow Aggregator]
8-
agent2[Agent2]
9-
agent3[Agent3]
10-
agent4[Agent4]
8+
agent2[agent2]
9+
agent3[agent3]
10+
agent4[agent4]
1111
subgraph parallel_workflow["Parallel workflow"]
1212
agent2
1313
agent3

examples/complex_llm_workflow/generator.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,21 @@ def execute(latitude:, longitude:)
3838
end
3939

4040
# Define LLMs
41-
class Agent1 < MARS::Agent
41+
class Agent1 < MARS::AgentStep
4242
def system_prompt
4343
"You are a helpful assistant that can answer questions.
4444
When asked about a country, only answer with its name."
4545
end
4646
end
4747

48-
class Agent2 < MARS::Agent
48+
class Agent2 < MARS::AgentStep
4949
def system_prompt
5050
"You are a helpful assistant that can answer questions and help with tasks.
5151
Return information about the typical food of the country."
5252
end
5353
end
5454

55-
class Agent3 < MARS::Agent
55+
class Agent3 < MARS::AgentStep
5656
def system_prompt
5757
"You are a helpful assistant that can answer questions and help with tasks.
5858
Return information about the popular sports of the country."
@@ -63,7 +63,7 @@ def schema
6363
end
6464
end
6565

66-
class Agent4 < MARS::Agent
66+
class Agent4 < MARS::AgentStep
6767
def system_prompt
6868
"You are a helpful assistant that can answer questions and help with tasks.
6969
Return the current weather of the country's capital."
@@ -75,10 +75,10 @@ def tools
7575
end
7676

7777
# Create the LLMs
78-
llm1 = Agent1.new(options: { model: "gpt-4o" })
79-
llm2 = Agent2.new(options: { model: "gpt-4o" })
80-
llm3 = Agent3.new(options: { model: "gpt-4o" })
81-
llm4 = Agent4.new(options: { model: "gpt-4o" })
78+
llm1 = Agent1.new
79+
llm2 = Agent2.new
80+
llm3 = Agent3.new
81+
llm4 = Agent4.new
8282

8383
parallel_workflow = MARS::Workflows::Parallel.new(
8484
"Parallel workflow",

examples/complex_workflow/diagram.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
flowchart LR
33
in((In))
44
out((Out))
5-
agent1[Agent1]
5+
agent1[agent1]
66
gate{Gate}
7-
agent4[Agent4]
7+
agent4[agent4]
88
parallel_workflow_aggregator[Parallel workflow Aggregator]
9-
agent2[Agent2]
10-
agent3[Agent3]
9+
agent2[agent2]
10+
agent3[agent3]
1111
parallel_workflow_2_aggregator[Parallel workflow 2 Aggregator]
12-
agent5[Agent5]
12+
agent5[agent5]
1313
subgraph parallel_workflow_2["Parallel workflow 2"]
1414
sequential_workflow
1515
agent5

examples/complex_workflow/generator.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
require_relative "../../lib/mars"
55

66
# Define LLMs
7-
class Agent1 < MARS::Agent
7+
class Agent1 < MARS::AgentStep
88
end
99

10-
class Agent2 < MARS::Agent
10+
class Agent2 < MARS::AgentStep
1111
end
1212

13-
class Agent3 < MARS::Agent
13+
class Agent3 < MARS::AgentStep
1414
end
1515

16-
class Agent4 < MARS::Agent
16+
class Agent4 < MARS::AgentStep
1717
end
1818

19-
class Agent5 < MARS::Agent
19+
class Agent5 < MARS::AgentStep
2020
end
2121

2222
# Create the LLMs

examples/parallel_workflow/diagram.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ flowchart LR
33
in((In))
44
out((Out))
55
aggregator[Aggregator]
6-
agent1[Agent1]
7-
agent2[Agent2]
8-
agent3[Agent3]
6+
agent1[agent1]
7+
agent2[agent2]
8+
agent3[agent3]
99
subgraph parallel_workflow["Parallel workflow"]
1010
agent1
1111
agent2

examples/parallel_workflow/generator.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
require_relative "../../lib/mars"
55

66
# Define the LLMs
7-
class Agent1 < MARS::Agent
7+
class Agent1 < MARS::AgentStep
88
end
99

10-
class Agent2 < MARS::Agent
10+
class Agent2 < MARS::AgentStep
1111
end
1212

13-
class Agent3 < MARS::Agent
13+
class Agent3 < MARS::AgentStep
1414
end
1515

1616
# Create the LLMs

examples/simple_workflow/diagram.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,25 @@
22
flowchart LR
33
in((In))
44
out((Out))
5-
agent1[Agent1]
5+
agent1[agent1]
66
gate{Gate}
7-
agent2[Agent2]
8-
agent3[Agent3]
7+
agent4[agent4]
8+
agent2[agent2]
9+
agent3[agent3]
10+
subgraph failure_workflow["Failure workflow"]
11+
agent4
12+
end
13+
subgraph main_pipeline["Main Pipeline"]
14+
agent1
15+
gate
16+
agent4
17+
agent2
18+
agent3
19+
end
920
in --> agent1
1021
agent1 --> gate
11-
gate -->|success| agent2
12-
gate -->|default| out
22+
gate -->|failure| agent4
23+
gate --> agent2
1324
agent2 --> agent3
1425
agent3 --> out
1526
```

examples/simple_workflow/generator.rb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,42 @@
44
require_relative "../../lib/mars"
55

66
# Define the LLMs
7-
class Agent1 < MARS::Agent
7+
class Agent1 < MARS::AgentStep
88
end
99

10-
class Agent2 < MARS::Agent
10+
class Agent2 < MARS::AgentStep
1111
end
1212

13-
class Agent3 < MARS::Agent
13+
class Agent3 < MARS::AgentStep
14+
end
15+
16+
class Agent4 < MARS::AgentStep
1417
end
1518

1619
# Create the LLMs
1720
llm1 = Agent1.new
1821
llm2 = Agent2.new
1922
llm3 = Agent3.new
23+
llm4 = Agent4.new
2024

21-
# Create the success workflow (LLM 2 -> LLM 3)
22-
success_workflow = MARS::Workflows::Sequential.new(
23-
"Success workflow",
24-
steps: [llm2, llm3]
25+
# Create the failure workflow (LLM 3)
26+
failure_workflow = MARS::Workflows::Sequential.new(
27+
"Failure workflow",
28+
steps: [llm4]
2529
)
2630

2731
# Create the gate that decides between exit or continue
2832
gate = MARS::Gate.new(
2933
check: ->(input) { input[:result] },
3034
fallbacks: {
31-
success: success_workflow
35+
failure: failure_workflow
3236
}
3337
)
3438

3539
# Create the main workflow: LLM 1 -> Gate
3640
main_workflow = MARS::Workflows::Sequential.new(
3741
"Main Pipeline",
38-
steps: [llm1, gate]
42+
steps: [llm1, gate, llm2, llm3]
3943
)
4044

4145
# Generate and save the diagram

lib/mars.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
loader = Zeitwerk::Loader.for_gem
99
loader.inflector.inflect("mars" => "MARS")
10+
loader.ignore("#{__dir__}/mars_rb.rb")
1011
loader.setup
1112

1213
module MARS

0 commit comments

Comments
 (0)