fix(langgraph/python): import ag_ui_langgraph without FastAPI installed (#2067)#2182
Open
dkedar7 wants to merge 1 commit into
Open
fix(langgraph/python): import ag_ui_langgraph without FastAPI installed (#2067)#2182dkedar7 wants to merge 1 commit into
dkedar7 wants to merge 1 commit into
Conversation
FastAPI is declared an optional dependency (only the HTTP endpoint helper in endpoint.py uses it), but __init__.py eagerly imported `.endpoint`, so `import ag_ui_langgraph` / `from ag_ui_langgraph import LangGraphAgent` raised ModuleNotFoundError: No module named 'fastapi' when FastAPI wasn't installed -- breaking every purely in-process consumer that just iterates LangGraphAgent.run() to render AG-UI events locally (a terminal or Jupyter renderer, for example). Guard the optional endpoint import: add_langgraph_fastapi_endpoint stays in __all__ and is simply None until FastAPI is present, so the served path is unchanged. endpoint.py is the only module importing fastapi/starlette; the adapter (agent/types/utils/a2ui_tool/middlewares) is already FastAPI-free. Adds a regression test that blocks fastapi/starlette in a subprocess and asserts LangGraphAgent imports and add_langgraph_fastapi_endpoint is None. Fixes ag-ui-protocol#2067 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #2067.
Problem
FastAPI is declared an optional dependency of
ag-ui-langgraph(only the HTTP endpoint helper inendpoint.pyuses it), butag_ui_langgraph/__init__.pyeagerly imports.endpoint. So a purely in-process consumer — one that just iteratesLangGraphAgent.run()to render AG-UI events locally (a terminal or Jupyter renderer, say) — can't import the package without the web stack:endpoint.pyis the only module importingfastapi/starlette; the adapter itself (agent.py,types.py,utils.py,a2ui_tool.py,middlewares/) is already FastAPI-free.Fix
Guard the optional endpoint import:
add_langgraph_fastapi_endpointstays in__all__and is simplyNoneuntil FastAPI is present, so the served path is unchanged.Tests
Adds
tests/test_import_without_fastapi.py— a regression test that blocksfastapi/starlettein a subprocess and assertsLangGraphAgentimports andadd_langgraph_fastapi_endpoint is None. Verified the existingtest_deprecation_warnings.pyandtest_endpoint_health_path.pystill pass (the guard doesn't touch the served path), and the full Python suite passes (380 tests).Context: I filed #2067 two weeks ago with this diagnosis and offered to PR; sending it now since the change is small and ready. Happy to adjust to whatever you prefer.