- Notifications
You must be signed in to change notification settings - Fork20.1k
fix(agents): auto-await coroutines in async middleware#34407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
fix(agents): auto-await coroutines in async middleware#34407
Conversation
When async middleware forgets to await handler(request), it returns acoroutine instead of ModelResponse, causing:AttributeError: 'coroutine' object has no attribute 'result'This fix adds _normalize_to_model_response_async() which:1. Detects when middleware returns a coroutine2. Auto-awaits it with a helpful warning message3. Guides users to fix their codeCloseslangchain-ai#34234
hankbesser commentedDec 17, 2025
Sorry if this comes off harsh, But why add 147 lines to an already loaded I would say this is more of a documentation point as there isn't really any asynchronous specific documentation for middleware anywhere. But those are just my two cents. Thanks for the work though. |
Summary
'coroutine' object has no attribute 'result'when usinglangchain.agents.create_agentwith async execution (ainvoke) and custom async middleware #34234_normalize_to_model_response_async()to detect when async middleware returns a coroutine instead of ModelResponse/AIMessageProblem
When users implement
awrap_model_calland forget to await the handler:This causes
AttributeError: 'coroutine' object has no attribute 'result'which is confusing.Solution
The fix detects this scenario and:
Test plan
AI agents were involved in developing this contribution.