smart_agent 0.1.1 → 0.1.2
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 +62 -49
- data/lib/smart_agent/agent.rb +7 -7
- data/lib/smart_agent/tool.rb +4 -0
- data/lib/smart_agent/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f34059e0f8389ab46e42221507a17545c3e5baf0ae63c5d7273018168f608d30
|
4
|
+
data.tar.gz: cf815b9c79556577b56328ef992dfa5f522871c4c805b8d7d1e8c24d24a45947
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a5ee8bc0ac6af2c198ba15d855b5fcdf181fb27cce922e7f0f649018e3aaa8ed3836723fa4cd2b41d3b1afa2806b679980a5e64a3fdecc33cddd596287ad861
|
7
|
+
data.tar.gz: 9da300c1c13c8c0828d92ccd2ae7caa3bb228be51439bab7dc6ab4211f22686d76f91a4c11fab56bd67d62b412dd375fb6ab294e4805b8fffd62105d95a25670
|
data/README.md
CHANGED
@@ -1,76 +1,89 @@
|
|
1
|
-
#
|
1
|
+
# SmartAgent Framework
|
2
2
|
|
3
|
-
|
4
|
-
[](https://rubygems.org/gems/smart_agent)
|
5
|
-
[](LICENSE)
|
3
|
+
SmartAgent is an intelligent agent framework developed in Ruby, supporting tool calling and natural language interaction.
|
6
4
|
|
7
|
-
|
5
|
+
## Features
|
8
6
|
|
9
|
-
|
7
|
+
- Supports defining smart agents (SmartAgent) and tools (Tool)
|
8
|
+
- Built-in utility tools:
|
9
|
+
- Weather query (get_weather)
|
10
|
+
- Math calculations (get_sum)
|
11
|
+
- Code generation and execution (get_code)
|
12
|
+
- Integrated with OpenDigger MCP service
|
13
|
+
- Supports natural language interaction in both English and Chinese
|
14
|
+
- Extensible tool system
|
10
15
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Ensure you have Ruby (>= 2.7) and Bundler installed:
|
19
|
+
|
20
|
+
```bash
|
21
|
+
gem install bundler
|
22
|
+
```
|
23
|
+
|
24
|
+
Then run:
|
25
|
+
|
26
|
+
```bash
|
27
|
+
bundle install
|
28
|
+
```
|
29
|
+
|
30
|
+
Or install the gem directly:
|
31
|
+
|
32
|
+
```bash
|
33
|
+
gem install smart_agent
|
34
|
+
```
|
35
|
+
|
36
|
+
## Usage Examples
|
16
37
|
|
17
|
-
|
38
|
+
### Basic Usage
|
18
39
|
|
19
40
|
```ruby
|
20
41
|
require 'smart_agent'
|
21
42
|
|
22
|
-
SmartAgent.
|
23
|
-
result = call_worker(:weather, params, with_tools: true)
|
24
|
-
if result.call_tools?
|
25
|
-
weather_result = call_tools(result)
|
26
|
-
return call_worker(:weather_summary, params, weather_result, with_tools: false)
|
27
|
-
else
|
28
|
-
return result
|
29
|
-
end
|
30
|
-
end
|
43
|
+
agent = SmartAgent.build_agent(:smart_bot, tools: [:get_code])
|
31
44
|
|
32
|
-
|
33
|
-
|
34
|
-
param_define :date, "Specific Date or Today or Tomorrow", :date
|
35
|
-
# Call the Weather API
|
36
|
-
end
|
45
|
+
# Weather query
|
46
|
+
puts agent.please("What's the weather in Shanghai tomorrow?")
|
37
47
|
|
38
|
-
|
39
|
-
|
40
|
-
agent = SmartAgent.create(:weather_bot, [:get_weather])
|
48
|
+
# Math calculation
|
49
|
+
puts agent.please("Calculate the sum of 130 and 51")
|
41
50
|
|
42
|
-
|
51
|
+
# Code generation and execution
|
52
|
+
puts agent.please("Calculate the area of a triangle with base 132 and height 7.6 using a Ruby function")
|
43
53
|
```
|
44
54
|
|
45
|
-
|
55
|
+
### Custom Tools
|
46
56
|
|
47
|
-
Add to your Gemfile:
|
48
57
|
```ruby
|
49
|
-
|
58
|
+
SmartAgent::Tool.define :my_tool do
|
59
|
+
param_define :param1, "Parameter description", :string
|
60
|
+
param_define :param2, "Another parameter", :integer
|
61
|
+
|
62
|
+
if input_params
|
63
|
+
# Tool logic
|
64
|
+
"Processing result"
|
65
|
+
end
|
66
|
+
end
|
50
67
|
```
|
51
68
|
|
52
|
-
|
53
|
-
```bash
|
54
|
-
bundle install
|
55
|
-
```
|
69
|
+
## MCP Integration
|
56
70
|
|
57
|
-
|
58
|
-
```bash
|
59
|
-
gem install smart_agent
|
60
|
-
```
|
71
|
+
Supports getting GitHub project metrics via OpenDigger MCP service:
|
61
72
|
|
62
|
-
|
73
|
+
```ruby
|
74
|
+
|
75
|
+
SmartAgent::MCPClient.define :opendigger do
|
76
|
+
type :stdio
|
77
|
+
command "node ~/open-digger-mcp-server/dist/index.js"
|
78
|
+
end
|
63
79
|
|
64
|
-
|
80
|
+
puts agent.please("Query OpenRank metrics changes for Vue project on GitHub")
|
81
|
+
```
|
65
82
|
|
66
83
|
## Contributing
|
67
84
|
|
68
|
-
|
69
|
-
2. Create feature branch (`git checkout -b feature/amazing-feature`)
|
70
|
-
3. Commit changes (`git commit -m 'Add some amazing feature'`)
|
71
|
-
4. Push branch (`git push origin feature/amazing-feature`)
|
72
|
-
5. Open a Pull Request
|
85
|
+
Issues and pull requests are welcome.
|
73
86
|
|
74
87
|
## License
|
75
88
|
|
76
|
-
|
89
|
+
MIT License. See LICENSE file for details.
|
data/lib/smart_agent/agent.rb
CHANGED
@@ -87,10 +87,10 @@ module SmartAgent
|
|
87
87
|
if @agent.on_event && with_tools == false
|
88
88
|
SmartAgent.prompt_engine.call_worker_by_stream(name, params) do |chunk, _bytesize|
|
89
89
|
if chunk.dig("choices", 0, "delta", "reasoning_content")
|
90
|
-
@agent.processor(:reasoning).call(chunk)
|
90
|
+
@agent.processor(:reasoning).call(chunk) if @agent.processor(:reasoning)
|
91
91
|
end
|
92
92
|
if chunk.dig("choices", 0, "delta", "content")
|
93
|
-
@agent.processor(:content).call(chunk)
|
93
|
+
@agent.processor(:content).call(chunk) if @agent.processor(:content)
|
94
94
|
end
|
95
95
|
end
|
96
96
|
else
|
@@ -101,23 +101,23 @@ module SmartAgent
|
|
101
101
|
end
|
102
102
|
|
103
103
|
def call_tools(result)
|
104
|
-
@agent.processor(:tool).call({ :status => :start })
|
104
|
+
@agent.processor(:tool).call({ :status => :start }) if @agent.processor(:tool)
|
105
105
|
SmartAgent.logger.info("call tools: " + result.to_s)
|
106
106
|
results = []
|
107
107
|
result.call_tools.each do |tool|
|
108
108
|
tool_name = tool["function"]["name"].to_sym
|
109
109
|
params = JSON.parse(tool["function"]["arguments"])
|
110
110
|
if Tool.find_tool(tool_name)
|
111
|
-
@agent.processor(:tool).call({ :content => "ToolName is `#{tool_name}`" })
|
111
|
+
@agent.processor(:tool).call({ :content => "ToolName is `#{tool_name}`" }) if @agent.processor(:tool)
|
112
112
|
results << Tool.new(tool_name).call(params)
|
113
113
|
end
|
114
114
|
if server_name = MCPClient.find_server_by_tool_name(tool_name)
|
115
|
-
@agent.processor(:tool).call({ :content => "MCP Server is `#{server_name}`, ToolName is `#{tool_name}`" })
|
115
|
+
@agent.processor(:tool).call({ :content => "MCP Server is `#{server_name}`, ToolName is `#{tool_name}`" }) if @agent.processor(:tool)
|
116
116
|
results << MCPClient.new(server_name).call(tool_name, params)
|
117
117
|
end
|
118
|
-
@agent.processor(:tool).call({ :content => " ... done\n" })
|
118
|
+
@agent.processor(:tool).call({ :content => " ... done\n" }) if @agent.processor(:tool)
|
119
119
|
end
|
120
|
-
@agent.processor(:tool).call({ :status => :end })
|
120
|
+
@agent.processor(:tool).call({ :status => :end }) if @agent.processor(:tool)
|
121
121
|
return results
|
122
122
|
end
|
123
123
|
|
data/lib/smart_agent/tool.rb
CHANGED
data/lib/smart_agent/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Your Name
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-03-
|
10
|
+
date: 2025-03-30 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: smart_prompt
|