@@ -19,8 +19,6 @@ class SportsSchema < RubyLLM::Schema
1919 end
2020end
2121
22- sports_schema = SportsSchema . new
23-
2422# Define weather tool
2523class Weather < RubyLLM ::Tool
2624 description "Gets current weather for a location"
@@ -39,34 +37,55 @@ def execute(latitude:, longitude:)
3937 end
4038end
4139
42- weather_tool = Weather . new
40+ # Define LLMs
41+ class Agent1 < Mars ::Agent
42+ def system_prompt
43+ "You are a helpful assistant that can answer questions.
44+ When asked about a country, only answer with its name."
45+ end
46+ end
4347
44- # Create the LLMs
45- llm1 = Mars ::Agent . new (
46- name : "LLM 1" , options : { model : "gpt-4o" } ,
47- instructions : "You are a helpful assistant that can answer questions.
48- When asked about a country, only answer with its name."
49- )
48+ class Agent2 < Mars ::Agent
49+ def system_prompt
50+ "You are a helpful assistant that can answer questions and help with tasks.
51+ Return information about the typical food of the country."
52+ end
53+ end
54+
55+ class Agent3 < Mars ::Agent
56+ def system_prompt
57+ "You are a helpful assistant that can answer questions and help with tasks.
58+ Return information about the popular sports of the country."
59+ end
60+
61+ def schema
62+ SportsSchema . new
63+ end
64+ end
5065
51- llm2 = Mars ::Agent . new ( name : "LLM 2" , options : { model : "gpt-4o" } ,
52- instructions : "You are a helpful assistant that can answer questions and help with tasks.
53- Return information about the typical food of the country." )
66+ class Agent4 < Mars ::Agent
67+ def system_prompt
68+ "You are a helpful assistant that can answer questions and help with tasks.
69+ Return the current weather of the country's capital."
70+ end
5471
55- llm3 = Mars ::Agent . new ( name : "LLM 3" , options : { model : "gpt-4o" } , schema : sports_schema ,
56- instructions : "You are a helpful assistant that can answer questions and help with tasks.
57- Return information about the popular sports of the country." )
72+ def tools
73+ [ Weather . new ]
74+ end
75+ end
5876
59- llm4 = Mars ::Agent . new ( name : "LLM 4" , options : { model : "gpt-4o" } , tools : [ weather_tool ] ,
60- instructions : "You are a helpful assistant that can answer questions and help with tasks.
61- Return the current weather of the country's capital." )
77+ # 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" } )
6282
6383parallel_workflow = Mars ::Workflows ::Parallel . new (
6484 "Parallel workflow" ,
6585 steps : [ llm2 , llm3 , llm4 ]
6686)
6787
6888gate = Mars ::Gate . new (
69- name : "Gate" ,
7089 condition : -> ( input ) { input . split . length < 10 ? :success : :error } ,
7190 branches : {
7291 success : parallel_workflow
@@ -84,4 +103,4 @@ def execute(latitude:, longitude:)
84103puts "Complex workflow diagram saved to: examples/complex_llm_workflow/diagram.md"
85104
86105# Run the workflow
87- puts sequential_workflow . run ( "Which is the largest country in South America ?" )
106+ puts sequential_workflow . run ( "Which is the largest country in Europe ?" )
0 commit comments