Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,8 @@ RSpec/ExampleLength:
RSpec/MultipleExpectations:
Enabled: false

RSpec/MultipleMemoizedHelpers:
Enabled: false

RSpec/VerifiedDoubleReference:
Enabled: false
28 changes: 21 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,20 @@ Here's a simple example to get you started:
```ruby
require 'mars'

# Define agents
class Agent1 < Mars::Agent
end

class Agent2 < Mars::Agent
end

class Agent3 < Mars::Agent
end

# Create agents
agent1 = Mars::Agent.new(name: "Agent 1")
agent2 = Mars::Agent.new(name: "Agent 2")
agent3 = Mars::Agent.new(name: "Agent 3")
agent1 = Agent1.new
agent2 = Agent2.new
agent3 = Agent3.new

# Create a sequential workflow
workflow = Mars::Workflows::Sequential.new(
Expand All @@ -69,9 +79,13 @@ result = workflow.run("Your input here")
Agents are the basic building blocks of MARS. They represent individual units of work:

```ruby
agent = Mars::Agent.new(
name: "My Agent",
instructions: "You are a helpful assistant",
class CustomAgent < Mars::Agent
def system_prompt
"You are a helpful assistant"
end
end

agent = CustomAgent.new(
options: { model: "gpt-4o" }
)
```
Expand Down Expand Up @@ -110,7 +124,7 @@ Create conditional branching in your workflows:

```ruby
gate = Mars::Gate.new(
name: "Decision Gate",
"Decision Gate",
condition: ->(input) { input[:score] > 0.5 ? :success : :failure },
branches: {
success: success_workflow,
Expand Down
24 changes: 12 additions & 12 deletions examples/complex_llm_workflow/diagram.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
flowchart LR
in((In))
out((Out))
llm_1[LLM 1]
agent1[Agent1]
gate{Gate}
parallel_workflow_aggregator[Parallel workflow Aggregator]
llm_2[LLM 2]
llm_3[LLM 3]
llm_4[LLM 4]
in --> llm_1
llm_1 --> gate
gate -->|success| llm_2
gate -->|success| llm_3
gate -->|success| llm_4
agent2[Agent2]
agent3[Agent3]
agent4[Agent4]
in --> agent1
agent1 --> gate
gate -->|success| agent2
gate -->|success| agent3
gate -->|success| agent4
gate -->|default| out
llm_2 --> parallel_workflow_aggregator
agent2 --> parallel_workflow_aggregator
parallel_workflow_aggregator --> out
llm_3 --> parallel_workflow_aggregator
llm_4 --> parallel_workflow_aggregator
agent3 --> parallel_workflow_aggregator
agent4 --> parallel_workflow_aggregator
```
59 changes: 39 additions & 20 deletions examples/complex_llm_workflow/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ class SportsSchema < RubyLLM::Schema
end
end

sports_schema = SportsSchema.new

# Define weather tool
class Weather < RubyLLM::Tool
description "Gets current weather for a location"
Expand All @@ -39,34 +37,55 @@ def execute(latitude:, longitude:)
end
end

weather_tool = Weather.new
# Define LLMs
class Agent1 < Mars::Agent
def system_prompt
"You are a helpful assistant that can answer questions.
When asked about a country, only answer with its name."
end
end

# Create the LLMs
llm1 = Mars::Agent.new(
name: "LLM 1", options: { model: "gpt-4o" },
instructions: "You are a helpful assistant that can answer questions.
When asked about a country, only answer with its name."
)
class Agent2 < Mars::Agent
def system_prompt
"You are a helpful assistant that can answer questions and help with tasks.
Return information about the typical food of the country."
end
end

class Agent3 < Mars::Agent
def system_prompt
"You are a helpful assistant that can answer questions and help with tasks.
Return information about the popular sports of the country."
end

def schema
SportsSchema.new
end
end

llm2 = Mars::Agent.new(name: "LLM 2", options: { model: "gpt-4o" },
instructions: "You are a helpful assistant that can answer questions and help with tasks.
Return information about the typical food of the country.")
class Agent4 < Mars::Agent
def system_prompt
"You are a helpful assistant that can answer questions and help with tasks.
Return the current weather of the country's capital."
end

llm3 = Mars::Agent.new(name: "LLM 3", options: { model: "gpt-4o" }, schema: sports_schema,
instructions: "You are a helpful assistant that can answer questions and help with tasks.
Return information about the popular sports of the country.")
def tools
[Weather.new]
end
end

llm4 = Mars::Agent.new(name: "LLM 4", options: { model: "gpt-4o" }, tools: [weather_tool],
instructions: "You are a helpful assistant that can answer questions and help with tasks.
Return the current weather of the country's capital.")
# Create the LLMs
llm1 = Agent1.new(options: { model: "gpt-4o" })
llm2 = Agent2.new(options: { model: "gpt-4o" })
llm3 = Agent3.new(options: { model: "gpt-4o" })
llm4 = Agent4.new(options: { model: "gpt-4o" })

parallel_workflow = Mars::Workflows::Parallel.new(
"Parallel workflow",
steps: [llm2, llm3, llm4]
)

gate = Mars::Gate.new(
name: "Gate",
condition: ->(input) { input.split.length < 10 ? :success : :error },
branches: {
success: parallel_workflow
Expand All @@ -84,4 +103,4 @@ def execute(latitude:, longitude:)
puts "Complex workflow diagram saved to: examples/complex_llm_workflow/diagram.md"

# Run the workflow
puts sequential_workflow.run("Which is the largest country in South America?")
puts sequential_workflow.run("Which is the largest country in Europe?")
34 changes: 17 additions & 17 deletions examples/complex_workflow/diagram.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@
flowchart LR
in((In))
out((Out))
llm_1[LLM 1]
agent1[Agent1]
gate{Gate}
parallel_workflow_2_aggregator[Parallel workflow 2 Aggregator]
llm_4[LLM 4]
agent4[Agent4]
parallel_workflow_aggregator[Parallel workflow Aggregator]
llm_2[LLM 2]
llm_3[LLM 3]
llm_5[LLM 5]
in --> llm_1
llm_1 --> gate
gate -->|success| llm_4
gate -->|success| llm_5
gate -->|warning| llm_4
gate -->|error| llm_2
gate -->|error| llm_3
agent2[Agent2]
agent3[Agent3]
agent5[Agent5]
in --> agent1
agent1 --> gate
gate -->|success| agent4
gate -->|success| agent5
gate -->|warning| agent4
gate -->|error| agent2
gate -->|error| agent3
gate -->|default| out
llm_4 --> llm_2
llm_4 --> llm_3
llm_2 --> parallel_workflow_aggregator
agent4 --> agent2
agent4 --> agent3
agent2 --> parallel_workflow_aggregator
parallel_workflow_aggregator --> parallel_workflow_2_aggregator
parallel_workflow_aggregator --> out
llm_3 --> parallel_workflow_aggregator
agent3 --> parallel_workflow_aggregator
parallel_workflow_2_aggregator --> out
llm_5 --> parallel_workflow_2_aggregator
agent5 --> parallel_workflow_2_aggregator
```
25 changes: 18 additions & 7 deletions examples/complex_workflow/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,28 @@

require_relative "../../lib/mars"

# Create the LLMs
llm1 = Mars::Agent.new(name: "LLM 1")
# Define LLMs
class Agent1 < Mars::Agent
end

class Agent2 < Mars::Agent
end

llm2 = Mars::Agent.new(name: "LLM 2")
class Agent3 < Mars::Agent
end

llm3 = Mars::Agent.new(name: "LLM 3")
class Agent4 < Mars::Agent
end

llm4 = Mars::Agent.new(name: "LLM 4")
class Agent5 < Mars::Agent
end

llm5 = Mars::Agent.new(name: "LLM 5")
# Create the LLMs
llm1 = Agent1.new
llm2 = Agent2.new
llm3 = Agent3.new
llm4 = Agent4.new
llm5 = Agent5.new

# Create a parallel workflow (LLM 2 x LLM 3)
parallel_workflow = Mars::Workflows::Parallel.new(
Expand All @@ -34,7 +46,6 @@

# Create the gate that decides between exit or continue
gate = Mars::Gate.new(
name: "Gate",
condition: ->(input) { input[:result] },
branches: {
success: parallel_workflow2,
Expand Down
18 changes: 9 additions & 9 deletions examples/parallel_workflow/diagram.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ flowchart LR
in((In))
out((Out))
aggregator[Aggregator]
llm_1[LLM 1]
llm_2[LLM 2]
llm_3[LLM 3]
in --> llm_1
in --> llm_2
in --> llm_3
llm_1 --> aggregator
agent1[Agent1]
agent2[Agent2]
agent3[Agent3]
in --> agent1
in --> agent2
in --> agent3
agent1 --> aggregator
aggregator --> out
llm_2 --> aggregator
llm_3 --> aggregator
agent2 --> aggregator
agent3 --> aggregator
```
16 changes: 12 additions & 4 deletions examples/parallel_workflow/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@

require_relative "../../lib/mars"

# Create the LLMs
llm1 = Mars::Agent.new(name: "LLM 1")
# Define the LLMs
class Agent1 < Mars::Agent
end

class Agent2 < Mars::Agent
end

llm2 = Mars::Agent.new(name: "LLM 2")
class Agent3 < Mars::Agent
end

llm3 = Mars::Agent.new(name: "LLM 3")
# Create the LLMs
llm1 = Agent1.new
llm2 = Agent2.new
llm3 = Agent3.new

aggregator = Mars::Aggregator.new("Aggregator", operation: lambda(&:sum))

Expand Down
16 changes: 8 additions & 8 deletions examples/simple_workflow/diagram.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
flowchart LR
in((In))
out((Out))
llm_1[LLM 1]
agent1[Agent1]
gate{Gate}
llm_2[LLM 2]
llm_3[LLM 3]
in --> llm_1
llm_1 --> gate
gate -->|success| llm_2
agent2[Agent2]
agent3[Agent3]
in --> agent1
agent1 --> gate
gate -->|success| agent2
gate -->|default| out
llm_2 --> llm_3
llm_3 --> out
agent2 --> agent3
agent3 --> out
```
17 changes: 12 additions & 5 deletions examples/simple_workflow/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@

require_relative "../../lib/mars"

# Create the LLMs
llm1 = Mars::Agent.new(name: "LLM 1")
# Define the LLMs
class Agent1 < Mars::Agent
end

class Agent2 < Mars::Agent
end

llm2 = Mars::Agent.new(name: "LLM 2")
class Agent3 < Mars::Agent
end

llm3 = Mars::Agent.new(name: "LLM 3")
# Create the LLMs
llm1 = Agent1.new
llm2 = Agent2.new
llm3 = Agent3.new

# Create the success workflow (LLM 2 -> LLM 3)
success_workflow = Mars::Workflows::Sequential.new(
Expand All @@ -18,7 +26,6 @@

# Create the gate that decides between exit or continue
gate = Mars::Gate.new(
name: "Gate",
condition: ->(input) { input[:result] },
branches: {
success: success_workflow
Expand Down
Loading