smart_agent 0.2.5 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 073c6c178d7f30d8d61dcce3fe2d40bb0c99ac9db4650d3668d450981ccd79d6
4
- data.tar.gz: 2d4be5da80580092e1fd3c4d9a6f1d48a696b5710093b5cbdf758c316d85871e
3
+ metadata.gz: ff8fd3192792e6b8cb6f4763f443d72525ddcec5ac8f3ea8b48dd8b1b46271ac
4
+ data.tar.gz: af335195cf3dfa97419c9a9b3eee058b9167c4b3e288b813283721efd97172ea
5
5
  SHA512:
6
- metadata.gz: 5423fa3a288b71060d792f10f0f7daedde53993fbd91dac242c2cbe973ad7c3de70d8f25ca6075a2feb764d328c3c2e1b78ba3d7aee2957b074b36ebf8513651
7
- data.tar.gz: 7db9fc287b67e52de852221bc72a4496ea1ebf74db102dd0ea9bb6476ba6e27ccf12edd8bcbda8af7c33356cab7eaea51a1ab327293806a8b3c07356034e4d2a
6
+ metadata.gz: 1287d8e23a9535e82f286c10209b5f01bf4d3a560c61e77aa0f64f3926332907c484e07f83a1986ba942580a92deeee19db9ed203d2896e5b0d1c32e97b02bec
7
+ data.tar.gz: a5afa33689f0bb2792915ff9414e3cd4fae54ce13254ba8490f58e1ec4910d1287edfcfd77bdb4b54f8f170279cb2720ba4be28d177d4f5abfefab2d4170e34b
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Ruby Version](https://img.shields.io/badge/Ruby-3.2%2B-red)](https://www.ruby-lang.org/)
4
4
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](./LICENSE)
5
- [![Version](https://img.shields.io/badge/Version-0.2.5-green.svg)](./lib/smart_agent/version.rb)
5
+ [![Version](https://img.shields.io/badge/Version-0.2.6-green.svg)](./lib/smart_agent/version.rb)
6
6
 
7
7
  **An intelligent agent framework for Ruby with MCP support, tool calling, and multi-LLM integration**
8
8
 
@@ -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 = @response.dig("choices", 0, "message", "tool_calls")
13
- if tool_calls
14
- unless tool_calls.empty?
15
- return tool_calls
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
@@ -1,3 +1,3 @@
1
1
  module SmartAgent
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.7"
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.5
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.3.6
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.3.6
25
+ version: 0.4.2
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: mcp-sdk.rb
28
28
  requirement: !ruby/object:Gem::Requirement