langgraph-api 0.2.96__py3-none-any.whl → 0.2.98__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of langgraph-api might be problematic. Click here for more details.

langgraph_api/__init__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.2.96"
1
+ __version__ = "0.2.98"
@@ -39,11 +39,15 @@ async def create_thread(
39
39
  )
40
40
 
41
41
  if supersteps := payload.get("supersteps"):
42
- await Threads.State.bulk(
43
- conn,
44
- config={"configurable": {"thread_id": thread_id}},
45
- supersteps=supersteps,
46
- )
42
+ try:
43
+ await Threads.State.bulk(
44
+ conn,
45
+ config={"configurable": {"thread_id": thread_id}},
46
+ supersteps=supersteps,
47
+ )
48
+ except HTTPException as e:
49
+ detail = f"Thread {thread_id} was created, but there were problems updating the state: {e.detail}"
50
+ raise HTTPException(status_code=201, detail=detail) from e
47
51
 
48
52
  return ApiResponse(await fetchone(iter, not_found_code=409))
49
53
 
langgraph_api/asyncio.py CHANGED
@@ -141,6 +141,13 @@ def call_soon_in_main_loop(coro: Coroutine[Any, Any, T]) -> asyncio.Future[T]:
141
141
  return this_loop_fut
142
142
 
143
143
 
144
+ def call_soon_threadsafe(callback, *args) -> asyncio.Handle:
145
+ """Run a coroutine in the main event loop."""
146
+ if _MAIN_LOOP is None:
147
+ raise RuntimeError("No event loop set")
148
+ return _MAIN_LOOP.call_soon_threadsafe(callback, *args)
149
+
150
+
144
151
  class SimpleTaskGroup(AbstractAsyncContextManager["SimpleTaskGroup"]):
