langgraph-executor 0.0.1a2__py3-none-any.whl → 0.0.1a4__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_executor/__init__.py +1 -1
- langgraph_executor/executor_base.py +43 -5
- {langgraph_executor-0.0.1a2.dist-info → langgraph_executor-0.0.1a4.dist-info}/METADATA +1 -1
- {langgraph_executor-0.0.1a2.dist-info → langgraph_executor-0.0.1a4.dist-info}/RECORD +5 -5
- {langgraph_executor-0.0.1a2.dist-info → langgraph_executor-0.0.1a4.dist-info}/WHEEL +0 -0
langgraph_executor/__init__.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "0.0.
|
1
|
+
__version__ = "0.0.1a4"
|
@@ -3,7 +3,14 @@ import contextlib
|
|
3
3
|
import functools
|
4
4
|
import logging
|
5
5
|
import uuid
|
6
|
-
from collections.abc import
|
6
|
+
from collections.abc import (
|
7
|
+
AsyncIterator,
|
8
|
+
Awaitable,
|
9
|
+
Callable,
|
10
|
+
Collection,
|
11
|
+
Iterator,
|
12
|
+
Sequence,
|
13
|
+
)
|
7
14
|
from typing import Any, Protocol, cast
|
8
15
|
|
9
16
|
import grpc
|
@@ -17,6 +24,7 @@ from langgraph.pregel import Pregel
|
|
17
24
|
from langgraph.pregel._algo import apply_writes
|
18
25
|
from langgraph.pregel._checkpoint import channels_from_checkpoint
|
19
26
|
from langgraph.pregel._retry import arun_with_retry
|
27
|
+
from langgraph.store.base import BaseStore
|
20
28
|
from langgraph.types import PregelExecutableTask
|
21
29
|
|
22
30
|
from langgraph_executor.common import (
|
@@ -65,6 +73,16 @@ class LangGraphExecutorServicer(executor_pb2_grpc.LangGraphExecutorServicer):
|
|
65
73
|
subgraph_map: dict[str, str],
|
66
74
|
get_graph: GetGraph,
|
67
75
|
logger: Logger | None = None,
|
76
|
+
on_message: Callable[
|
77
|
+
[
|
78
|
+
BaseMessageChunk,
|
79
|
+
dict[str, Any],
|
80
|
+
],
|
81
|
+
None,
|
82
|
+
]
|
83
|
+
| None = None,
|
84
|
+
on_custom: Callable[[Any], None] | None = None,
|
85
|
+
get_store: Callable[[], Awaitable[BaseStore]] | None = None,
|
68
86
|
):
|
69
87
|
"""Initialize the servicer with compiled graphs.
|
70
88
|
|
@@ -82,6 +100,9 @@ class LangGraphExecutorServicer(executor_pb2_grpc.LangGraphExecutorServicer):
|
|
82
100
|
self.get_graph = get_graph
|
83
101
|
_patch_base_message_with_ids()
|
84
102
|
self._graph_definition_cache: dict[str, executor_pb2.GetGraphResponse] = {}
|
103
|
+
self.on_message = on_message
|
104
|
+
self.on_custom = on_custom
|
105
|
+
self.get_store = get_store
|
85
106
|
|
86
107
|
async def ListGraphs(
|
87
108
|
self, request: Any, context: grpc.aio.ServicerContext
|
@@ -174,6 +195,7 @@ class LangGraphExecutorServicer(executor_pb2_grpc.LangGraphExecutorServicer):
|
|
174
195
|
try:
|
175
196
|
request = await _get_init_request(request_iterator)
|
176
197
|
config = reconstruct_config(request.task.config)
|
198
|
+
store = await self.get_store() if self.get_store is not None else None
|
177
199
|
async with self.get_graph(request.graph_name, config) as graph:
|
178
200
|
stream_messages = "messages" in request.stream_modes
|
179
201
|
stream_custom = "custom" in request.stream_modes
|
@@ -181,13 +203,18 @@ class LangGraphExecutorServicer(executor_pb2_grpc.LangGraphExecutorServicer):
|
|
181
203
|
stream_queue = asyncio.Queue()
|
182
204
|
|
183
205
|
custom_stream_writer = (
|
184
|
-
_create_custom_stream_writer(
|
206
|
+
_create_custom_stream_writer(
|
207
|
+
stream_queue, self.logger, on_custom=self.on_custom
|
208
|
+
)
|
185
209
|
if stream_custom
|
186
210
|
else None
|
187
211
|
)
|
188
212
|
|
189
213
|
task = reconstruct_task(
|
190
|
-
request,
|
214
|
+
request,
|
215
|
+
graph,
|
216
|
+
custom_stream_writer=custom_stream_writer,
|
217
|
+
store=store,
|
191
218
|
)
|
192
219
|
if stream_messages:
|
193
220
|
# Create and inject callback handler
|
@@ -196,6 +223,7 @@ class LangGraphExecutorServicer(executor_pb2_grpc.LangGraphExecutorServicer):
|
|
196
223
|
stream_callback,
|
197
224
|
logger=self.logger,
|
198
225
|
stream_queue=stream_queue,
|
226
|
+
on_message=self.on_message,
|
199
227
|
),
|
200
228
|
task.id,
|
201
229
|
)
|
@@ -362,13 +390,16 @@ async def _run_task(
|
|
362
390
|
|
363
391
|
def stream_callback(
|
364
392
|
message: BaseMessageChunk,
|
365
|
-
metadata: dict,
|
393
|
+
metadata: dict[str, Any],
|
366
394
|
*,
|
367
395
|
logger: Logger,
|
368
396
|
stream_queue: asyncio.Queue[executor_pb2.ExecuteTaskResponse],
|
397
|
+
on_message: Callable[[BaseMessageChunk, dict[str, Any]], None] | None = None,
|
369
398
|
):
|
370
399
|
"""Callback to capture stream chunks and queue them."""
|
371
400
|
try:
|
401
|
+
if on_message is not None:
|
402
|
+
on_message(message, metadata)
|
372
403
|
stream_queue.put_nowait(
|
373
404
|
executor_pb2.ExecuteTaskResponse(
|
374
405
|
message_or_message_chunk=_extract_output_message(message)
|
@@ -378,12 +409,19 @@ def stream_callback(
|
|
378
409
|
logger.warning(f"Failed to create stream chunk: {e}", exc_info=True)
|
379
410
|
|
380
411
|
|
381
|
-
def _create_custom_stream_writer(
|
412
|
+
def _create_custom_stream_writer(
|
413
|
+
stream_queue: asyncio.Queue[Any],
|
414
|
+
logger: Logger,
|
415
|
+
*,
|
416
|
+
on_custom: Callable[[Any], None] | None = None,
|
417
|
+
):
|
382
418
|
"""Create a proper stream_writer function for custom mode (like langgraph does)."""
|
383
419
|
|
384
420
|
def stream_writer(content):
|
385
421
|
"""Custom stream writer that creates CustomStreamEvent messages."""
|
386
422
|
try:
|
423
|
+
if on_custom is not None:
|
424
|
+
on_custom(content)
|
387
425
|
# Create payload struct (like langgraph does)
|
388
426
|
payload = Struct()
|
389
427
|
if isinstance(content, str):
|
@@ -1,9 +1,9 @@
|
|
1
|
-
langgraph_executor/__init__.py,sha256=
|
1
|
+
langgraph_executor/__init__.py,sha256=uM_3HhsbqJiR7MV8Zx7ur-gqgdixAWQv-HmjMR8c9vY,24
|
2
2
|
langgraph_executor/common.py,sha256=w75Bqbrj5LOtiWoOOdIi45yVB05xYXDAnokwg7MgDQE,13688
|
3
3
|
langgraph_executor/example.py,sha256=TcfxgC9VfpZFliWnuVdJMllCDa8ji7vrSCRWnmdsUA8,900
|
4
4
|
langgraph_executor/execute_task.py,sha256=_m-WyVODhShI29qzkK0DXSPoTY4E_izbuaT7F_fVZVw,7262
|
5
5
|
langgraph_executor/executor.py,sha256=oUg6q8WWjAIwuh2ik76IbCPMKfmegT5ePZsWFnvR4WE,5296
|
6
|
-
langgraph_executor/executor_base.py,sha256=
|
6
|
+
langgraph_executor/executor_base.py,sha256=CP2C59PWi90NA3949rvaB7GPPMwSMh4pfLqY9Vb51JE,19597
|
7
7
|
langgraph_executor/extract_graph.py,sha256=f7NNeZigRQlTAYg_-mV8eBgQ9q8kuThCDwLjRO6wReQ,6365
|
8
8
|
langgraph_executor/info_logger.py,sha256=kgoVnMxm_aloHal89NHfH_Qb9eixrqD0dHmgnrm_vL4,3110
|
9
9
|
langgraph_executor/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -27,6 +27,6 @@ langgraph_executor/pb/types_pb2.py,sha256=rUboWBthlLM-iJOmZZta-HSekwTNFuXfWLaYHe
|
|
27
27
|
langgraph_executor/pb/types_pb2.pyi,sha256=tBX4LzmfWZ-IYscIeAEBTDC02GWWKEAQVB2JPNHChDc,40957
|
28
28
|
langgraph_executor/pb/types_pb2_grpc.py,sha256=EPv87wCc-6BNJ2xTNcb9d3ictDerK5cBt7qhd7EmJiQ,886
|
29
29
|
langgraph_executor/pb/types_pb2_grpc.pyi,sha256=Dl8kkjhqb6F1Kt24mcFg7ppish4iKVfjRiiBxEjsMMA,413
|
30
|
-
langgraph_executor-0.0.
|
31
|
-
langgraph_executor-0.0.
|
32
|
-
langgraph_executor-0.0.
|
30
|
+
langgraph_executor-0.0.1a4.dist-info/METADATA,sha256=5Ng1JslMYube7c36AvUoXtoWVj5iBeUbv0g7qdTuddY,433
|
31
|
+
langgraph_executor-0.0.1a4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
32
|
+
langgraph_executor-0.0.1a4.dist-info/RECORD,,
|
File without changes
|