smart_agent 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +10 -2
- data/lib/smart_agent/agent.rb +0 -10
- data/lib/smart_agent/mcp_client.rb +36 -0
- data/lib/smart_agent/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1a92b61bd5f0241c702a83b4d0c598341c263516965d0dffa2ef9adff0bb21cc
|
|
4
|
+
data.tar.gz: d2208e003c420c9aa638e3553cab1ab3826024efe1e8a83334a27fe2bf71130f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6e1ec7cf916db65f2b3ea5c3b6fc67ab1848679178e5277a1de0dd20162ddc40e6f4de38f4a836c2b7fd4a86d9179dcddf4e5a5d4194eb7f93a194d4e607a05e
|
|
7
|
+
data.tar.gz: 6fbf7faf9afb9c2925ae50bed76e98a453f1a2c221d08d755db49ae39ee826ec7dabf2b3f8c4752706824a07f10e48548948d4fa900e5ed2df199529b960bd6d
|
data/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.ruby-lang.org/)
|
|
4
4
|
[](./LICENSE)
|
|
5
|
-
[](./lib/smart_agent/version.rb)
|
|
6
6
|
|
|
7
7
|
**An intelligent agent framework for Ruby with MCP support, tool calling, and multi-LLM integration**
|
|
8
8
|
|
|
@@ -167,10 +167,18 @@ SmartAgent::MCPClient.define :web_service do
|
|
|
167
167
|
url "https://api.example.com/mcp/sse"
|
|
168
168
|
end
|
|
169
169
|
|
|
170
|
+
SmartAgent::MCPClient.define :limited_web_service do
|
|
171
|
+
type :sse
|
|
172
|
+
url "https://api.example.com/mcp/sse"
|
|
173
|
+
functions [:search, :fetch]
|
|
174
|
+
end
|
|
175
|
+
|
|
170
176
|
# Use with agent
|
|
171
177
|
agent = engine.build_agent(:research_bot, mcp_servers: [:opendigger, :postgres])
|
|
172
178
|
```
|
|
173
179
|
|
|
180
|
+
If `functions` is configured, only the listed MCP tools are exposed to the agent. If `functions` is omitted, all tools from that MCP server are exposed.
|
|
181
|
+
|
|
174
182
|
### Advanced Features
|
|
175
183
|
|
|
176
184
|
#### Stream Processing with Events
|
|
@@ -300,4 +308,4 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
|
|
|
300
308
|
|
|
301
309
|
---
|
|
302
310
|
|
|
303
|
-
**⭐ Star this repository if you find it useful!**
|
|
311
|
+
**⭐ Star this repository if you find it useful!**
|
data/lib/smart_agent/agent.rb
CHANGED
|
@@ -26,10 +26,6 @@ module SmartAgent
|
|
|
26
26
|
@tool_call_proc = block
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
def on_logging(&block)
|
|
30
|
-
@log_proc = block
|
|
31
|
-
end
|
|
32
|
-
|
|
33
29
|
def on_event
|
|
34
30
|
if @reasoning_event_proc || @content_event_proc
|
|
35
31
|
return true
|
|
@@ -46,8 +42,6 @@ module SmartAgent
|
|
|
46
42
|
return @content_event_proc
|
|
47
43
|
when :tool
|
|
48
44
|
return @tool_call_proc
|
|
49
|
-
when :logging
|
|
50
|
-
return @log_proc
|
|
51
45
|
else
|
|
52
46
|
return nil
|
|
53
47
|
end
|
|
@@ -75,10 +69,6 @@ module SmartAgent
|
|
|
75
69
|
@agent = agent
|
|
76
70
|
end
|
|
77
71
|
|
|
78
|
-
def show_log(msg)
|
|
79
|
-
@agent.processor(:logging).call(msg) if @agent.processor(:logging)
|
|
80
|
-
end
|
|
81
|
-
|
|
82
72
|
def call_worker(name, params, with_tools: true, with_history: false)
|
|
83
73
|
SmartAgent.logger.info("Call Worker name is: #{name}")
|
|
84
74
|
SmartAgent.logger.info("Call Worker params is: #{params}")
|
|
@@ -18,6 +18,8 @@ module SmartAgent
|
|
|
18
18
|
def to_json
|
|
19
19
|
mcp_server_json = @client.list_tools
|
|
20
20
|
if mcp_server_json
|
|
21
|
+
mcp_server_json["tools"] = filter_tools(mcp_server_json["tools"])
|
|
22
|
+
MCPClient.clear_server_tools(@name)
|
|
21
23
|
mcp_server_json["tools"].each do |tool|
|
|
22
24
|
MCPClient.set_server(tool["name"].to_sym, @name)
|
|
23
25
|
end
|
|
@@ -42,6 +44,18 @@ module SmartAgent
|
|
|
42
44
|
@client.stop
|
|
43
45
|
end
|
|
44
46
|
|
|
47
|
+
private
|
|
48
|
+
|
|
49
|
+
def filter_tools(tools)
|
|
50
|
+
return [] unless tools
|
|
51
|
+
|
|
52
|
+
allowed_functions = @context.functions
|
|
53
|
+
return tools unless allowed_functions
|
|
54
|
+
|
|
55
|
+
allowed_names = allowed_functions.map(&:to_s)
|
|
56
|
+
tools.select { |tool| allowed_names.include?(tool["name"].to_s) }
|
|
57
|
+
end
|
|
58
|
+
|
|
45
59
|
class << self
|
|
46
60
|
def servers
|
|
47
61
|
@servers ||= {}
|
|
@@ -51,6 +65,10 @@ module SmartAgent
|
|
|
51
65
|
@tool_to_server ||= {}
|
|
52
66
|
end
|
|
53
67
|
|
|
68
|
+
def server_to_tools
|
|
69
|
+
@server_to_tools ||= Hash.new { |hash, key| hash[key] = [] }
|
|
70
|
+
end
|
|
71
|
+
|
|
54
72
|
def define(name, &block)
|
|
55
73
|
servers[name] = block
|
|
56
74
|
client = MCPClient.new(name)
|
|
@@ -59,6 +77,14 @@ module SmartAgent
|
|
|
59
77
|
|
|
60
78
|
def set_server(tool_name, server_name)
|
|
61
79
|
tool_to_server[tool_name] = server_name
|
|
80
|
+
server_to_tools[server_name] << tool_name unless server_to_tools[server_name].include?(tool_name)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def clear_server_tools(server_name)
|
|
84
|
+
server_to_tools[server_name].each do |tool_name|
|
|
85
|
+
tool_to_server.delete(tool_name)
|
|
86
|
+
end
|
|
87
|
+
server_to_tools[server_name] = []
|
|
62
88
|
end
|
|
63
89
|
|
|
64
90
|
def find_server_by_tool_name(tool_name)
|
|
@@ -68,6 +94,10 @@ module SmartAgent
|
|
|
68
94
|
end
|
|
69
95
|
|
|
70
96
|
class MCPContext
|
|
97
|
+
def initialize
|
|
98
|
+
@functions = nil
|
|
99
|
+
end
|
|
100
|
+
|
|
71
101
|
def type(mcp_type)
|
|
72
102
|
@mcp_type = mcp_type
|
|
73
103
|
end
|
|
@@ -87,5 +117,11 @@ module SmartAgent
|
|
|
87
117
|
def url(url)
|
|
88
118
|
@command_path = url
|
|
89
119
|
end
|
|
120
|
+
|
|
121
|
+
def functions(names = :__smart_agent_not_provided__)
|
|
122
|
+
return @functions if names == :__smart_agent_not_provided__
|
|
123
|
+
|
|
124
|
+
@functions = names
|
|
125
|
+
end
|
|
90
126
|
end
|
|
91
127
|
end
|
data/lib/smart_agent/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: smart_agent
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Zhuang Biaowei
|
|
@@ -13,16 +13,16 @@ dependencies:
|
|
|
13
13
|
name: smart_prompt
|
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
|
15
15
|
requirements:
|
|
16
|
-
- - "
|
|
16
|
+
- - "~>"
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version:
|
|
18
|
+
version: 0.3.5
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
|
-
- - "
|
|
23
|
+
- - "~>"
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version:
|
|
25
|
+
version: 0.3.5
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: mcp-sdk.rb
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
85
85
|
- !ruby/object:Gem::Version
|
|
86
86
|
version: '0'
|
|
87
87
|
requirements: []
|
|
88
|
-
rubygems_version:
|
|
88
|
+
rubygems_version: 4.0.6
|
|
89
89
|
specification_version: 4
|
|
90
90
|
summary: Intelligent agent framework with DSL and MCP integration
|
|
91
91
|
test_files: []
|