145
152
  """An async task group that can be configured to wait and/or cancel tasks on exit.
146
153
 
langgraph_api/logging.py CHANGED
@@ -68,11 +68,31 @@ class AddApiVersion:
68
68
 
69
69
 
70
70
  class AddLoggingContext:
71
+ def __init__(self):
72
+ try:
73
+ from langchain_core.runnables.config import (
74
+ RunnableConfig,
75
+ var_child_runnable_config,
76
+ )
77
+
78
+ self.cvar: contextvars.ContextVar[RunnableConfig | None] = (
79
+ var_child_runnable_config
80
+ )
81
+ except Exception:
82
+ self.cvar = False
83
+
71
84
  def __call__(
72
85
  self, logger: logging.Logger, method_name: str, event_dict: EventDict
73
86
  ) -> EventDict:
74
87
  if (ctx := worker_config.get()) is not None:
75
88
  event_dict.update(ctx)
89
+ if (
90
+ self.cvar is not None
91
+ and (conf := self.cvar.get())
92
+ and (metadata := conf.get("metadata"))
93
+ and (lgnode := metadata.get("langgraph_node"))
94
+ ):
95
+ event_dict["langgraph_node"] = lgnode
76
96
  return event_dict
77
97
 
78
98
 
@@ -128,6 +148,7 @@ class Formatter(structlog.stdlib.ProcessorFormatter):
128
148
  super().__init__(
129
149
  processors=[
130
150
  structlog.stdlib.ProcessorFormatter.remove_processors_meta,
151
+ AddLoggingContext(),
131
152
  renderer,
132
153
  ],
133
154
  foreign_pre_chain=shared_processors,
@@ -136,7 +157,6 @@ class Formatter(structlog.stdlib.ProcessorFormatter):
136
157
 
137
158
 
138
159
  # configure structlog
139
-
140
160
  if not structlog.is_configured():
141
161
  structlog.configure(
142
162
  processors=[
langgraph_api/state.py CHANGED
@@ -2,7 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  import typing
4
4
 
5
- from langgraph.types import StateSnapshot
5
+ from langgraph.types import Interrupt, StateSnapshot
6
6
 
7
7
  from langgraph_api.schema import Checkpoint, ThreadState
8
8
 
@@ -38,6 +38,23 @@ def runnable_config_to_checkpoint(
38
38
  return checkpoint
39
39
 
40
40
 
41
+ def state_interrupt_to_thread_interrupt(interrupt: Interrupt | dict) -> dict:
42
+ # Sometimes the interrupt received in StateSnapshot is a dict.
43
+ # Let's convert it toan Interrupt object to gain access to dynamic `interrupt_id`.
44
+ if isinstance(interrupt, dict):
45
+ interrupt = Interrupt(**interrupt)
46
+
47
+ return {
48
+ "interrupt_id": interrupt.interrupt_id
49
+ if hasattr(interrupt, "interrupt_id")
50
+ else None,
51
+ "value": interrupt.value,
52
+ "resumable": interrupt.resumable,
53
+ "ns": interrupt.ns,
54
+ "when": interrupt.when,
55
+ }
56
+
57
+
41
58
  def state_snapshot_to_thread_state(state: StateSnapshot) -> ThreadState:
42
59
  return {
43
60
  "values": state.values,
@@ -48,7 +65,9 @@ def state_snapshot_to_thread_state(state: StateSnapshot) -> ThreadState:
48
65
  "name": t.name,
49
66
  "path": t.path,
50
67
  "error": t.error,
51
- "interrupts": t.interrupts,
68
+ "interrupts": [
69
+ state_interrupt_to_thread_interrupt(i) for i in t.interrupts
70
+ ],
52
71
  "checkpoint": t.state["configurable"]
53
72
  if t.state is not None and not isinstance(t.state, StateSnapshot)
54
73
  else None,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: langgraph-api
3
- Version: 0.2.96
3
+ Version: 0.2.98
4
4
  Author-email: Nuno Campos <nuno@langchain.dev>, Will Fu-Hinthorn <will@langchain.dev>
5
5
  License: Elastic-2.0
6
6
  License-File: LICENSE
@@ -1,6 +1,6 @@
1
- langgraph_api/__init__.py,sha256=YQS1TD-5gNlLqV7Twd5RQ7JgXF4Qi3b2BsDy8yxanH4,23
1
+ langgraph_api/__init__.py,sha256=SZSk7mJkvklaLjMr4nqLhJATWHlSnR87dAGE8WoUVrk,23
2
2
  langgraph_api/asgi_transport.py,sha256=eqifhHxNnxvI7jJqrY1_8RjL4Fp9NdN4prEub2FWBt8,5091
3
- langgraph_api/asyncio.py,sha256=qrYEqPRrqtGq7E7KjcMC-ALyN79HkRnmp9rM2TAw9L8,9404
3
+ langgraph_api/asyncio.py,sha256=Wv4Rwm-a-Cf6JpfgJmVuVlXQ7SlwrjbTn0eq1ux8I2Q,9652
4
4
  langgraph_api/cli.py,sha256=-R0fvxg4KNxTkSe7xvDZruF24UMhStJYjpAYlUx3PBk,16018
5
5
  langgraph_api/command.py,sha256=3O9v3i0OPa96ARyJ_oJbLXkfO8rPgDhLCswgO9koTFA,768
6
6
  langgraph_api/config.py,sha256=Nxhx6fOsxk_u-Aae54JAGn46JQ1wKXPjeu_KX_3d4wQ,11918
@@ -10,7 +10,7 @@ langgraph_api/feature_flags.py,sha256=ZoId5X1FpWGvHcKAduqDMRNEKks5Bt8Eswww_xoch5
10
10
  langgraph_api/graph.py,sha256=Q9tRf1WBaxFBOgs_orlMAlBVJM0-cpZVduknU_fbzRM,24235
11
11
  langgraph_api/http.py,sha256=L0leP5fH4NIiFgJd1YPMnTRWqrUUYq_4m5j558UwM5E,5612
12
12
  langgraph_api/http_metrics.py,sha256=VgM45yU1FkXuI9CIOE_astxAAu2G-OJ42BRbkcos_CQ,5555
13
- langgraph_api/logging.py,sha256=LL2LNuMYFrqDhG_KbyKy9AoAPghcdlFj2T50zMyPddk,4182
13
+ langgraph_api/logging.py,sha256=4K1Fnq8rrGC9CqJubZtP34Y9P2zh7VXf_41q7bH3OXU,4849
14
14
  langgraph_api/metadata.py,sha256=lfovneEMLA5vTNa61weMkQkiZCtwo-qdwFwqNSj5qVs,6638
15
15
  langgraph_api/patch.py,sha256=Dgs0PXHytekX4SUL6KsjjN0hHcOtGLvv1GRGbh6PswU,1408
16
16
  langgraph_api/queue_entrypoint.py,sha256=hC8j-A4cUxibusiiPJBlK0mkmChNZxNcXn5GVwL0yic,4889
@@ -19,7 +19,7 @@ langgraph_api/schema.py,sha256=IdloGYognffSCZOFPujXE0QfNNlxQGd3BJbinYy5Q1c,5708
19
19
  langgraph_api/serde.py,sha256=0ALETUn582vNF-m0l_WOZGF_scL1VPA39fDkwMJQPrg,5187
20
20
  langgraph_api/server.py,sha256=Z_VL-kIphybTRDWBIqHMfRhgCmAFyTRqAGlgnHQF0Zg,6973
21
21
  langgraph_api/sse.py,sha256=SLdtZmTdh5D8fbWrQjuY9HYLd2dg8Rmi6ZMmFMVc2iE,4204
22
- langgraph_api/state.py,sha256=NLl5YgLKppHJ7zfF0bXjsroXmIGCZez0IlDAKNGVy0g,2365
22
+ langgraph_api/state.py,sha256=Fn38_E8K0LmK6x6RsZCWr-cnu8RH-2qLBXqkA3TgfdY,3045
23
23
  langgraph_api/store.py,sha256=srRI0fQXNFo_RSUs4apucr4BEp_KrIseJksZXs32MlQ,4635
24
24
  langgraph_api/stream.py,sha256=EorM9BD7oiCvkRXlMqnOkBd9P1X3mEagS_oHp-_9aRQ,13669
25
25
  langgraph_api/thread_ttl.py,sha256=-Ox8NFHqUH3wGNdEKMIfAXUubY5WGifIgCaJ7npqLgw,1762
@@ -35,7 +35,7 @@ langgraph_api/api/meta.py,sha256=fmc7btbtl5KVlU_vQ3Bj4J861IjlqmjBKNtnxSV-S-Q,419
35
35
  langgraph_api/api/openapi.py,sha256=KToI2glOEsvrhDpwdScdBnL9xoLOqkTxx5zKq2pMuKQ,11957
36
36
  langgraph_api/api/runs.py,sha256=37phCkg8pgEQZQNqFlehIHmvVbdeD8A1ojV7Vk7Mm08,19944
37
37
  langgraph_api/api/store.py,sha256=TSeMiuMfrifmEnEbL0aObC2DPeseLlmZvAMaMzPgG3Y,5535
38
- langgraph_api/api/threads.py,sha256=ogMKmEoiycuaV3fa5kpupDohJ7fwUOfVczt6-WSK4FE,9322
38
+ langgraph_api/api/threads.py,sha256=nQMlGnsrFD1F4S-ID_q0HZrF2GZ0Pm7aV04Sh1eYgds,9588
39
39
  langgraph_api/api/ui.py,sha256=17QrRy2XVzP7x_0RdRw7pmSv-n1lmnb54byHCGGeNhM,2490
40
40
  langgraph_api/auth/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
41
41
  langgraph_api/auth/custom.py,sha256=ZtNSQ4hIldbd2HvRsilwKzN_hjCWIiIOHClmYyPi8FM,22206
@@ -94,8 +94,8 @@ langgraph_runtime/store.py,sha256=7mowndlsIroGHv3NpTSOZDJR0lCuaYMBoTnTrewjslw,11
94
94
  LICENSE,sha256=ZPwVR73Biwm3sK6vR54djCrhaRiM4cAD2zvOQZV8Xis,3859
95
95
  logging.json,sha256=3RNjSADZmDq38eHePMm1CbP6qZ71AmpBtLwCmKU9Zgo,379
96
96
  openapi.json,sha256=p5tn_cNRiFA0HN3L6JfC9Nm16Hgv-BxvAQcJymKhVWI,143296
97
- langgraph_api-0.2.96.dist-info/METADATA,sha256=6reUZx6FDGWx6mlex-33Vg_n2LtRPnX1MCuMbnx9w-A,3891
98
- langgraph_api-0.2.96.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
99
- langgraph_api-0.2.96.dist-info/entry_points.txt,sha256=hGedv8n7cgi41PypMfinwS_HfCwA7xJIfS0jAp8htV8,78
100
- langgraph_api-0.2.96.dist-info/licenses/LICENSE,sha256=ZPwVR73Biwm3sK6vR54djCrhaRiM4cAD2zvOQZV8Xis,3859
101
- langgraph_api-0.2.96.dist-info/RECORD,,
97
+ langgraph_api-0.2.98.dist-info/METADATA,sha256=f0zTw-SE99YhdobRyKgWNLbb258h6mJS2y9HXslnByE,3891
98
+ langgraph_api-0.2.98.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
99
+ langgraph_api-0.2.98.dist-info/entry_points.txt,sha256=hGedv8n7cgi41PypMfinwS_HfCwA7xJIfS0jAp8htV8,78
100
+ langgraph_api-0.2.98.dist-info/licenses/LICENSE,sha256=ZPwVR73Biwm3sK6vR54djCrhaRiM4cAD2zvOQZV8Xis,3859
101
+ langgraph_api-0.2.98.dist-info/RECORD,,