generated from langchain-ai/react-agent
-
Notifications
You must be signed in to change notification settings - Fork 467
Open
Description
Used the following;
langgraph new --template=new-langgraph-project-python langgraph-app
uv sync
uv run langgraph dev
This runs without error and opens langgraph studio.
Tried adding an app.py to src/agent with stubbed version of a fasthtml app.
Added app to langgraph.json file:
{
"$schema": "https://langgra.ph/schema.json",
"dependencies": [
"."
],
"graphs": {
"agent": "./src/agent/graph.py:graph"
},
"http": {
"app": "./src/agent/app.py:app"
},
"env": ".env",
"image_distro": "wolfi"
}
But I get this error:
2025-11-09T22:06:05.685586Z [info ] Loading custom app from ./src/agent/app.py:app [langgraph_api.api] api_variant=local_dev langgraph_api_version=0.5.9 thread_name=MainThread
2025-11-09T22:06:05.756227Z [info ] 3 changes detected [watchfiles.main] api_variant=local_dev langgraph_api_version=0.5.9 thread_name=MainThread
Process SpawnProcess-1:
Traceback (most recent call last):
File "/Users/gmercer/miniconda3/lib/python3.11/multiprocessing/process.py", line 314, in _bootstrap
self.run()
File "/Users/gmercer/miniconda3/lib/python3.11/multiprocessing/process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "/Users/gmercer/Desktop/ai/langgraph-app/.venv/lib/python3.11/site-packages/uvicorn/_subprocess.py", line 80, in subprocess_started
target(sockets=sockets)
File "/Users/gmercer/Desktop/ai/langgraph-app/.venv/lib/python3.11/site-packages/uvicorn/server.py", line 67, in run
return asyncio_run(self.serve(sockets=sockets), loop_factory=self.config.get_loop_factory())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/gmercer/Desktop/ai/langgraph-app/.venv/lib/python3.11/site-packages/uvicorn/_compat.py", line 30, in asyncio_run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "/Users/gmercer/miniconda3/lib/python3.11/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "uvloop/loop.pyx", line 1518, in uvloop.loop.Loop.run_until_complete
File "/Users/gmercer/Desktop/ai/langgraph-app/.venv/lib/python3.11/site-packages/uvicorn/server.py", line 71, in serve
await self._serve(sockets)
File "/Users/gmercer/Desktop/ai/langgraph-app/.venv/lib/python3.11/site-packages/uvicorn/server.py", line 78, in _serve
config.load()
File "/Users/gmercer/Desktop/ai/langgraph-app/.venv/lib/python3.11/site-packages/uvicorn/config.py", line 439, in load
self.loaded_app = import_from_string(self.app)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/gmercer/Desktop/ai/langgraph-app/.venv/lib/python3.11/site-packages/uvicorn/importer.py", line 19, in import_from_string
module = importlib.import_module(module_str)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/gmercer/miniconda3/lib/python3.11/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 940, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/Users/gmercer/Desktop/ai/langgraph-app/.venv/lib/python3.11/site-packages/langgraph_api/server.py", line 217, in <module>
update_openapi_spec(app)
File "/Users/gmercer/Desktop/ai/langgraph-app/.venv/lib/python3.11/site-packages/langgraph_api/server.py", line 123, in update_openapi_spec
spec = schemas.get_schema(routes=app.routes)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/gmercer/Desktop/ai/langgraph-app/.venv/lib/python3.11/site-packages/langgraph_api/utils/__init__.py", line 141, in get_schema
parsed = self.parse_docstring(endpoint.func)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/gmercer/Desktop/ai/langgraph-app/.venv/lib/python3.11/site-packages/starlette/schemas.py", line 113, in parse_docstring
parsed = yaml.safe_load(docstring)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/gmercer/Desktop/ai/langgraph-app/.venv/lib/python3.11/site-packages/yaml/__init__.py", line 125, in safe_load
return load(stream, SafeLoader)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/gmercer/Desktop/ai/langgraph-app/.venv/lib/python3.11/site-packages/yaml/__init__.py", line 81, in load
return loader.get_single_data()
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/gmercer/Desktop/ai/langgraph-app/.venv/lib/python3.11/site-packages/yaml/constructor.py", line 49, in get_single_data
node = self.get_single_node()
^^^^^^^^^^^^^^^^^^^^^^
File "/Users/gmercer/Desktop/ai/langgraph-app/.venv/lib/python3.11/site-packages/yaml/composer.py", line 36, in get_single_node
document = self.compose_document()
^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/gmercer/Desktop/ai/langgraph-app/.venv/lib/python3.11/site-packages/yaml/composer.py", line 58, in compose_document
self.get_event()
File "/Users/gmercer/Desktop/ai/langgraph-app/.venv/lib/python3.11/site-packages/yaml/parser.py", line 118, in get_event
self.current_event = self.state()
^^^^^^^^^^^^
File "/Users/gmercer/Desktop/ai/langgraph-app/.venv/lib/python3.11/site-packages/yaml/parser.py", line 193, in parse_document_end
token = self.peek_token()
^^^^^^^^^^^^^^^^^
File "/Users/gmercer/Desktop/ai/langgraph-app/.venv/lib/python3.11/site-packages/yaml/scanner.py", line 129, in peek_token
self.fetch_more_tokens()
File "/Users/gmercer/Desktop/ai/langgraph-app/.venv/lib/python3.11/site-packages/yaml/scanner.py", line 223, in fetch_more_tokens
return self.fetch_value()
^^^^^^^^^^^^^^^^^^
File "/Users/gmercer/Desktop/ai/langgraph-app/.venv/lib/python3.11/site-packages/yaml/scanner.py", line 577, in fetch_value
raise ScannerError(None, None,
yaml.scanner.ScannerError: mapping values are not allowed here
in "<unicode string>", line 3, column 61:
... to support the following methods:
Here is what the app.py looks like if that helps:
# mypy: disable-error-code="no-untyped-def,misc"
"""FastHTML-based chat interface for the LangGraph agent.
This module implements a real-time chat interface using FastHTML components and Server-Sent Events (SSE)
for streaming responses. It maintains conversation history and supports multiple chat threads per user.
Mostly based on: https://github.com/AnswerDotAI/fasthtml-example/blob/main/04_sse/sse_chatbot.py
Note: the JS / CSS in this was largely vibe-coded. The main **point** of this repo is
to show that you can add custom routes to a langgraph deployment so you can do things like
stream responses or add a custom UI.
"""
import uuid
from typing import AsyncGenerator, Dict
from fasthtml.common import ( # type: ignore
H2,
A,
Button,
Div,
FastHTML,
Form,
Input,
Link,
Script,
Title,
picolink,
)
from fasthtml.core import Request # type: ignore
from langgraph_sdk import get_client
from starlette.responses import RedirectResponse, StreamingResponse
# Initialize the LangGraph client
langgraph_client = get_client()
# Define HTML headers for styling and client-side functionality
tlink = (Script(src="https://cdn.tailwindcss.com"),)
dlink = Link(
rel="stylesheet",
href="https://cdn.jsdelivr.net/npm/daisyui@4.11.1/dist/full.min.css",
)
sselink = Script(src="https://unpkg.com/htmx-ext-sse@2.2.1/sse.js")
# Add custom styles
custom_styles = Script(
"""
"""
)
fonts = Link(
rel="stylesheet",
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap",
)
app = FastHTML(hdrs=(tlink, dlink, picolink, sselink, custom_styles, fonts), live=True)
@app.get("/") # type: ignore
def get():
return Div(P('Hello World!'), hx_get="/change")
Metadata
Metadata
Assignees
Labels
No labels