Skip to content

Commit 277c341

Browse files
authored
Configure loopback transports (#3522)
1 parent 88d0f41 commit 277c341

File tree

2 files changed

+40
-25
lines changed

2 files changed

+40
-25
lines changed

libs/sdk-py/langgraph_sdk/client.py

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,21 @@ def get_client(
147147
# example usage: client.<model>.<method_name>()
148148
assistants = await client.assistants.get(assistant_id="some_uuid")
149149
"""
150+
150151
transport: Optional[httpx.AsyncBaseTransport] = None
151152
if url is None:
152-
try:
153-
from langgraph_api.server import app # type: ignore
154-
153+
if os.environ.get("__LANGGRAPH_DEFER_LOOPBACK_TRANSPORT") == "true":
154+
transport = httpx.ASGITransport(app=None, root_path="/noauth")
155+
_registered_transports.append(transport)
155156
url = "http://api"
156-
transport = httpx.ASGITransport(app, root_path="/noauth")
157-
except Exception:
158-
url = "http://localhost:8123"
157+
else:
158+
try:
159+
from langgraph_api.server import app # type: ignore
160+
161+
url = "http://api"
162+
transport = httpx.ASGITransport(app, root_path="/noauth")
163+
except Exception:
164+
url = "http://localhost:8123"
159165

160166
if transport is None:
161167
transport = httpx.AsyncHTTPTransport(retries=5)
@@ -1318,9 +1324,9 @@ def stream(
13181324
""" # noqa: E501
13191325
payload = {
13201326
"input": input,
1321-
"command": {k: v for k, v in command.items() if v is not None}
1322-
if command
1323-
else None,
1327+
"command": (
1328+
{k: v for k, v in command.items() if v is not None} if command else None
1329+
),
13241330
"config": config,
13251331
"metadata": metadata,
13261332
"stream_mode": stream_mode,
@@ -1505,9 +1511,9 @@ async def create(
15051511
""" # noqa: E501
15061512
payload = {
15071513
"input": input,
1508-
"command": {k: v for k, v in command.items() if v is not None}
1509-
if command
1510-
else None,
1514+
"command": (
1515+
{k: v for k, v in command.items() if v is not None} if command else None
1516+
),
15111517
"stream_mode": stream_mode,
15121518
"stream_subgraphs": stream_subgraphs,
15131519
"config": config,
@@ -1676,9 +1682,9 @@ async def wait(
16761682
""" # noqa: E501
16771683
payload = {
16781684
"input": input,
1679-
"command": {k: v for k, v in command.items() if v is not None}
1680-
if command
1681-
else None,
1685+
"command": (
1686+
{k: v for k, v in command.items() if v is not None} if command else None
1687+
),
16821688
"config": config,
16831689
"metadata": metadata,
16841690
"assistant_id": assistant_id,
@@ -3483,9 +3489,9 @@ def stream(
34833489
""" # noqa: E501
34843490
payload = {
34853491
"input": input,
3486-
"command": {k: v for k, v in command.items() if v is not None}
3487-
if command
3488-
else None,
3492+
"command": (
3493+
{k: v for k, v in command.items() if v is not None} if command else None
3494+
),
34893495
"config": config,
34903496
"metadata": metadata,
34913497
"stream_mode": stream_mode,
@@ -3670,9 +3676,9 @@ def create(
36703676
""" # noqa: E501
36713677
payload = {
36723678
"input": input,
3673-
"command": {k: v for k, v in command.items() if v is not None}
3674-
if command
3675-
else None,
3679+
"command": (
3680+
{k: v for k, v in command.items() if v is not None} if command else None
3681+
),
36763682
"stream_mode": stream_mode,
36773683
"stream_subgraphs": stream_subgraphs,
36783684
"config": config,
@@ -3838,9 +3844,9 @@ def wait(
38383844
""" # noqa: E501
38393845
payload = {
38403846
"input": input,
3841-
"command": {k: v for k, v in command.items() if v is not None}
3842-
if command
3843-
else None,
3847+
"command": (
3848+
{k: v for k, v in command.items() if v is not None} if command else None
3849+
),
38443850
"config": config,
38453851
"metadata": metadata,
38463852
"assistant_id": assistant_id,
@@ -4444,3 +4450,12 @@ def list_namespaces(
44444450

44454451
def _provided_vals(d: dict):
44464452
return {k: v for k, v in d.items() if v is not None}
4453+
4454+
4455+
_registered_transports: list[httpx.ASGITransport] = []
4456+
4457+
4458+
# Do not move; this is used in the server.
4459+
def configure_loopback_transports(app: Any) -> None:
4460+
for transport in _registered_transports:
4461+
transport.app = app

libs/sdk-py/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "langgraph-sdk"
3-
version = "0.1.52"
3+
version = "0.1.53"
44
description = "SDK for interacting with LangGraph API"
55
authors = []
66
license = "MIT"

0 commit comments

Comments
 (0)