Skip to content

Commit 1266971

Browse files
authored
Add agent and gate (#2)
* Add Agent and Gate
1 parent c733b15 commit 1266971

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

lib/mars/agent.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# frozen_string_literal: true
2+
3+
module Mars
4+
class Agent < Runnable
5+
def initialize(name:, options:, tools: [], schema: nil)
6+
@name = name
7+
@tools = Array(tools)
8+
@schema = schema
9+
@options = options
10+
end
11+
12+
def run(input)
13+
chat.ask(input)
14+
end
15+
16+
private
17+
18+
attr_reader :name, :tools, :schema, :options
19+
20+
def chat
21+
@chat ||= RubyLLM::Chat.new(**options).with_tools(tools).with_schema(schema)
22+
end
23+
end
24+
end

lib/mars/gate.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# frozen_string_literal: true
2+
3+
module Mars
4+
class Gate < Runnable
5+
def initialize(name:, condition:, branches:)
6+
@name = name
7+
@condition = condition
8+
@branches = branches
9+
end
10+
11+
def run(input)
12+
result = condition.call(input)
13+
14+
raise "Invalid condition result: #{result}" unless branches.key?(result)
15+
16+
branches[result].run(input)
17+
end
18+
19+
private
20+
21+
attr_reader :name, :condition, :branches
22+
end
23+
end

mars.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Gem::Specification.new do |spec|
3434
spec.require_paths = ["lib"]
3535

3636
# Uncomment to register a new dependency of your gem
37-
# spec.add_dependency "example-gem", "~> 1.0"
37+
spec.add_dependency "ruby_llm", "~> 1.0"
3838

3939
# For more information and examples about making a new gem, check out our
4040
# guide at: https://bundler.io/guides/creating_gem.html

0 commit comments

Comments
 (0)