Fix async streaming support for Agno Team.arun() - Resolves #1262 #1265
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.
📥 Pull Request
📘 Description
Fixes #1262 - Resolves
TypeError: 'async for' requires an object with __aiter__ method, got coroutinewhen using Agno v2 async streaming with AgentOps instrumentation.Root Cause: When
Team.arun(stream=True)is called, it returns an async generator directly. The previous wrapper was defined asasync def, which caused Python to wrap the returned async generator in a coroutine, breakingasync forloops.Solution:
AsyncStreamingResultWrapperclass that properly implements the async iteration protocol (__aiter__and__anext__)create_team_async_wrapperfromasync def wrappertodef wrapper- this allows async generators to be returned directly without coroutine wrappinginspect.isasyncgen()checks to detect and properly wrap async generatorscreate_streaming_agent_async_wrapperto check for__aiter__before__iter__for correct async detection🧪 Testing
Created test script
examples/agno/test_async_streaming_team.pythat reproduces the original issue:RunStartedEventconfirming async streaming worksruff checkandruff format🔍 Human Review Checklist
Critical items:
inspect.isasyncgen(result)is the correct check for detecting async generators at runtimeAsyncStreamingResultWrapper.__anext__- does span cleanup happen correctly in all cases?create_workflow_async_wrapper) need similar fixesAdditional considerations:
5. Verify context attachment/detachment is correct and doesn't leak contexts
6. Consider if this pattern change should have automated tests added
Session Info: