Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
majiayu000 wants to merge2 commits intolangchain-ai:master
base:master
Choose a base branch
Loading
frommajiayu000:fix-async-middleware-missing-await

Conversation

@majiayu000
Copy link
Contributor

Summary

Problem

When users implementawrap_model_call and forget to await the handler:

asyncdefawrap_model_call(self,request,handler):returnhandler(request)# Missing await!

This causesAttributeError: 'coroutine' object has no attribute 'result' which is confusing.

Solution

The fix detects this scenario and:

  1. Auto-awaits the coroutine to prevent the crash
  2. Emits a warning explaining the issue and how to fix it

Test plan

  • Added tests for missing await scenarios (single/multiple middleware)
  • Added test verifying proper await does not emit warning
  • All existing middleware tests pass (167 tests)
  • Linting passes
  • Type checking passes

AI agents were involved in developing this contribution.

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
@github-actionsgithub-actionsbot added langchain`langchain` package issues & PRs fixFor PRs that implement a fix labelsDec 17, 2025
@hankbesser
Copy link

Sorry if this comes off harsh, But why add 147 lines to an already loadedfactory.py when this entails giving a warning when not adding the correct 'await' before the asynchronous handler. Also technically, if downstream middleware short circuits the system, you might not want to await the handler and have the bare coroutine move down stream.

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.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

fixFor PRs that implement a fixlangchain`langchain` package issues & PRs

Projects

None yet

Milestone

No milestone

2 participants

@majiayu000@hankbesser

[8]ページ先頭

©2009-2025 Movatter.jp