smart_agent 0.2.1 → 0.2.3
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 +22 -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: d6400f1562f197a6506e7d11644b703dba1a247f72b264bc0d4fdf20fbda9156
|
|
4
|
+
data.tar.gz: 19057cba182dcd003525eb44abc98f3e445e40749f0df8a584054ec3ec24a022
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4476b0feeac3175ed2ff681ab41731f4b3c0f590b9318a193836b646b4028564c99791a38181e8021ec67d4986ec024355f9d15121ab239cf2fff4174c71be75
|
|
7
|
+
data.tar.gz: a29fdfeee975a91f7b58ee96552d92d80040c3aa0829f16022ce604f5d7e81f60ed14704aedc192d2c0b977cbc81889ec290580ea251ba9d02a774d11e73ae60
|
data/lib/smart_agent/agent.rb
CHANGED
|
@@ -26,6 +26,10 @@ 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
|
+
|
|
29
33
|
def on_event
|
|
30
34
|
if @reasoning_event_proc || @content_event_proc
|
|
31
35
|
return true
|
|
@@ -42,6 +46,8 @@ module SmartAgent
|
|
|
42
46
|
return @content_event_proc
|
|
43
47
|
when :tool
|
|
44
48
|
return @tool_call_proc
|
|
49
|
+
when :logging
|
|
50
|
+
return @log_proc
|
|
45
51
|
else
|
|
46
52
|
return nil
|
|
47
53
|
end
|
|
@@ -69,6 +75,10 @@ module SmartAgent
|
|
|
69
75
|
@agent = agent
|
|
70
76
|
end
|
|
71
77
|
|
|
78
|
+
def show_log(msg)
|
|
79
|
+
@agent.processor(:logging).call(msg) if @agent.processor(:logging)
|
|
80
|
+
end
|
|
81
|
+
|
|
72
82
|
def call_worker(name, params, with_tools: true, with_history: false)
|
|
73
83
|
SmartAgent.logger.info("Call Worker name is: #{name}")
|
|
74
84
|
SmartAgent.logger.info("Call Worker params is: #{params}")
|
|
@@ -151,19 +161,16 @@ module SmartAgent
|
|
|
151
161
|
tool_name = tool["function"]["name"].to_sym
|
|
152
162
|
params = safe_parse(tool["function"]["arguments"])
|
|
153
163
|
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)
|
|
164
|
+
tool_result = Tool.find_tool(tool_name).call(params, @agent)
|
|
157
165
|
if tool_result
|
|
166
|
+
@agent.processor(:tool).call({ :content => tool_result })
|
|
158
167
|
SmartAgent.prompt_engine.history_messages << { "role" => "assistant", "content" => "", "tool_calls" => [tool] } #result.response.dig("choices", 0, "message")
|
|
159
168
|
SmartAgent.prompt_engine.history_messages << { "role" => "tool", "tool_call_id" => tool_call_id, "content" => tool_result.to_s.force_encoding("UTF-8") }
|
|
160
169
|
results << tool_result
|
|
161
170
|
end
|
|
162
171
|
end
|
|
163
172
|
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)
|
|
173
|
+
tool_result = MCPClient.new(server_name).call(tool_name, params, @agent)
|
|
167
174
|
if tool_result
|
|
168
175
|
@agent.processor(:tool).call({ :content => tool_result })
|
|
169
176
|
SmartAgent.prompt_engine.history_messages << { "role" => "assistant", "content" => "", "tool_calls" => [tool] } # result.response.dig("choices", 0, "message")
|
|
@@ -177,6 +184,15 @@ module SmartAgent
|
|
|
177
184
|
return results
|
|
178
185
|
end
|
|
179
186
|
|
|
187
|
+
def call_tool(name, params = {})
|
|
188
|
+
if Tool.find_tool(name)
|
|
189
|
+
return Tool.find_tool(name).call(params, @agent)
|
|
190
|
+
end
|
|
191
|
+
if server_name = MCPClient.find_server_by_tool_name(name)
|
|
192
|
+
return MCPClient.new(server_name).call(name, params, @agent)
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
|
|
180
196
|
def params
|
|
181
197
|
@params ||= {}
|
|
182
198
|
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