ai-agents 0.4.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a2d71857e9614f2dad748a9510a5f29925cf070dd7a7dad59ac8a243eadbc28
4
- data.tar.gz: e0f836ad647303fdd3482ca1f1d144bda34573d74ff8741487a4a0b550860f01
3
+ metadata.gz: 28606a36bd85d6b3614af2fd49f1be51376bd31bf7d9ee2af625136b0265427c
4
+ data.tar.gz: bdc4d344b634c20b9d411098da7249069ff65f07097073212cd7715f9a3f16dd
5
5
  SHA512:
6
- metadata.gz: 2728cc0f9e4b377c438ecfd73db1ff0e72e3399f8c5602c330b78fcfb53f081bbd80e44bb3036549f0b906b8df09da5ecff371af3b895f7b0e98645e74809967
7
- data.tar.gz: c22baa1ce3c5aef5e1a2d17e208eb040f49edb46f4d275946e93fab506dcb3cc40eb1dfc9638f62beadec19a61421fe27d9fe079268b0b867b7c787a2c31cb19
6
+ metadata.gz: 25e9fd02dfe5c8944bea743b19d3977ef453cfacbf82f85bf3580d6c1c175d2eb94fd0db10e7669cad5f7abf075a01deb73803c4b800873ea12c4b92d36522b4
7
+ data.tar.gz: e20bbe3e83cc10b0392738442adbf5a275b2c7f1f6002d07a6828a1b65e885743a7568d72bf00d24d4e818d7117d6784b003ea4e6489515b25e704ec92f91d63
data/CHANGELOG.md CHANGED
@@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.4.2] - 2025-08-04
9
+
10
+ ### Fixed
11
+ - **Structured Output Conversation History**: Fixed crash when restoring conversation history containing Hash content from structured output responses
12
+ - Runner and MessageExtractor now properly handle Hash content without calling `.strip()` method
13
+ - Added `MessageExtractor.content_empty?` utility method to handle both String and Hash content types
14
+
15
+ ## [0.4.1] - 2025-08-04
16
+
17
+ ### Fixed
18
+ - **Structured Output JSON Parsing**: Fixed automatic JSON parsing for structured output responses
19
+ - Chat class now properly parses JSON string responses to Hash objects when schema is configured
20
+ - Maintains compatibility with RubyLLM's automatic parsing behavior from the documentation
21
+ - Gracefully handles invalid JSON by keeping original string content
22
+ - Added comprehensive test coverage for both valid and invalid JSON scenarios
23
+
8
24
  ## [0.4.0] - 2025-08-01
9
25
 
10
26
  ### Added
data/lib/agents/chat.rb CHANGED
@@ -55,6 +55,15 @@ module Agents
55
55
  )
56
56
  @on[:end_message]&.call(response)
57
57
 
58
+ # Handle JSON parsing for structured output (like RubyLLM::Chat)
59
+ if @schema && response.content.is_a?(String)
60
+ begin
61
+ response.content = JSON.parse(response.content)
62
+ rescue JSON::ParserError
63
+ # If parsing fails, keep content as string
64
+ end
65
+ end
66
+
58
67
  add_message(response)
59
68
 
60
69
  if response.tool_call?
@@ -17,6 +17,21 @@ module Agents
17
17
  # { role: :tool, content: "Result", tool_call_id: "call_123" }
18
18
  # ]
19
19
  class MessageExtractor
20
+ # Check if content is considered empty (handles both String and Hash content)
21
+ #
22
+ # @param content [String, Hash, nil] The content to check
23
+ # @return [Boolean] true if content is empty, false otherwise
24
+ def self.content_empty?(content)
25
+ case content
26
+ when String
27
+ content.strip.empty?
28
+ when Hash
29
+ content.empty?
30
+ else
31
+ content.nil?
32
+ end
33
+ end
34
+
20
35
  # Extract messages from a chat object for conversation history persistence
21
36
  #
22
37
  # @param chat [Object] Chat object that responds to :messages
@@ -47,7 +62,7 @@ module Agents
47
62
  private
48
63
 
49
64
  def extract_user_or_assistant_message(msg)
50
- return nil unless msg.content && !msg.content.strip.empty?
65
+ return nil unless msg.content && !self.class.content_empty?(msg.content)
51
66
 
52
67
  message = {
53
68
  role: msg.role,
data/lib/agents/runner.rb CHANGED
@@ -200,7 +200,7 @@ module Agents
200
200
  history.each do |msg|
201
201
  # Only restore user and assistant messages with content
202
202
  next unless %i[user assistant].include?(msg[:role].to_sym)
203
- next unless msg[:content] && !msg[:content].strip.empty?
203
+ next unless msg[:content] && !MessageExtractor.content_empty?(msg[:content])
204
204
 
205
205
  chat.add_message(
206
206
  role: msg[:role].to_sym,
@@ -228,8 +228,6 @@ module Agents
228
228
 
229
229
  # Clean up temporary handoff state
230
230
  context_wrapper.context.delete(:pending_handoff)
231
- rescue StandardError => e
232
- puts "[Agents] Failed to save conversation state: #{e.message}"
233
231
  end
234
232
 
235
233
  def create_chat(agent, context_wrapper)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Agents
4
- VERSION = "0.4.0"
4
+ VERSION = "0.4.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ai-agents
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shivam Mishra