@@ -147,15 +147,21 @@ def get_client(
147
147
# example usage: client.<model>.<method_name>()
148
148
assistants = await client.assistants.get(assistant_id="some_uuid")
149
149
"""
150
+
150
151
transport : Optional [httpx .AsyncBaseTransport ] = None
151
152
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 )
155
156
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"
159
165
160
166
if transport is None :
161
167
transport = httpx .AsyncHTTPTransport (retries = 5 )
@@ -1318,9 +1324,9 @@ def stream(
1318
1324
""" # noqa: E501
1319
1325
payload = {
1320
1326
"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
+ ) ,
1324
1330
"config" : config ,
1325
1331
"metadata" : metadata ,
1326
1332
"stream_mode" : stream_mode ,
@@ -1505,9 +1511,9 @@ async def create(
1505
1511
""" # noqa: E501
1506
1512
payload = {
1507
1513
"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
+ ) ,
1511
1517
"stream_mode" : stream_mode ,
1512
1518
"stream_subgraphs" : stream_subgraphs ,
1513
1519
"config" : config ,
@@ -1676,9 +1682,9 @@ async def wait(
1676
1682
""" # noqa: E501
1677
1683
payload = {
1678
1684
"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
+ ) ,
1682
1688
"config" : config ,
1683
1689
"metadata" : metadata ,
1684
1690
"assistant_id" : assistant_id ,
@@ -3483,9 +3489,9 @@ def stream(
3483
3489
""" # noqa: E501
3484
3490
payload = {
3485
3491
"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
+ ) ,
3489
3495
"config" : config ,
3490
3496
"metadata" : metadata ,
3491
3497
"stream_mode" : stream_mode ,
@@ -3670,9 +3676,9 @@ def create(
3670
3676
""" # noqa: E501
3671
3677
payload = {
3672
3678
"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
+ ) ,
3676
3682
"stream_mode" : stream_mode ,
3677
3683
"stream_subgraphs" : stream_subgraphs ,
3678
3684
"config" : config ,
@@ -3838,9 +3844,9 @@ def wait(
3838
3844
""" # noqa: E501
3839
3845
payload = {
3840
3846
"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
+ ) ,
3844
3850
"config" : config ,
3845
3851
"metadata" : metadata ,
3846
3852
"assistant_id" : assistant_id ,
@@ -4444,3 +4450,12 @@ def list_namespaces(
4444
4450
4445
4451
def _provided_vals (d : dict ):
4446
4452
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
0 commit comments