langgraph-api 0.19.0.dev8__py3-none-any.whl → 0.19.0.dev9__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.
- langgraph_api/__init__.py +1 -1
- langgraph_api/_checkpointer/_adapter.py +3 -1
- langgraph_api/api/__init__.py +1 -1
- langgraph_api/api/threads.py +6 -1
- langgraph_api/cli.py +20 -1
- langgraph_api/config/__init__.py +6 -0
- langgraph_api/embedded_core.py +114 -0
- langgraph_api/event_streaming/service.py +19 -16
- langgraph_api/feature_flags.py +8 -2
- langgraph_api/grpc/client.py +1 -1
- langgraph_api/grpc/ops/threads.py +8 -0
- langgraph_api/runtime/checkpoint.py +6 -0
- langgraph_api/runtime/database.py +38 -0
- langgraph_api/runtime/lifespan.py +50 -0
- langgraph_api/runtime/routes.py +56 -0
- langgraph_api/runtime/store.py +44 -0
- langgraph_api/store.py +3 -3
- langgraph_api/stream.py +2 -0
- {langgraph_api-0.19.0.dev8.dist-info → langgraph_api-0.19.0.dev9.dist-info}/METADATA +5 -1
- {langgraph_api-0.19.0.dev8.dist-info → langgraph_api-0.19.0.dev9.dist-info}/RECORD +27 -22
- langgraph_grpc_common/proto/core_api_pb2.py +160 -160
- langgraph_grpc_common/proto/core_api_pb2.pyi +36 -4
- langgraph_runtime/__init__.py +16 -1
- openapi.json +25 -1
- {langgraph_api-0.19.0.dev8.dist-info → langgraph_api-0.19.0.dev9.dist-info}/WHEEL +0 -0
- {langgraph_api-0.19.0.dev8.dist-info → langgraph_api-0.19.0.dev9.dist-info}/entry_points.txt +0 -0
- {langgraph_api-0.19.0.dev8.dist-info → langgraph_api-0.19.0.dev9.dist-info}/licenses/LICENSE +0 -0
langgraph_api/__init__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.19.0.
|
|
1
|
+
__version__ = "0.19.0.dev9"
|
|
@@ -347,11 +347,13 @@ async def get_checkpointer(
|
|
|
347
347
|
)
|
|
348
348
|
|
|
349
349
|
from langgraph_api.feature_flags import ( # noqa: PLC0415
|
|
350
|
+
INMEM_USES_CORE,
|
|
350
351
|
IS_POSTGRES_BACKEND,
|
|
351
352
|
PREFER_GRPC_CHECKPOINTER,
|
|
352
353
|
)
|
|
353
354
|
|
|
354
|
-
|
|
355
|
+
# Inmem on Go core has no Python checkpointer.
|
|
356
|
+
if INMEM_USES_CORE or (IS_POSTGRES_BACKEND and PREFER_GRPC_CHECKPOINTER):
|
|
355
357
|
return cast(
|
|
356
358
|
"FullCheckpointerProtocol",
|
|
357
359
|
GrpcCheckpointer(
|
langgraph_api/api/__init__.py
CHANGED
|
@@ -287,7 +287,7 @@ custom_app_lifespan = (
|
|
|
287
287
|
|
|
288
288
|
|
|
289
289
|
if "__inmem" in MIGRATIONS_PATH:
|
|
290
|
-
from
|
|
290
|
+
from langgraph_runtime.routes import get_internal_routes
|
|
291
291
|
|
|
292
292
|
if get_internal_routes is not None:
|
|
293
293
|
for route in get_internal_routes():
|
langgraph_api/api/threads.py
CHANGED
|
@@ -122,7 +122,12 @@ def _exclude_metadata_kwargs(payload: dict) -> dict:
|
|
|
122
122
|
return {"exclude_metadata": exclude_metadata}
|
|
123
123
|
|
|
124
124
|
|
|
125
|
-
_THREAD_TIME_RANGE_FIELDS = (
|
|
125
|
+
_THREAD_TIME_RANGE_FIELDS = (
|
|
126
|
+
"created_after",
|
|
127
|
+
"created_before",
|
|
128
|
+
"state_updated_after",
|
|
129
|
+
"state_updated_before",
|
|
130
|
+
)
|
|
126
131
|
|
|
127
132
|
|
|
128
133
|
def _time_range_kwargs(payload: dict) -> dict:
|
langgraph_api/cli.py
CHANGED
|
@@ -16,6 +16,8 @@ from concurrent.futures import ThreadPoolExecutor
|
|
|
16
16
|
from concurrent.futures import TimeoutError as FutureTimeoutError
|
|
17
17
|
from typing import Literal
|
|
18
18
|
|
|
19
|
+
from langgraph_api import embedded_core
|
|
20
|
+
|
|
19
21
|
if typing.TYPE_CHECKING:
|
|
20
22
|
from packaging.version import Version
|
|
21
23
|
|
|
@@ -299,7 +301,24 @@ def run_server(
|
|
|
299
301
|
continue
|
|
300
302
|
to_patch[k] = v
|
|
301
303
|
|
|
302
|
-
|
|
304
|
+
def _env(name: str, default: str = "") -> str:
|
|
305
|
+
if env_vars and name in env_vars:
|
|
306
|
+
return env_vars[name]
|
|
307
|
+
return os.getenv(name, default)
|
|
308
|
+
|
|
309
|
+
use_core = runtime_edition == "inmem" and _env(
|
|
310
|
+
"FF_INMEM_CORE", "false"
|
|
311
|
+
).lower() in ("true", "1", "yes")
|
|
312
|
+
if use_core:
|
|
313
|
+
to_patch[embedded_core.ADDRESS_ENV] = ""
|
|
314
|
+
core = (
|
|
315
|
+
embedded_core.start(None if disable_persistence else embedded_core.SQLITE_PATH)
|
|
316
|
+
if use_core
|
|
317
|
+
else contextlib.nullcontext(None)
|
|
318
|
+
)
|
|
319
|
+
with patch_environment(**to_patch), core as core_address:
|
|
320
|
+
if core_address is not None:
|
|
321
|
+
os.environ[embedded_core.ADDRESS_ENV] = core_address
|
|
303
322
|
is_ssl = ssl_certfile is not None and ssl_keyfile is not None
|
|
304
323
|
local_url = _resolve_server_url(
|
|
305
324
|
host,
|
langgraph_api/config/__init__.py
CHANGED
|
@@ -207,6 +207,12 @@ LANGGRAPH_CLOUD_LICENSE_KEY = env("LANGGRAPH_CLOUD_LICENSE_KEY", cast=str, defau
|
|
|
207
207
|
# When true, the Go core-server owns Postgres schema setup (DB migrations +
|
|
208
208
|
# vector index)
|
|
209
209
|
DB_MIGRATION_BY_CORE_API = env("DB_MIGRATION_BY_CORE_API", cast=bool, default=True)
|
|
210
|
+
# Bounds core-server startup, including migrations, and how long Python waits
|
|
211
|
+
# for it. Core-server reads the same env var. Keep under the startup probe.
|
|
212
|
+
# Not in public docs: infrastructure, set by platform
|
|
213
|
+
STARTUP_TIMEOUT_SECONDS = env("STARTUP_TIMEOUT_SECONDS", cast=float, default=270.0)
|
|
214
|
+
if STARTUP_TIMEOUT_SECONDS <= 0:
|
|
215
|
+
STARTUP_TIMEOUT_SECONDS = 270.0
|
|
210
216
|
|
|
211
217
|
# redis
|
|
212
218
|
# Not in public docs: infrastructure, set by platform
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
import os
|
|
5
|
+
import subprocess
|
|
6
|
+
import tempfile
|
|
7
|
+
import time
|
|
8
|
+
from contextlib import contextmanager
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import TYPE_CHECKING
|
|
11
|
+
|
|
12
|
+
try:
|
|
13
|
+
from langgraph_api_core_bin import binary_path
|
|
14
|
+
except ImportError:
|
|
15
|
+
binary_path = None
|
|
16
|
+
|
|
17
|
+
if TYPE_CHECKING:
|
|
18
|
+
from collections.abc import Iterator
|
|
19
|
+
|
|
20
|
+
logger = logging.getLogger(__name__)
|
|
21
|
+
|
|
22
|
+
# Hands the address of a core started by ``langgraph dev`` to its server process.
|
|
23
|
+
ADDRESS_ENV = "LANGGRAPH_EMBEDDED_CORE_ADDRESS"
|
|
24
|
+
SQLITE_PATH = os.path.join(".langgraph_api", "core.sqlite")
|
|
25
|
+
# Local data formats this version no longer reads. Add a pattern whenever a
|
|
26
|
+
# change drops local dev data instead of migrating it.
|
|
27
|
+
DROPPED_LOCAL_DATA = (
|
|
28
|
+
".*.pckl", # Python in-memory runtime
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@contextmanager
|
|
33
|
+
def start(sqlite_path: str | None = None) -> Iterator[str]:
|
|
34
|
+
"""Run Go core on SQLite; in-memory unless ``sqlite_path`` is given."""
|
|
35
|
+
if binary_path is None:
|
|
36
|
+
raise RuntimeError(
|
|
37
|
+
"Local development requires the inmem extra: "
|
|
38
|
+
"pip install 'langgraph-api[inmem]'"
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
with tempfile.TemporaryDirectory(prefix="langgraph-core-") as temp_dir:
|
|
42
|
+
address_file = Path(temp_dir, "address")
|
|
43
|
+
env = os.environ.copy()
|
|
44
|
+
env.update(
|
|
45
|
+
DATABASE_URI="",
|
|
46
|
+
DISPATCH_MODE="single-process",
|
|
47
|
+
LANGGRAPH_STORE_BACKEND="grpc",
|
|
48
|
+
LSD_GRPC_SERVER_ADDRESS="127.0.0.1:0",
|
|
49
|
+
PPROF_ADDR="127.0.0.1:0",
|
|
50
|
+
)
|
|
51
|
+
# An empty DATABASE_URI falls back to POSTGRES_URI, which sqlite_only cores refuse.
|
|
52
|
+
env.pop("POSTGRES_URI", None)
|
|
53
|
+
env.pop("REDIS_URI", None)
|
|
54
|
+
env.pop("REDIS_URI_CUSTOM", None)
|
|
55
|
+
# Core exits when this pipe closes, so it never outlives this process.
|
|
56
|
+
args = [
|
|
57
|
+
binary_path(),
|
|
58
|
+
"-apply-db-schema",
|
|
59
|
+
"-exit-on-stdin-close",
|
|
60
|
+
"-address-file",
|
|
61
|
+
address_file,
|
|
62
|
+
]
|
|
63
|
+
if sqlite_path:
|
|
64
|
+
Path(sqlite_path).parent.mkdir(parents=True, exist_ok=True)
|
|
65
|
+
_warn_dropped_local_data(Path(sqlite_path).parent)
|
|
66
|
+
args += ["-sqlite-path", sqlite_path]
|
|
67
|
+
process = subprocess.Popen(
|
|
68
|
+
args,
|
|
69
|
+
env=env,
|
|
70
|
+
stdin=subprocess.PIPE,
|
|
71
|
+
)
|
|
72
|
+
try:
|
|
73
|
+
yield _wait_for_address(process, address_file)
|
|
74
|
+
finally:
|
|
75
|
+
if process.poll() is None:
|
|
76
|
+
process.terminate()
|
|
77
|
+
try:
|
|
78
|
+
process.wait(timeout=5)
|
|
79
|
+
except subprocess.TimeoutExpired:
|
|
80
|
+
process.kill()
|
|
81
|
+
process.wait()
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _warn_dropped_local_data(data_dir: Path) -> None:
|
|
85
|
+
dropped = sorted(
|
|
86
|
+
str(f) for pattern in DROPPED_LOCAL_DATA for f in data_dir.glob(pattern)
|
|
87
|
+
)
|
|
88
|
+
if dropped:
|
|
89
|
+
logger.warning(
|
|
90
|
+
"Ignoring local data from an older format that this version no longer "
|
|
91
|
+
"reads; threads and runs stored there won't appear: %s",
|
|
92
|
+
", ".join(dropped),
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _wait_for_address(
|
|
97
|
+
process: subprocess.Popen[bytes], address_file: Path, timeout: float = 30
|
|
98
|
+
) -> str:
|
|
99
|
+
deadline = time.monotonic() + timeout
|
|
100
|
+
while time.monotonic() < deadline:
|
|
101
|
+
if process.poll() is not None:
|
|
102
|
+
raise RuntimeError(
|
|
103
|
+
f"LangGraph API core exited with code {process.returncode}"
|
|
104
|
+
)
|
|
105
|
+
try:
|
|
106
|
+
if address := address_file.read_text().strip():
|
|
107
|
+
return address
|
|
108
|
+
except FileNotFoundError:
|
|
109
|
+
pass
|
|
110
|
+
time.sleep(0.05)
|
|
111
|
+
raise RuntimeError("Timed out waiting for LangGraph API core to start")
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
__all__ = ["ADDRESS_ENV", "SQLITE_PATH", "start"]
|
|
@@ -788,10 +788,25 @@ class ThreadRunManager:
|
|
|
788
788
|
sanitize_reserved_keys(params)
|
|
789
789
|
config = params.get("config") if _is_record(params.get("config")) else {}
|
|
790
790
|
|
|
791
|
-
#
|
|
792
|
-
# the
|
|
791
|
+
# The fork target arrives only via ``config.configurable.checkpoint_id``
|
|
792
|
+
# (the SDK folds its ergonomic ``forkFrom`` option into this field
|
|
793
|
+
# client-side, so there is a single way to provide it). Extract it
|
|
794
|
+
# here and map it onto the top-level ``checkpoint_id`` / ``checkpoint``
|
|
795
|
+
# fields of ``run_payload`` below: ``create_valid_run``, the shared
|
|
796
|
+
# run-creation path also used by the legacy REST run-create endpoints,
|
|
797
|
+
# reads the fork target from those fields (UUID-validating it and
|
|
798
|
+
# injecting it back into ``config.configurable``), so populating them is
|
|
799
|
+
# what makes the run replay from the requested checkpoint rather than
|
|
800
|
+
# the thread's latest state.
|
|
801
|
+
checkpoint_id = _checkpoint_id_from_run_start_config(params)
|
|
802
|
+
|
|
803
|
+
# Only a plain run.start needs the lookups below, which can wait seconds
|
|
804
|
+
# on a busy thread: ``input.respond`` checked its interrupts already and
|
|
805
|
+
# always resumes, and a fork starts a new run from its checkpoint
|
|
806
|
+
# whatever the thread's latest one waits on.
|
|
793
807
|
force_resume = params.get("force_resume")
|
|
794
|
-
|
|
808
|
+
infer_resume = not force_resume and checkpoint_id is None
|
|
809
|
+
current_run = await self._fetch_current_run() if infer_resume else None
|
|
795
810
|
|
|
796
811
|
current_status = None
|
|
797
812
|
if current_run is not None:
|
|
@@ -802,7 +817,7 @@ class ThreadRunManager:
|
|
|
802
817
|
)
|
|
803
818
|
|
|
804
819
|
has_interrupts = False
|
|
805
|
-
if params.get("input") is not None and
|
|
820
|
+
if params.get("input") is not None and infer_resume:
|
|
806
821
|
has_interrupts = await self._has_pending_interrupts()
|
|
807
822
|
if has_interrupts and not keyed_by_interrupt_id(params["input"]):
|
|
808
823
|
# One answer can't say which of several pending interrupts it is
|
|
@@ -831,18 +846,6 @@ class ThreadRunManager:
|
|
|
831
846
|
},
|
|
832
847
|
}
|
|
833
848
|
|
|
834
|
-
# The fork target arrives only via ``config.configurable.checkpoint_id``
|
|
835
|
-
# (the SDK folds its ergonomic ``forkFrom`` option into this field
|
|
836
|
-
# client-side, so there is a single way to provide it). Extract it
|
|
837
|
-
# here and map it onto the top-level ``checkpoint_id`` / ``checkpoint``
|
|
838
|
-
# fields of ``run_payload`` below: ``create_valid_run`` — the shared
|
|
839
|
-
# run-creation path also used by the legacy REST run-create endpoints —
|
|
840
|
-
# reads the fork target from those fields (UUID-validating it and
|
|
841
|
-
# injecting it back into ``config.configurable``), so populating them is
|
|
842
|
-
# what makes the run replay from the requested checkpoint rather than
|
|
843
|
-
# the thread's latest state.
|
|
844
|
-
checkpoint_id = _checkpoint_id_from_run_start_config(params)
|
|
845
|
-
|
|
846
849
|
run_payload: dict[str, Any] = {
|
|
847
850
|
"assistant_id": assistant_id,
|
|
848
851
|
"input": None if is_resume else params.get("input"),
|
langgraph_api/feature_flags.py
CHANGED
|
@@ -20,7 +20,13 @@ USE_DURABILITY = LANGGRAPH_PY_MINOR >= (0, 6)
|
|
|
20
20
|
_RUNTIME_EDITION = os.getenv("LANGGRAPH_RUNTIME_EDITION", "inmem")
|
|
21
21
|
IS_POSTGRES_BACKEND = _RUNTIME_EDITION == "postgres"
|
|
22
22
|
IS_INMEM_BACKEND = _RUNTIME_EDITION == "inmem"
|
|
23
|
-
|
|
23
|
+
# Opt-in: run the in-memory runtime on Go core with SQLite.
|
|
24
|
+
INMEM_USES_CORE = IS_INMEM_BACKEND and os.getenv("FF_INMEM_CORE", "false").lower() in (
|
|
25
|
+
"true",
|
|
26
|
+
"1",
|
|
27
|
+
"yes",
|
|
28
|
+
)
|
|
29
|
+
IS_POSTGRES_OR_GRPC_BACKEND = IS_POSTGRES_BACKEND or INMEM_USES_CORE
|
|
24
30
|
# Server-side kill switch for the Protocol v2 event-streaming surface
|
|
25
31
|
# (#3296). When false, the v2 routes are not registered (clients hit a
|
|
26
32
|
# 404), and ``_create_or_resume_run`` rejects any direct call with a
|
|
@@ -58,7 +64,7 @@ def _resolve_prefer_grpc_checkpointer(
|
|
|
58
64
|
|
|
59
65
|
|
|
60
66
|
# When true on the postgres runtime, use ``GrpcCheckpointer``.
|
|
61
|
-
# Inmem
|
|
67
|
+
# Inmem on Go core always uses it; Python inmem never does.
|
|
62
68
|
# Custom checkpointer (``backend=custom`` in ``LANGGRAPH_CHECKPOINTER``) and
|
|
63
69
|
# Mongo (``backend=mongo``) is also unaffected.
|
|
64
70
|
# langgraph < 0.5 keeps Send() packets in checkpoint["pending_sends"], which only
|
langgraph_api/grpc/client.py
CHANGED
|
@@ -380,6 +380,8 @@ class Threads(Authenticated):
|
|
|
380
380
|
exclude_metadata: list[dict[str, Any]] | None = None,
|
|
381
381
|
created_after: datetime | None = None,
|
|
382
382
|
created_before: datetime | None = None,
|
|
383
|
+
state_updated_after: datetime | None = None,
|
|
384
|
+
state_updated_before: datetime | None = None,
|
|
383
385
|
raw_values: bool = False,
|
|
384
386
|
ctx: Any = None,
|
|
385
387
|
) -> tuple[AsyncIterator[Thread], int | None]:
|
|
@@ -405,6 +407,8 @@ class Threads(Authenticated):
|
|
|
405
407
|
"values_json": json_dumpb_optional(values),
|
|
406
408
|
"created_after": created_after,
|
|
407
409
|
"created_before": created_before,
|
|
410
|
+
"state_updated_after": state_updated_after,
|
|
411
|
+
"state_updated_before": state_updated_before,
|
|
408
412
|
"limit": limit,
|
|
409
413
|
"offset": offset,
|
|
410
414
|
"sort_by": _map_threads_sort_by(sort_by),
|
|
@@ -462,6 +466,8 @@ class Threads(Authenticated):
|
|
|
462
466
|
exclude_metadata: list[dict[str, Any]] | None = None,
|
|
463
467
|
created_after: datetime | None = None,
|
|
464
468
|
created_before: datetime | None = None,
|
|
469
|
+
state_updated_after: datetime | None = None,
|
|
470
|
+
state_updated_before: datetime | None = None,
|
|
465
471
|
ctx: Any = None,
|
|
466
472
|
) -> int:
|
|
467
473
|
metadata = metadata or {}
|
|
@@ -483,6 +489,8 @@ class Threads(Authenticated):
|
|
|
483
489
|
"values_json": json_dumpb_optional(values),
|
|
484
490
|
"created_after": created_after,
|
|
485
491
|
"created_before": created_before,
|
|
492
|
+
"state_updated_after": state_updated_after,
|
|
493
|
+
"state_updated_before": state_updated_before,
|
|
486
494
|
}
|
|
487
495
|
if exclude_metadata:
|
|
488
496
|
request_kwargs["exclude_metadata_json"] = json_dumpb(exclude_metadata)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from collections.abc import AsyncIterator
|
|
2
|
+
from contextlib import asynccontextmanager
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class CoreApiConnectionProto:
|
|
7
|
+
"""No-op connection for operations persisted through Go core."""
|
|
8
|
+
|
|
9
|
+
@asynccontextmanager
|
|
10
|
+
async def pipeline(self):
|
|
11
|
+
yield None
|
|
12
|
+
|
|
13
|
+
@asynccontextmanager
|
|
14
|
+
async def transaction(self):
|
|
15
|
+
yield None
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@asynccontextmanager
|
|
19
|
+
async def connect(
|
|
20
|
+
*, supports_core_api: bool = True, __test__: bool = False
|
|
21
|
+
) -> AsyncIterator[Any]:
|
|
22
|
+
yield CoreApiConnectionProto()
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
async def start_pool() -> None:
|
|
26
|
+
pass
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
async def stop_pool() -> None:
|
|
30
|
+
pass
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
async def healthcheck(*, check_db: bool = True) -> None:
|
|
34
|
+
pass
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def pool_stats(*args: Any, **kwargs: Any) -> dict[str, dict[str, int]]:
|
|
38
|
+
return {}
|
|
@@ -9,7 +9,9 @@ from langchain_core.runnables.config import RunnableConfig, var_child_runnable_c
|
|
|
9
9
|
from langgraph.constants import CONF
|
|
10
10
|
from starlette.applications import Starlette
|
|
11
11
|
|
|
12
|
+
from langgraph_api import config, embedded_core
|
|
12
13
|
from langgraph_api.config import BG_JOB_SHUTDOWN_GRACE_PERIOD_SECS
|
|
14
|
+
from langgraph_api.feature_flags import INMEM_USES_CORE
|
|
13
15
|
from langgraph_api.runtime import queue
|
|
14
16
|
from langgraph_license.validation import (
|
|
15
17
|
check_license_periodically,
|
|
@@ -33,6 +35,54 @@ async def lifespan(
|
|
|
33
35
|
cancel_event: asyncio.Event | None = None,
|
|
34
36
|
with_cron_scheduler: bool = True,
|
|
35
37
|
taskset: set[asyncio.Task] | None = None,
|
|
38
|
+
):
|
|
39
|
+
async with (
|
|
40
|
+
_embedded_core(),
|
|
41
|
+
_lifespan(
|
|
42
|
+
app,
|
|
43
|
+
cancel_event=cancel_event,
|
|
44
|
+
with_cron_scheduler=with_cron_scheduler,
|
|
45
|
+
taskset=taskset,
|
|
46
|
+
),
|
|
47
|
+
):
|
|
48
|
+
yield
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@asynccontextmanager
|
|
52
|
+
async def _embedded_core():
|
|
53
|
+
"""Run Go core as a child process for the in-memory runtime.
|
|
54
|
+
|
|
55
|
+
LSD_GRPC_SERVER_ADDRESS is ignored: the in-memory runtime only talks to its
|
|
56
|
+
own SQLite core, never to an external one.
|
|
57
|
+
"""
|
|
58
|
+
if not INMEM_USES_CORE:
|
|
59
|
+
yield
|
|
60
|
+
return
|
|
61
|
+
if os.environ.get("LSD_GRPC_SERVER_ADDRESS"):
|
|
62
|
+
logger.warning(
|
|
63
|
+
"Ignoring LSD_GRPC_SERVER_ADDRESS: the in-memory runtime runs its own core"
|
|
64
|
+
)
|
|
65
|
+
if address := os.environ.get(embedded_core.ADDRESS_ENV):
|
|
66
|
+
config.LSD_GRPC_SERVER_ADDRESS = address
|
|
67
|
+
yield
|
|
68
|
+
return
|
|
69
|
+
|
|
70
|
+
persist = os.getenv("LANGGRAPH_DISABLE_FILE_PERSISTENCE", "false").lower() != "true"
|
|
71
|
+
core = embedded_core.start(embedded_core.SQLITE_PATH if persist else None)
|
|
72
|
+
config.LSD_GRPC_SERVER_ADDRESS = await asyncio.to_thread(core.__enter__)
|
|
73
|
+
try:
|
|
74
|
+
yield
|
|
75
|
+
finally:
|
|
76
|
+
await asyncio.to_thread(core.__exit__, None, None, None)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
@asynccontextmanager
|
|
80
|
+
async def _lifespan(
|
|
81
|
+
app: Starlette | None,
|
|
82
|
+
*,
|
|
83
|
+
cancel_event: asyncio.Event | None,
|
|
84
|
+
with_cron_scheduler: bool,
|
|
85
|
+
taskset: set[asyncio.Task] | None,
|
|
36
86
|
):
|
|
37
87
|
# Import at point of use to avoid circular dependencies
|
|
38
88
|
from langgraph_api import ( # noqa: PLC0415
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""Internal routes for the in-memory runtime on Go core."""
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
|
|
5
|
+
from langgraph_grpc_common.proto import core_api_pb2 as pb
|
|
6
|
+
from langgraph_runtime_inmem import routes as inmem_routes
|
|
7
|
+
|
|
8
|
+
from langgraph_api import config
|
|
9
|
+
from langgraph_api._checkpointer._adapter import CHECKPOINTER_STACK
|
|
10
|
+
from langgraph_api.grpc.client import get_shared_client
|
|
11
|
+
from langgraph_api.grpc.ops.threads import proto_to_thread
|
|
12
|
+
from langgraph_api.route import ApiRequest, ApiResponse, ApiRoute
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
async def truncate(request: ApiRequest):
|
|
16
|
+
"""Truncate all core data (for testing)."""
|
|
17
|
+
if config.USE_CUSTOM_CHECKPOINTER:
|
|
18
|
+
inner = getattr(CHECKPOINTER_STACK, "inner", None)
|
|
19
|
+
if inner is not None and hasattr(inner, "clear"):
|
|
20
|
+
await asyncio.to_thread(inner.clear)
|
|
21
|
+
|
|
22
|
+
client = await get_shared_client()
|
|
23
|
+
await client.admin.Truncate(
|
|
24
|
+
pb.TruncateRequest(
|
|
25
|
+
runs=True,
|
|
26
|
+
threads=True,
|
|
27
|
+
assistants=True,
|
|
28
|
+
checkpointer=True,
|
|
29
|
+
store=True,
|
|
30
|
+
)
|
|
31
|
+
)
|
|
32
|
+
return ApiResponse({"ok": True})
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
async def debug_get_raw_thread(request: ApiRequest):
|
|
36
|
+
"""Return raw thread from core without decryption (for testing)."""
|
|
37
|
+
client = await get_shared_client()
|
|
38
|
+
thread = await client.threads.Get(
|
|
39
|
+
pb.GetThreadRequest(thread_id=pb.UUID(value=request.path_params["thread_id"]))
|
|
40
|
+
)
|
|
41
|
+
return ApiResponse(proto_to_thread(thread))
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def get_internal_routes():
|
|
45
|
+
"""Deploy routes from the Python runtime, with internal routes backed by core."""
|
|
46
|
+
routes = inmem_routes.get_internal_routes()
|
|
47
|
+
if not routes:
|
|
48
|
+
return routes
|
|
49
|
+
return [r for r in routes if not r.path.startswith("/internal/")] + [
|
|
50
|
+
ApiRoute(
|
|
51
|
+
"/internal/debug/thread/{thread_id}",
|
|
52
|
+
debug_get_raw_thread,
|
|
53
|
+
methods=["GET"],
|
|
54
|
+
),
|
|
55
|
+
ApiRoute("/internal/truncate", truncate, methods=["POST"]),
|
|
56
|
+
]
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import threading
|
|
2
|
+
from typing import Any
|
|
3
|
+
|
|
4
|
+
from langgraph_grpc_common.store import GrpcStore
|
|
5
|
+
|
|
6
|
+
import langgraph_api.config as api_config
|
|
7
|
+
from langgraph_api.encryption.context import get_encryption_context
|
|
8
|
+
from langgraph_api.graph import resolve_embeddings
|
|
9
|
+
|
|
10
|
+
_STORE_CONFIG: api_config.StoreConfig = {}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def set_store_config(config: api_config.StoreConfig) -> None:
|
|
14
|
+
global _STORE_CONFIG
|
|
15
|
+
_STORE_CONFIG = config.copy()
|
|
16
|
+
if "index" not in _STORE_CONFIG or not _STORE_CONFIG["index"]:
|
|
17
|
+
return
|
|
18
|
+
_STORE_CONFIG["index"]["embed"] = resolve_embeddings(_STORE_CONFIG["index"])
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
_STORE = threading.local()
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def start_store() -> None:
|
|
25
|
+
_STORE.store = GrpcStore(
|
|
26
|
+
api_config.LSD_GRPC_SERVER_ADDRESS,
|
|
27
|
+
index=_STORE_CONFIG.get("index"),
|
|
28
|
+
ttl=_STORE_CONFIG.get("ttl"),
|
|
29
|
+
encryption_context_provider=get_encryption_context
|
|
30
|
+
if api_config.LANGGRAPH_ENCRYPTION
|
|
31
|
+
else None,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def get_store_config() -> api_config.StoreConfig:
|
|
36
|
+
return _STORE_CONFIG
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def Store(*args: Any, **kwargs: Any) -> GrpcStore:
|
|
40
|
+
if not hasattr(_STORE, "store"):
|
|
41
|
+
if not _STORE_CONFIG and api_config.STORE_CONFIG:
|
|
42
|
+
set_store_config(api_config.STORE_CONFIG)
|
|
43
|
+
start_store()
|
|
44
|
+
return _STORE.store
|
langgraph_api/store.py
CHANGED
|
@@ -19,7 +19,7 @@ from langgraph_api.encryption.middleware import (
|
|
|
19
19
|
encrypt_request,
|
|
20
20
|
)
|
|
21
21
|
from langgraph_api.encryption.shared import ENCRYPTION_CONTEXT_KEY
|
|
22
|
-
from langgraph_api.feature_flags import
|
|
22
|
+
from langgraph_api.feature_flags import IS_POSTGRES_OR_GRPC_BACKEND
|
|
23
23
|
from langgraph_api.timing import profiled_import
|
|
24
24
|
from langgraph_api.utils.config import run_in_executor
|
|
25
25
|
|
|
@@ -48,12 +48,12 @@ async def get_store() -> BaseStore:
|
|
|
48
48
|
# Go core encrypts the postgres built-in store, and custom stores own their data
|
|
49
49
|
# format and remain plaintext here; only the in-memory store is encrypted here.
|
|
50
50
|
def _bypass_store_encryption() -> bool:
|
|
51
|
-
return
|
|
51
|
+
return IS_POSTGRES_OR_GRPC_BACKEND or CUSTOM_STORE is not None
|
|
52
52
|
|
|
53
53
|
|
|
54
54
|
def _bypass_store_decryption(item: dict[str, Any]) -> bool:
|
|
55
55
|
if CUSTOM_STORE is None:
|
|
56
|
-
return
|
|
56
|
+
return IS_POSTGRES_OR_GRPC_BACKEND
|
|
57
57
|
value = item.get("value")
|
|
58
58
|
return not isinstance(value, dict) or ENCRYPTION_CONTEXT_KEY not in value
|
|
59
59
|
|
langgraph_api/stream.py
CHANGED
|
@@ -914,6 +914,8 @@ async def consume(
|
|
|
914
914
|
stream_modes.add("messages")
|
|
915
915
|
stream_modes.add("metadata")
|
|
916
916
|
stream_modes.add("control")
|
|
917
|
+
# No run stream carries it, but a resumed thread stream replays it.
|
|
918
|
+
stream_modes.add("interrupts")
|
|
917
919
|
|
|
918
920
|
if FF_ASYNC_PUBLISH_QUEUE:
|
|
919
921
|
await _consume_async_queue(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: langgraph-api
|
|
3
|
-
Version: 0.19.0.
|
|
3
|
+
Version: 0.19.0.dev9
|
|
4
4
|
Author-email: Will Fu-Hinthorn <will@langchain.dev>, Josh Rogers <josh@langchain.dev>, Parker Rule <parker@langchain.dev>
|
|
5
5
|
License: Elastic-2.0
|
|
6
6
|
License-File: LICENSE
|
|
@@ -42,6 +42,10 @@ Requires-Dist: uvloop>=0.18.0; platform_system != 'Windows'
|
|
|
42
42
|
Requires-Dist: watchfiles>=0.13
|
|
43
43
|
Requires-Dist: websockets>=13.0
|
|
44
44
|
Requires-Dist: zstandard>=0.23.0
|
|
45
|
+
Provides-Extra: inmem
|
|
46
|
+
Requires-Dist: blockbuster<2.0.0,>=1.5.24; extra == 'inmem'
|
|
47
|
+
Requires-Dist: langgraph-api-core-bin<0.20.0.dev0,>=0.19.0.dev0; extra == 'inmem'
|
|
48
|
+
Requires-Dist: langgraph>=0.5; extra == 'inmem'
|
|
45
49
|
Description-Content-Type: text/markdown
|
|
46
50
|
|
|
47
51
|
# LangGraph API
|