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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e36441cd494df0719fcfe3ecff04976392e091372706e04e65949c6d17f32e95
4
- data.tar.gz: dabe51abbd3e8cb0b8184f042b32361a0a50fe9cbc4f7b86e8fa93b88ee222aa
3
+ metadata.gz: f34059e0f8389ab46e42221507a17545c3e5baf0ae63c5d7273018168f608d30
4
+ data.tar.gz: cf815b9c79556577b56328ef992dfa5f522871c4c805b8d7d1e8c24d24a45947
5
5
  SHA512:
6
- metadata.gz: '09335af182cc6402c814098f1de24dbf62e5ef5187fb6297c3f4b2b301e04d8b37e1da242b0d7bb0ea55d42722ca90c7ce451fbdd7d7832ff84dd1f1f6643751'
7
- data.tar.gz: 910c95df53d2564bc1f842c56925866d8ac255365c9329e7113450dbb9fffd9d8221d51c3c72e3342c4bbfec0b33bf79642eeb736457b188c76f4025cf96c71a
6
+ metadata.gz: 0a5ee8bc0ac6af2c198ba15d855b5fcdf181fb27cce922e7f0f649018e3aaa8ed3836723fa4cd2b41d3b1afa2806b679980a5e64a3fdecc33cddd596287ad861
7
+ data.tar.gz: 9da300c1c13c8c0828d92ccd2ae7caa3bb228be51439bab7dc6ab4211f22686d76f91a4c11fab56bd67d62b412dd375fb6ab294e4805b8fffd62105d95a25670
data/README.md CHANGED
@@ -1,76 +1,89 @@
1
- # Smart Agent Framework
1
+ # SmartAgent Framework
2
2
 
3
- [![Ruby Version](https://img.shields.io/badge/Ruby-3.2%2B-red)](https://www.ruby-lang.org)
4
- [![Gem Version](https://img.shields.io/gem/v/smart_agent)](https://rubygems.org/gems/smart_agent)
5
- [![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
3
+ SmartAgent is an intelligent agent framework developed in Ruby, supporting tool calling and natural language interaction.
6
4
 
7
- An intelligent agent framework built on [smart_prompt](https://github.com/zhuangbiaowei/smart_prompt), featuring DSL definition, function calling and MCP protocol integration.
5
+ ## Features
8
6
 
9
- ## Key Features
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
- - **Declarative DSL** - Define agents and workflows using concise Ruby syntax
12
- - **Function Calling** - Seamless integration with LLM capabilities
13
- - **MCP Protocol** - Built-in Model Context Protocol support
14
- - **Task Orchestration** - Coordinate multiple agents for complex tasks
15
- - **Extensible Architecture** - Support custom functions and protocol handlers
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
- ## Quick Start
38
+ ### Basic Usage
18
39
 
19
40
  ```ruby
20
41
  require 'smart_agent'
21
42
 
22
- SmartAgent.define :weather_bot do
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
- SmartAgent::Tool.define :get_weather do |location, date|
33
- param_define :location, "City or More Specific Address", :str
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
- engine = SmartPrompt::Engine.new("./config/llm_config.yml")
39
- SmartAgent.engine = engine
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
- puts agent.please("Get tomorrow's weather forecast in Shanghai")
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
- ## Installation
55
+ ### Custom Tools
46
56
 
47
- Add to your Gemfile:
48
57
  ```ruby
49
- gem 'smart_agent'
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
- Then execute:
53
- ```bash
54
- bundle install
55
- ```
69
+ ## MCP Integration
56
70
 
57
- Or install directly:
58
- ```bash
59
- gem install smart_agent
60
- ```
71
+ Supports getting GitHub project metrics via OpenDigger MCP service:
61
72
 
62
- ## Documentation
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
- Full documentation available at: [docs.smartagent.dev](https://docs.smartagent.dev)
80
+ puts agent.please("Query OpenRank metrics changes for Vue project on GitHub")
81
+ ```
65
82
 
66
83
  ## Contributing
67
84
 
68
- 1. Fork the repository
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
- Released under the MIT License. See [LICENSE](LICENSE) for details.
89
+ MIT License. See LICENSE file for details.
@@ -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
 
@@ -63,5 +63,9 @@ module SmartAgent
63
63
  def param_define(name, description, type)
64
64
  params[name] = { description: description, type: type }
65
65
  end
66
+
67
+ def call_worker(name, params)
68
+ SmartAgent.prompt_engine.call_worker(name, params)
69
+ end
66
70
  end
67
71
  end
@@ -1,3 +1,3 @@
1
1
  module SmartAgent
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
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.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-28 00:00:00.000000000 Z
10
+ date: 2025-03-30 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: smart_prompt