Fix OpenAI stream wrapper attribute delegation #1098
Closed
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.
Fix OpenAI Stream Wrapper Attribute Delegation
Fixes #1101
Problem
Users integrating AgentOps with ChainLit and other frameworks were encountering the error:
This occurred when code tried to access attributes like
choiceson OpenAI streaming responses that were wrapped by AgentOps instrumentation.Root Cause
The
OpenAIAsyncStreamWrapperandOpenaiStreamWrapperclasses act as proxies around OpenAI stream objects but didn't implement__getattr__to delegate attribute access to the underlying stream. When code accessedstream.choices, Python looked for the attribute on the wrapper class, couldn't find it, and raised anAttributeError.Solution
Added
__getattr__method to both wrapper classes following the established pattern in the codebase (similar toagentops/instrumentation/agentic/agno/instrumentor.py):This ensures any attribute not explicitly defined on the wrapper gets forwarded to the underlying stream object, making the wrapper transparent to users.
Changes
__getattr__method toOpenAIAsyncStreamWrapperclass__getattr__method toOpenaiStreamWrapperclass (sync version) for consistencyself._streamTesting
choices,model,id, and other stream attributesCompatibility
Link to Devin run: https://app.devin.ai/sessions/37821e78215c47a2965b384be6169155
Requested by: Alex ([email protected])