Skip to content

Conversation

@KarthikeyaKollu
Copy link

Fixes #214 - Error: cannot pickle '_thread.RLock' object when using OpenAIChat with Memori + Agno in streaming mode.

The issue occurred because InvokeAsync was trying to call handle_post_response() on the raw stream object, which contains unpicklable _thread.RLock objects.

The fix detects when stream=True is in kwargs and returns a wrapped async generator that:

  1. Iterates through the stream and yields each chunk
  2. Collects chunks into raw_response using merge_chunk
  3. Only calls handle_post_response after the stream is fully consumed

This matches the behavior of InvokeAsyncStream but allows InvokeAsync to handle both streaming and non-streaming scenarios dynamically.

Fixes MemoriLabs#214 - Error: cannot pickle '_thread.RLock' object when using
OpenAIChat with Memori + Agno in streaming mode.

The issue occurred because InvokeAsync was trying to call
handle_post_response() on the raw stream object, which contains
unpicklable _thread.RLock objects.

The fix detects when stream=True is in kwargs and returns a wrapped
async generator that:
1. Iterates through the stream and yields each chunk
2. Collects chunks into raw_response using merge_chunk
3. Only calls handle_post_response after the stream is fully consumed

This matches the behavior of InvokeAsyncStream but allows InvokeAsync
to handle both streaming and non-streaming scenarios dynamically.
@devwdave
Copy link
Collaborator

devwdave commented Dec 8, 2025

@KarthikeyaKollu Thanks for the contribution! The team will review this PR later in the week and provide feedback if necessary.

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.

[Bug] Error: cannot pickle '_thread.RLock' object when using OpenAIChat with Memori + Agno (Streaming Mode)

2 participants