Skip to content

fix(langgraph): lazy-load FastAPI endpoint import - #2236

Open
Solaris-star wants to merge 1 commit into
ag-ui-protocol:mainfrom
Solaris-star:fix/2013-lazy-fastapi-import
Open

fix(langgraph): lazy-load FastAPI endpoint import#2236
Solaris-star wants to merge 1 commit into
ag-ui-protocol:mainfrom
Solaris-star:fix/2013-lazy-fastapi-import

Conversation

@Solaris-star

Copy link
Copy Markdown

Summary

fastapi is declared as an optional extra for ag-ui-langgraph, but package __init__.py eagerly imported endpoint.py, which imports FastAPI at module top. Any middleware-only install then failed on:

import ag_ui_langgraph

Fix

  • Stop importing add_langgraph_fastapi_endpoint at package import time.
  • Expose it via __getattr__ so the FastAPI endpoint is only loaded when explicitly accessed.
  • Core exports (LangGraphAgent, helpers) work without FastAPI installed.

Tests

python -m pytest tests/test_lazy_fastapi_import.py tests/test_endpoint_health_path.py -q
# 6 passed

Fixes #2013

fastapi is an optional extra, but package __init__ eagerly imported
endpoint.py (which imports fastapi at module top). Middleware-only
installs then failed on any import of ag_ui_langgraph. Load the endpoint
export via __getattr__ so core helpers work without fastapi installed.

Fixes ag-ui-protocol#2013
@Solaris-star
Solaris-star requested a review from a team as a code owner July 23, 2026 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: ag-ui-langgraph __init__ eagerly imports fastapi, breaking middleware-only (non-web) installs

1 participant