@@ -47,55 +47,61 @@ Here's a simple example to get you started:
4747``` ruby
4848require ' mars'
4949
50- # Define agents
51- class Agent1 < Mars ::Agent
50+ # Define a RubyLLM agent
51+ class MyAgent < RubyLLM ::Agent
52+ model " gpt-4o"
53+ instructions " You are a helpful assistant."
5254end
5355
54- class Agent2 < Mars ::Agent
56+ # Wrap it in a MARS step
57+ class MyStep < MARS ::AgentStep
58+ agent MyAgent
5559end
5660
57- class Agent3 < Mars ::Agent
58- end
59-
60- # Create agents
61- agent1 = Agent1 .new
62- agent2 = Agent2 .new
63- agent3 = Agent3 .new
61+ # Create steps
62+ step1 = MyStep .new (name: " step1" )
63+ step2 = MyStep .new (name: " step2" )
64+ step3 = MyStep .new (name: " step3" )
6465
6566# Create a sequential workflow
66- workflow = Mars ::Workflows ::Sequential .new (
67+ workflow = MARS ::Workflows ::Sequential .new (
6768 " My First Workflow" ,
68- steps: [agent1, agent2, agent3 ]
69+ steps: [step1, step2, step3 ]
6970)
7071
7172# Run the workflow
72- result = workflow.run(" Your input here" )
73+ context = workflow.run(" Your input here" )
74+ context.current_input # final output
75+ context[:step1 ] # access any step's output by name
7376```
7477
7578## Core Concepts
7679
77- ### Agents
80+ ### Agent Steps
7881
79- Agents are the basic building blocks of MARS. They represent individual units of work :
82+ Agent steps are the basic building blocks of MARS. They wrap a ` RubyLLM::Agent ` subclass for workflow orchestration :
8083
8184``` ruby
82- class CustomAgent < Mars ::Agent
83- def system_prompt
84- " You are a helpful assistant"
85- end
85+ class ResearcherAgent < RubyLLM ::Agent
86+ model " gpt-4o"
87+ instructions " You research topics thoroughly."
88+ tools WebSearch
89+ schema OutputSchema
8690end
8791
88- agent = CustomAgent .new (
89- options: { model: " gpt-4o" }
90- )
92+ class ResearcherStep < MARS ::AgentStep
93+ agent ResearcherAgent
94+ end
95+
96+ step = ResearcherStep .new (name: " researcher" )
9197```
9298
9399### Sequential Workflows
94100
95101Execute agents one after another, passing outputs as inputs:
96102
97103``` ruby
98- sequential = Mars ::Workflows ::Sequential .new (
104+ sequential = MARS ::Workflows ::Sequential .new (
99105 " Sequential Pipeline" ,
100106 steps: [agent1, agent2, agent3]
101107)
@@ -106,12 +112,12 @@ sequential = Mars::Workflows::Sequential.new(
106112Run multiple agents concurrently and aggregate their results:
107113
108114``` ruby
109- aggregator = Mars ::Aggregator .new (
115+ aggregator = MARS ::Aggregator .new (
110116 " Results Aggregator" ,
111117 operation: lambda { |results | results.join(" , " ) }
112118)
113119
114- parallel = Mars ::Workflows ::Parallel .new (
120+ parallel = MARS ::Workflows ::Parallel .new (
115121 " Parallel Pipeline" ,
116122 steps: [agent1, agent2, agent3],
117123 aggregator: aggregator
@@ -123,7 +129,7 @@ parallel = Mars::Workflows::Parallel.new(
123129Create conditional branching in your workflows:
124130
125131``` ruby
126- gate = Mars ::Gate .new (
132+ gate = MARS ::Gate .new (
127133 " Decision Gate" ,
128134 condition: -> (input) { input[:score ] > 0.5 ? :success : :failure },
129135 branches: {
@@ -138,7 +144,7 @@ gate = Mars::Gate.new(
138144Generate Mermaid diagrams to visualize your workflows:
139145
140146``` ruby
141- diagram = Mars ::Rendering ::Mermaid .new (workflow).render
147+ diagram = MARS ::Rendering ::Mermaid .new (workflow).render
142148File .write(" workflow_diagram.md" , diagram)
143149```
144150
@@ -197,7 +203,7 @@ The gem is available as open source under the terms of the [MIT License](https:/
197203
198204## Code of Conduct
199205
200- Everyone interacting in the Mars project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [ code of conduct] ( https://github.com/rootstrap/mars/blob/main/CODE_OF_CONDUCT.md ) .
206+ Everyone interacting in the MARS project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [ code of conduct] ( https://github.com/rootstrap/mars/blob/main/CODE_OF_CONDUCT.md ) .
201207
202208## Credits
203209
0 commit comments