Skip to content

Commit 2df0282

Browse files
santibclaude
andcommitted
Rename Agent to AgentStep with agent macro
Phase 3 of the Mars v2 refactor. - Rename Mars::Agent → Mars::AgentStep with class-level `agent` macro that wraps a RubyLLM::Agent subclass - AgentStep#run creates a new agent instance and delegates via .ask - Remove old Agent with its manual Chat setup (before_run/after_run, system_prompt, tools, schema instance methods) - Rename rendering graph module accordingly - Bump ruby_llm dependency to ~> 1.12 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 29ee560 commit 2df0282

7 files changed

Lines changed: 79 additions & 119 deletions

File tree

lib/mars/agent.rb

Lines changed: 0 additions & 48 deletions
This file was deleted.

lib/mars/agent_step.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
module MARS
4+
class AgentStep < Runnable
5+
class << self
6+
def agent(klass = nil)
7+
klass ? @agent_class = klass : @agent_class
8+
end
9+
end
10+
11+
def run(input)
12+
self.class.agent.new.ask(input).content
13+
end
14+
end
15+
end

lib/mars/rendering/graph.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module MARS
44
module Rendering
55
module Graph
66
def self.include_extensions
7-
MARS::Agent.include(Agent)
7+
MARS::AgentStep.include(AgentStep)
88
MARS::Gate.include(Gate)
99
MARS::Workflows::Sequential.include(SequentialWorkflow)
1010
MARS::Workflows::Parallel.include(ParallelWorkflow)
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module MARS
44
module Rendering
55
module Graph
6-
module Agent
6+
module AgentStep
77
include Base
88

99
def to_graph(builder, parent_id: nil, value: nil)
@@ -12,10 +12,6 @@ def to_graph(builder, parent_id: nil, value: nil)
1212

1313
[node_id]
1414
end
15-
16-
def name
17-
self.class.name
18-
end
1915
end
2016
end
2117
end

mars.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Gem::Specification.new do |spec|
3636

3737
# Uncomment to register a new dependency of your gem
3838
spec.add_dependency "async", "~> 2.34"
39-
spec.add_dependency "ruby_llm", "~> 1.9"
39+
spec.add_dependency "ruby_llm", "~> 1.12"
4040
spec.add_dependency "zeitwerk", "~> 2.7"
4141

4242
# For more information and examples about making a new gem, check out our

spec/mars/agent_spec.rb

Lines changed: 0 additions & 64 deletions
This file was deleted.

spec/mars/agent_step_spec.rb

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe MARS::AgentStep do
4+
describe ".agent" do
5+
it "stores and retrieves the agent class" do
6+
agent_class = Class.new
7+
step_class = Class.new(described_class) do
8+
agent agent_class
9+
end
10+
11+
expect(step_class.agent).to eq(agent_class)
12+
end
13+
14+
it "returns nil when no agent class is set" do
15+
step_class = Class.new(described_class)
16+
expect(step_class.agent).to be_nil
17+
end
18+
end
19+
20+
describe "#run" do
21+
let(:mock_agent_instance) do
22+
instance_double("RubyLLM::Agent").tap do |mock|
23+
allow(mock).to receive(:ask).and_return(instance_double("RubyLLM::Message", content: "agent response"))
24+
end
25+
end
26+
27+
let(:mock_agent_class) do
28+
instance_double("Class").tap do |mock|
29+
allow(mock).to receive(:new).and_return(mock_agent_instance)
30+
end
31+
end
32+
33+
let(:step_class) do
34+
klass = mock_agent_class
35+
Class.new(described_class) do
36+
agent klass
37+
end
38+
end
39+
40+
it "creates a new agent instance and calls ask" do
41+
step = step_class.new
42+
result = step.run("hello")
43+
44+
expect(result).to eq("agent response")
45+
expect(mock_agent_class).to have_received(:new)
46+
expect(mock_agent_instance).to have_received(:ask).with("hello")
47+
end
48+
end
49+
50+
describe "inheritance" do
51+
it "inherits from MARS::Runnable" do
52+
expect(described_class.ancestors).to include(MARS::Runnable)
53+
end
54+
55+
it "has access to name, formatter, and hooks from Runnable" do
56+
step = described_class.new(name: "my_agent")
57+
expect(step.name).to eq("my_agent")
58+
expect(step.formatter).to be_a(MARS::Formatter)
59+
end
60+
end
61+
end

0 commit comments

Comments
 (0)