smart_agent 0.2.1 → 0.2.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: 92f316229977853df082c594f3dfe42677dcb1d92e6e0ffe7e8c12dbf09db3cd
4
- data.tar.gz: 42890f035e21b320b205b62f9de845cd7d2d0f492c13967e9147f52822af4702
3
+ metadata.gz: 1826472ee93e682836acaee95a2ffe9b9889d5b90fbf946129c60c6d2d72d6be
4
+ data.tar.gz: 50d79300276d6d3c2f6b81d3311187f033b0ee8ff2f1dcfb236d563ff4cd7f44
5
5
  SHA512:
6
- metadata.gz: 0a837125205d17f4b9c3c3a3417c014f718c406a874fbc88a7339d59ee2dee1d5fd01fd4eb13654a28349bbbda97f1acc71b8b03b7a3ef14f21afe5f1dbbdf11
7
- data.tar.gz: e721b313294d3f149cf986e9d4a3140a83fb68368542b527f5c2205fc1ff850c3a4f8982f08185bb0ac28fe681b21e95c604b557d81f19cd7a4e87b7eccc9111
6
+ metadata.gz: c6225659a1b67fe096165c22171536b7b957e8679233affca58e2b219ee81b503699c8b5d74a76660ef826c8d85d9a46f1058a05c3ae96ec9ca28830aff11c58
7
+ data.tar.gz: 2be30f9eef187409ae14f29e9af9c790dbdb34d243868f415e8c28288c89a2e6f32ef86a8206bae9b3d4da9f82f427d056ee21ce6633924616ec3b9572dd77b4
@@ -151,19 +151,16 @@ module SmartAgent
151
151
  tool_name = tool["function"]["name"].to_sym
152
152
  params = safe_parse(tool["function"]["arguments"])
153
153
  if Tool.find_tool(tool_name)
154
- @agent.processor(:tool).call({ :content => "ToolName is `#{tool_name}`\n" }) if @agent.processor(:tool)
155
- @agent.processor(:tool).call({ :content => "params is `#{params}`\n" }) if @agent.processor(:tool)
156
- tool_result = Tool.find_tool(tool_name).call(params)
154
+ tool_result = Tool.find_tool(tool_name).call(params, @agent)
157
155
  if tool_result
156
+ @agent.processor(:tool).call({ :content => tool_result })
158
157
  SmartAgent.prompt_engine.history_messages << { "role" => "assistant", "content" => "", "tool_calls" => [tool] } #result.response.dig("choices", 0, "message")
159
158
  SmartAgent.prompt_engine.history_messages << { "role" => "tool", "tool_call_id" => tool_call_id, "content" => tool_result.to_s.force_encoding("UTF-8") }
160
159
  results << tool_result
161
160
  end
162
161
  end
163
162
  if server_name = MCPClient.find_server_by_tool_name(tool_name)
164
- @agent.processor(:tool).call({ :content => "MCP Server is `#{server_name}`, ToolName is `#{tool_name}`\n" }) if @agent.processor(:tool)
165
- @agent.processor(:tool).call({ :content => "params is `#{params}`\n" }) if @agent.processor(:tool)
166
- tool_result = MCPClient.new(server_name).call(tool_name, params)
163
+ tool_result = MCPClient.new(server_name).call(tool_name, params, @agent)
167
164
  if tool_result
168
165
  @agent.processor(:tool).call({ :content => tool_result })
169
166
  SmartAgent.prompt_engine.history_messages << { "role" => "assistant", "content" => "", "tool_calls" => [tool] } # result.response.dig("choices", 0, "message")
@@ -177,6 +174,15 @@ module SmartAgent
177
174
  return results
178
175
  end
179
176
 
177
+ def call_tool(name, params = {})
178
+ if Tool.find_tool(name)
179
+ return Tool.find_tool(name).call(params, @agent)
180
+ end
181
+ if server_name = MCPClient.find_server_by_tool_name(name)
182
+ return MCPClient.new(server_name).call(name, params, @agent)
183
+ end
184
+ end
185
+
180
186
  def params
181
187
  @params ||= {}
182
188
  end
@@ -25,7 +25,11 @@ module SmartAgent
25
25
  convertFormat(mcp_server_json)
26
26
  end
27
27
 
28
- def call(tool_name, params)
28
+ def call(tool_name, params, agent = nil)
29
+ if agent
30
+ agent.processor(:tool).call({ :content => "MCP Server is `#{@name}`, ToolName is `#{tool_name}`\n" }) if agent.processor(:tool)
31
+ agent.processor(:tool).call({ :content => "params is `#{params}`\n" }) if agent.processor(:tool)
32
+ end
29
33
  @client.call_method(
30
34
  {
31
35
  "name": tool_name.to_s,
@@ -8,7 +8,11 @@ module SmartAgent
8
8
  @context = ToolContext.new(self)
9
9
  end
10
10
 
11
- def call(params)
11
+ def call(params, agent = nil)
12
+ if agent
13
+ agent.processor(:tool).call({ :content => "ToolName is `#{@name}`\n" }) if agent.processor(:tool)
14
+ agent.processor(:tool).call({ :content => "params is `#{params}`\n" }) if agent.processor(:tool)
15
+ end
12
16
  @context.input_params = params
13
17
  @context.instance_eval(&@context.proc)
14
18
  end
@@ -90,7 +94,7 @@ module SmartAgent
90
94
  SmartAgent.prompt_engine.call_worker(name, params)
91
95
  end
92
96
 
93
- def call_tool(name, params)
97
+ def call_tool(name, params = {})
94
98
  if Tool.find_tool(name)
95
99
  return Tool.find_tool(name).call(params)
96
100
  end
@@ -1,3 +1,3 @@
1
1
  module SmartAgent
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
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.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zhuang Biaowei