Conversation
…aming path The async for loop was outside the async with stream context manager, causing 'Attempted to read or stream content, but the stream has been closed.'
Each streaming chunk was generating a new UUID, which broke OpenAI client expectations that all chunks in a stream share the same ID. This caused 'str' object has no attribute 'items' errors on some Hermes instances. Also pass chunk_id to _build_usage_chunk so the final usage chunk matches.
Models sometimes emit malformed tags like </aktool_calls> in text output instead of using the structured SSE tool events. These leak through to the user as raw text. Now stripped in both streaming and non-streaming paths.
The OpenAI SDK requires 'index' on every tool_calls delta entry in streaming chunks (ChoiceDeltaToolCall). Without it, pydantic validation fails with 'str' object has no attribute 'items' — crashing the Hermes client after 3 retries. Non-streaming tool_calls don't need index (different pydantic model).
…ersion
When a model's previous tool call has arguments that are a raw JSON
string (e.g. '"hello"' instead of '{"key": "value"}'), json.loads
returns a string, and calling .items() on it crashes with
'AttributeError: str object has no attribute items'.
This error was caught by Guanaco's streaming error handler and sent
as an SSE error chunk, which the OpenAI SDK wrapped as APIError with
the message 'str object has no attribute items'.
Fix: wrap non-dict args in a {'value': args} dict before iterating.
When the model emits malformed DSML with broken closing tags (e.g. '</peparameter>' instead of '</|DSML|parameter>'), the standard parser never matches the close tag and the buffer grows indefinitely. The model then retries the path character-by-character, producing massive DSML tag leakage into the chat. Fix: - Add 8000-char buffer overflow guard: if DSML buffer exceeds limit without completing, try fuzzy parse before flushing as content - Add _fuzzy_parse_dsml(): extracts invoke names and parameters even with broken closing tags, using both standard and broken-tag regexes - Prevents infinite buffering and tag leakage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes
indexfield to streaming tool_calls deltas — OpenAI SDK requiresindexonChoiceDeltaToolCall; missing it caused ValidationError → APIErrorargs.items()crash when tool call arguments are a raw JSON string instead of object ('str' object has no attribute 'items')Test Results