smart_agent 0.2.6 → 0.2.7
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/result.rb +60 -10
- data/lib/smart_agent/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ff8fd3192792e6b8cb6f4763f443d72525ddcec5ac8f3ea8b48dd8b1b46271ac
|
|
4
|
+
data.tar.gz: af335195cf3dfa97419c9a9b3eee058b9167c4b3e288b813283721efd97172ea
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1287d8e23a9535e82f286c10209b5f01bf4d3a560c61e77aa0f64f3926332907c484e07f83a1986ba942580a92deeee19db9ed203d2896e5b0d1c32e97b02bec
|
|
7
|
+
data.tar.gz: a5afa33689f0bb2792915ff9414e3cd4fae54ce13254ba8490f58e1ec4910d1287edfcfd77bdb4b54f8f170279cb2720ba4be28d177d4f5abfefab2d4170e34b
|
data/lib/smart_agent/result.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
1
3
|
module SmartAgent
|
|
2
4
|
class Result
|
|
3
5
|
def initialize(response)
|
|
@@ -9,16 +11,10 @@ module SmartAgent
|
|
|
9
11
|
if @response.class == String
|
|
10
12
|
return false
|
|
11
13
|
else
|
|
12
|
-
tool_calls =
|
|
13
|
-
if tool_calls
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
else
|
|
17
|
-
return false
|
|
18
|
-
end
|
|
19
|
-
else
|
|
20
|
-
return false
|
|
21
|
-
end
|
|
14
|
+
tool_calls = normalized_tool_calls
|
|
15
|
+
return false if tool_calls.empty?
|
|
16
|
+
|
|
17
|
+
return tool_calls
|
|
22
18
|
end
|
|
23
19
|
end
|
|
24
20
|
|
|
@@ -33,5 +29,59 @@ module SmartAgent
|
|
|
33
29
|
def response
|
|
34
30
|
@response
|
|
35
31
|
end
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
|
|
35
|
+
def normalized_tool_calls
|
|
36
|
+
tool_calls = openai_tool_calls
|
|
37
|
+
return tool_calls if tool_calls && !tool_calls.empty?
|
|
38
|
+
|
|
39
|
+
tool_use_blocks.map { |block| normalize_tool_use(block) }.compact
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def openai_tool_calls
|
|
43
|
+
@response.dig("choices", 0, "message", "tool_calls")
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def tool_use_blocks
|
|
47
|
+
content_blocks.select { |block| block["type"] == "tool_use" }
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def content_blocks
|
|
51
|
+
blocks = []
|
|
52
|
+
collect_content_blocks(@response, blocks)
|
|
53
|
+
blocks.select { |block| block.is_a?(Hash) }
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def collect_content_blocks(value, blocks)
|
|
57
|
+
case value
|
|
58
|
+
when Hash
|
|
59
|
+
content = value["content"]
|
|
60
|
+
blocks.concat(content) if content.is_a?(Array)
|
|
61
|
+
value.each_value { |child| collect_content_blocks(child, blocks) }
|
|
62
|
+
when Array
|
|
63
|
+
value.each { |child| collect_content_blocks(child, blocks) }
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def normalize_tool_use(block)
|
|
68
|
+
name = block["name"]
|
|
69
|
+
return nil unless name
|
|
70
|
+
|
|
71
|
+
{
|
|
72
|
+
"id" => block["id"],
|
|
73
|
+
"type" => "function",
|
|
74
|
+
"function" => {
|
|
75
|
+
"name" => name,
|
|
76
|
+
"arguments" => tool_arguments(block["input"]),
|
|
77
|
+
},
|
|
78
|
+
}
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def tool_arguments(input)
|
|
82
|
+
return input if input.is_a?(String)
|
|
83
|
+
|
|
84
|
+
JSON.generate(input || {})
|
|
85
|
+
end
|
|
36
86
|
end
|
|
37
87
|
end
|
data/lib/smart_agent/version.rb
CHANGED
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.
|
|
4
|
+
version: 0.2.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Zhuang Biaowei
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - "~>"
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: 0.4.
|
|
18
|
+
version: 0.4.2
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - "~>"
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: 0.4.
|
|
25
|
+
version: 0.4.2
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: mcp-sdk.rb
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|