Skip to content

Commit

Permalink
Configure loopback transports (#3522)
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw authored Feb 19, 2025
1 parent 88d0f41 commit 277c341
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 25 deletions.
63 changes: 39 additions & 24 deletions libs/sdk-py/langgraph_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,21 @@ def get_client(
# example usage: client.<model>.<method_name>()
assistants = await client.assistants.get(assistant_id="some_uuid")
"""

transport: Optional[httpx.AsyncBaseTransport] = None
if url is None:
try:
from langgraph_api.server import app # type: ignore

if os.environ.get("__LANGGRAPH_DEFER_LOOPBACK_TRANSPORT") == "true":
transport = httpx.ASGITransport(app=None, root_path="/noauth")
_registered_transports.append(transport)
url = "http://api"
transport = httpx.ASGITransport(app, root_path="/noauth")
except Exception:
url = "http://localhost:8123"
else:
try:
from langgraph_api.server import app # type: ignore

url = "http://api"
transport = httpx.ASGITransport(app, root_path="/noauth")
except Exception:
url = "http://localhost:8123"

if transport is None:
transport = httpx.AsyncHTTPTransport(retries=5)
Expand Down Expand Up @@ -1318,9 +1324,9 @@ def stream(
""" # noqa: E501
payload = {
"input": input,
"command": {k: v for k, v in command.items() if v is not None}
if command
else None,
"command": (
{k: v for k, v in command.items() if v is not None} if command else None
),
"config": config,
"metadata": metadata,
"stream_mode": stream_mode,
Expand Down Expand Up @@ -1505,9 +1511,9 @@ async def create(
""" # noqa: E501
payload = {
"input": input,
"command": {k: v for k, v in command.items() if v is not None}
if command
else None,
"command": (
{k: v for k, v in command.items() if v is not None} if command else None
),
"stream_mode": stream_mode,
"stream_subgraphs": stream_subgraphs,
"config": config,
Expand Down Expand Up @@ -1676,9 +1682,9 @@ async def wait(
""" # noqa: E501
payload = {
"input": input,
"command": {k: v for k, v in command.items() if v is not None}
if command
else None,
"command": (
{k: v for k, v in command.items() if v is not None} if command else None
),
"config": config,
"metadata": metadata,
"assistant_id": assistant_id,
Expand Down Expand Up @@ -3483,9 +3489,9 @@ def stream(
""" # noqa: E501
payload = {
"input": input,
"command": {k: v for k, v in command.items() if v is not None}
if command
else None,
"command": (
{k: v for k, v in command.items() if v is not None} if command else None
),
"config": config,
"metadata": metadata,
"stream_mode": stream_mode,
Expand Down Expand Up @@ -3670,9 +3676,9 @@ def create(
""" # noqa: E501
payload = {
"input": input,
"command": {k: v for k, v in command.items() if v is not None}
if command
else None,
"command": (
{k: v for k, v in command.items() if v is not None} if command else None
),
"stream_mode": stream_mode,
"stream_subgraphs": stream_subgraphs,
"config": config,
Expand Down Expand Up @@ -3838,9 +3844,9 @@ def wait(
""" # noqa: E501
payload = {
"input": input,
"command": {k: v for k, v in command.items() if v is not None}
if command
else None,
"command": (
{k: v for k, v in command.items() if v is not None} if command else None
),
"config": config,
"metadata": metadata,
"assistant_id": assistant_id,
Expand Down Expand Up @@ -4444,3 +4450,12 @@ def list_namespaces(

def _provided_vals(d: dict):
return {k: v for k, v in d.items() if v is not None}


_registered_transports: list[httpx.ASGITransport] = []


# Do not move; this is used in the server.
def configure_loopback_transports(app: Any) -> None:
for transport in _registered_transports:
transport.app = app
2 changes: 1 addition & 1 deletion libs/sdk-py/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "langgraph-sdk"
version = "0.1.52"
version = "0.1.53"
description = "SDK for interacting with LangGraph API"
authors = []
license = "MIT"
Expand Down

0 comments on commit 277c341

Please sign in to comment.