Skip to content

Conversation

@mattwebbio
Copy link
Contributor

I was trying to use the Anthropic provider with streaming and tool calling, and ran into a couple of bugs:

  1. Streaming errors for higher-level gem events - The anthropic gem emits convenience events (SignatureEvent, ThinkingEvent, etc.) that were causing "Unexpected chunk type: signature" errors.

  2. Empty tool input JSON parsing - For tools with no parameters, empty partial_json would cause JSON.parse syntax errors.

These two changes resolved the issue locally for me. They were devised by Claude, so please look at it a little more closely - but they seem to make sense to me and as I said I have tested this on my end. Happy to make changes as necessary.

Cheers!

mattwebbio and others added 2 commits January 30, 2026 21:50
The anthropic gem (1.12+) emits higher-level convenience events
(TextEvent, ThinkingEvent, SignatureEvent, etc.) in addition to raw
streaming events when using MessageStream.

The :signature event was causing "Unexpected chunk type: signature"
errors because it lacks a :snapshot method, causing it to fall
through to the error handler.

Added explicit handling for all higher-level convenience events:
:text, :input_json, :citation, :thinking, :signature

These are safely ignored since the actual content is already
processed via the raw :content_block_delta events.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
For tools with no parameters, the streaming API may send empty
partial_json, resulting in an empty string input that would fail
JSON.parse with a syntax error.

Changes:
- Use json_buf.present? instead of just json_buf to skip empty strings
- For string inputs, check .present? before parsing and default to {}

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@TonsOfFun TonsOfFun merged commit 7a56e46 into activeagents:main Feb 1, 2026
9 checks passed
@mattwebbio mattwebbio deleted the fix-anthropic-streaming-signature-event branch February 1, 2026 03:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants