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 +4 -4
- data/lib/smart_agent/agent.rb +12 -6
- data/lib/smart_agent/mcp_client.rb +5 -1
- data/lib/smart_agent/tool.rb +6 -2
- data/lib/smart_agent/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1826472ee93e682836acaee95a2ffe9b9889d5b90fbf946129c60c6d2d72d6be
|
4
|
+
data.tar.gz: 50d79300276d6d3c2f6b81d3311187f033b0ee8ff2f1dcfb236d563ff4cd7f44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6225659a1b67fe096165c22171536b7b957e8679233affca58e2b219ee81b503699c8b5d74a76660ef826c8d85d9a46f1058a05c3ae96ec9ca28830aff11c58
|
7
|
+
data.tar.gz: 2be30f9eef187409ae14f29e9af9c790dbdb34d243868f415e8c28288c89a2e6f32ef86a8206bae9b3d4da9f82f427d056ee21ce6633924616ec3b9572dd77b4
|
data/lib/smart_agent/agent.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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,
|
data/lib/smart_agent/tool.rb
CHANGED
@@ -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
|
data/lib/smart_agent/version.rb
CHANGED