smart_agent 0.2.6 → 0.2.8

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: 352e9af56a4c21484309f623b893ce166561458624d9f9a6d9cfcabaff0a4766
4
- data.tar.gz: 0ff30d3602f0e205c4ca335249203a41c95a6c6d4033847494bf64b7abfb5ff4
3
+ metadata.gz: 666973e72e303998abcf62405a78a124205ccdbc741c011d3a3cec05a234e7a0
4
+ data.tar.gz: eaf248d80cd7f5c203cfde80de6dc1ed9827539173dce3afb704e5661631cf77
5
5
  SHA512:
6
- metadata.gz: db49b780b5efc00c7a1a731338cbf5aca96dff969ea2740f44f4cea81926e772db957319ee222078de39011355e55ebf8c151323a4441f7e8f36e11c36ec769f
7
- data.tar.gz: ac700a1c932f24d2be2f12fe43fe5ecf2707fbee821ce77a1caf7f081bb6a9fab7d6129f51a2e8753f4eea13988406be654b4d7c35b48ba752aa98a8be5d62cf
6
+ metadata.gz: bcf37c58978695dd35a844a31ea998f30cc8035c8b51b4267b47ab9a90d29d0d4b59de0a67194632c641e2737de1bc1692452d31fa1640b89e344760cb2e62e4
7
+ data.tar.gz: c4f6a71d195797d30ebf34a82c02e5f637bd31e3085ac056092189199628b0c34b6d23d54be3936e4c13d02d8e879c228840e2c66b3c66f16334b6cb0b7010de
@@ -153,7 +153,7 @@ module SmartAgent
153
153
  if Tool.find_tool(tool_name)
154
154
  tool_result = Tool.find_tool(tool_name).call(params, @agent)
155
155
  if tool_result
156
- @agent.processor(:tool).call({ :content => tool_result })
156
+ @agent.processor(:tool).call({ :content => tool_result }) if @agent.processor(:tool)
157
157
  SmartAgent.prompt_engine.history_messages << { "role" => "assistant", "content" => "", "tool_calls" => [tool] } #result.response.dig("choices", 0, "message")
158
158
  SmartAgent.prompt_engine.history_messages << { "role" => "tool", "tool_call_id" => tool_call_id, "content" => tool_result.to_s.force_encoding("UTF-8") }
159
159
  results << tool_result
@@ -162,7 +162,7 @@ module SmartAgent
162
162
  if server_name = MCPClient.find_server_by_tool_name(tool_name)
163
163
  tool_result = MCPClient.new(server_name).call(tool_name, params, @agent)
164
164
  if tool_result
165
- @agent.processor(:tool).call({ :content => tool_result })
165
+ @agent.processor(:tool).call({ :content => tool_result }) if @agent.processor(:tool)
166
166
  SmartAgent.prompt_engine.history_messages << { "role" => "assistant", "content" => "", "tool_calls" => [tool] } # result.response.dig("choices", 0, "message")
167
167
  SmartAgent.prompt_engine.history_messages << { "role" => "tool", "tool_call_id" => tool_call_id, "content" => tool_result.to_s }
168
168
  results << tool_result
@@ -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.6"
2
+ VERSION = "0.2.8"
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.6
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zhuang Biaowei
@@ -13,16 +13,16 @@ dependencies:
13
13
  name: smart_prompt
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
- - - "~>"
16
+ - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: 0.4.1
18
+ version: 0.5.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.1
25
+ version: 0.5.2
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: mcp-sdk.rb
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  - !ruby/object:Gem::Version
86
86
  version: '0'
87
87
  requirements: []
88
- rubygems_version: 4.0.10
88
+ rubygems_version: 4.0.13
89
89
  specification_version: 4
90
90
  summary: Intelligent agent framework with DSL and MCP integration
91
91
  test_files: []