3tears-langgraph 0.14.0__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.
@@ -0,0 +1,118 @@
1
+ Metadata-Version: 2.4
2
+ Name: 3tears-langgraph
3
+ Version: 0.14.0
4
+ Summary: Three-tier LangGraph checkpoint saver: L1 SQLite -> L2 NATS KV -> L3 PostgreSQL
5
+ Project-URL: Repository, https://github.com/pacepace/3tears
6
+ Author: pace
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Framework :: AsyncIO
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.14
14
+ Classifier: Topic :: Database
15
+ Classifier: Topic :: Software Development :: Libraries
16
+ Classifier: Typing :: Typed
17
+ Requires-Python: >=3.14
18
+ Requires-Dist: 3tears
19
+ Requires-Dist: 3tears-media-contracts
20
+ Requires-Dist: 3tears-observe
21
+ Requires-Dist: asyncpg
22
+ Requires-Dist: langchain-core>=1.0
23
+ Requires-Dist: langchain>=1.0
24
+ Requires-Dist: langgraph-checkpoint>=4.0
25
+ Requires-Dist: langgraph>=1.0
26
+ Requires-Dist: uuid-utils
27
+ Description-Content-Type: text/markdown
28
+
29
+ # 3tears-langgraph
30
+
31
+ Three-tier LangGraph checkpoint saver: L1 (SQLite) -> L2 (NATS KV) -> L3 (PostgreSQL).
32
+
33
+ L1 and L2 are optional cache layers that degrade gracefully on failure. L3 (PostgreSQL) is the source of truth, reached through the `AsyncQueryExecutor` protocol so the same saver serves trusted services (direct asyncpg pool) and sandboxed agents (NATS L3 proxy).
34
+
35
+ ## Installation
36
+
37
+ ```bash
38
+ pip install 3tears-langgraph
39
+ ```
40
+
41
+ ## Usage
42
+
43
+ ```python
44
+ from threetears.langgraph import (
45
+ AsyncpgPoolAdapter,
46
+ ThreeTierCheckpointSaver,
47
+ )
48
+
49
+ # Trusted service with direct asyncpg.Pool: wrap once
50
+ saver = ThreeTierCheckpointSaver(executor=AsyncpgPoolAdapter(pool))
51
+
52
+ # Sandboxed agent: NatsProxyL3Backend already implements
53
+ # AsyncQueryExecutor, pass it straight through
54
+ saver = ThreeTierCheckpointSaver(executor=nats_l3_backend)
55
+
56
+ graph = builder.compile(checkpointer=saver)
57
+ ```
58
+
59
+ ## Middleware
60
+
61
+ The package ships platform-level [`AgentMiddleware`](https://docs.langchain.com/oss/python/langchain/middleware) for `langchain.agents.create_agent` — the framework-aligned successor to the old hand-rolled `AgentNodeHook` / `ToolNodeHook` protocols. Consumer-specific policy lives in each consumer as its own middleware; only the reusable platform seams live here:
62
+
63
+ - `PromptCachingMiddleware` (`wrap_model_call`) — annotates a leading bare-string system message with Anthropic `cache_control={"type": "ephemeral"}` when the model supports it, then normalizes cache-hit/creation counters onto `usage_metadata["cache_usage"]`. Non-Anthropic adapters degrade silently to bare-string system messages.
64
+ - `ToolResultOffloadMiddleware` (`wrap_tool_call`) — when a `ToolResultOffloader` is injected on `config["configurable"]` and a tool result exceeds `offload_threshold_chars`, stores the full content out-of-band and shows the model `"<summary>\n\n[ctx:<handle>]"` (the structured `artifact` is preserved). Opt-in: no offloader ⇒ byte-for-byte no-op.
65
+ - `ObjectCatalogMiddleware` (`wrap_tool_call`) — when a tool returns an `ObjectHandle` in its result artifact and an `ObjectCataloger` is injected, persists a catalog record under the verified call identity. Soft-fail side-effect: a catalog error never breaks the tool result.
66
+
67
+ ```python
68
+ from langchain.agents import create_agent
69
+
70
+ from threetears.langgraph import (
71
+ ObjectCatalogMiddleware,
72
+ PromptCachingMiddleware,
73
+ ToolResultOffloadMiddleware,
74
+ )
75
+
76
+ agent = create_agent(
77
+ model=chat_anthropic,
78
+ tools=tools,
79
+ middleware=[
80
+ PromptCachingMiddleware(),
81
+ ToolResultOffloadMiddleware(),
82
+ ObjectCatalogMiddleware(),
83
+ ],
84
+ )
85
+ # after a run, PromptCachingMiddleware has stamped:
86
+ # message.usage_metadata["cache_usage"]
87
+ # == {"cache_read_input_tokens": ..., "cache_creation_input_tokens": ..., "cached_tokens": ...}
88
+ ```
89
+
90
+ The offload / catalog contracts (`ToolResultOffloader`, `ObjectCataloger`) are pure structural `Protocol`s exported from `threetears.langgraph.offload` / `threetears.langgraph.catalog`; a consumer injects a concrete implementation on `config["configurable"]` (e.g. `tool_result_offloader`, `object_cataloger`) without the package taking any dependency on the consumer's context store.
91
+
92
+ See [`3tears/docs/prompt-caching.md`](../../docs/prompt-caching.md) for the full caching contract, summarization interaction, downstream wiring checklist, and a worked example.
93
+
94
+ ## Streaming
95
+
96
+ The package ships `StreamingResponse`, a transport-agnostic primitive that owns the lifecycle of one streaming response: `start` -> any number of `emit_token` / `emit_tool_call_*` -> mutually-exclusive `end` (success) or `error` (failure) terminal. `run_graph(compiled_graph, state, config)` consumes a LangGraph `astream_events(version="v2")` loop with the start/end ordering managed; on graph exception it fires `error(code="AGENT_FAILED", ...)` and re-raises so the caller still sees the failure on the synchronous path.
97
+
98
+ The wire vocabulary is fixed: `StreamStartEvent` / `StreamTokenEvent` / `StreamEndEvent` / `StreamErrorEvent` / `ToolCallStartEvent` / `ToolCallEndEvent` / `ToolCallProgressEvent`, dispatched via the `StreamEvent` discriminated union and the `parse_stream_event(payload)` adapter. The transport seam is the `StreamTransport` Protocol -- one method, `async def publish(self, payload: bytes) -> None`. Any wire (NATS subject, websocket, chunked HTTP body) satisfies it.
99
+
100
+ ```python
101
+ from threetears.langgraph import StreamingResponse, StreamTransport
102
+
103
+ class WebSocketStreamTransport:
104
+ """example transport for a websocket consumer."""
105
+ def __init__(self, ws): self._ws = ws
106
+ async def publish(self, payload: bytes) -> None:
107
+ await self._ws.send_bytes(payload)
108
+
109
+ stream = StreamingResponse(
110
+ transport=WebSocketStreamTransport(ws),
111
+ correlation_id=correlation_id,
112
+ conversation_id=conversation_id,
113
+ start_time_monotonic=request_start,
114
+ )
115
+ final_state = await stream.run_graph(compiled_graph, state, config)
116
+ ```
117
+
118
+ A reference adapter can bind the primitive to a per-correlation-id stream subject via `nc.publish_raw`. Tool-call observation envelopes flow through `ToolCallProgressHook` reading the active `StreamingResponse` from `config["configurable"]["streaming_response"]`.
@@ -0,0 +1,25 @@
1
+ threetears/langgraph/__init__.py,sha256=fHsrCf28JEek6hLTOOjZdxudtKNUBYYGBIbtDeg4YXM,4831
2
+ threetears/langgraph/caching.py,sha256=q0IIVpnBCHlAROKGde7t_HVIAbVapC_y4rUSvh3hW3g,22226
3
+ threetears/langgraph/catalog.py,sha256=9OxCrabb4142QRVnHljAquMn2QK3b1t2gK0DpsHC0js,2595
4
+ threetears/langgraph/checkpoint.py,sha256=HxcsD26p8aDxB4ryOOR2TaEV6YHcFQhBd2r7MmFhwsE,32174
5
+ threetears/langgraph/events.py,sha256=l5t_D2YPYpYhWdrGMwcCZlpdyMRdv4er5RFYcRrk-CA,21689
6
+ threetears/langgraph/middleware.py,sha256=sALqs8ksg687JfkI5AydUdQqqQmUkyUb2V5W5pB5vR8,6914
7
+ threetears/langgraph/middleware_catalog.py,sha256=4nRduROwpJjcx-oIz7KbL-Md2Hjd3qeIME7bpphAytI,9034
8
+ threetears/langgraph/middleware_context.py,sha256=bWHsNgFn0WkMb3uy0wmm2x3E1U6y0x2R4Wwp00sVGdw,8276
9
+ threetears/langgraph/middleware_offload.py,sha256=yGTPZkN0chQAH61oojr4pnDrEjiOZ1bpFC0egyKdX_M,10982
10
+ threetears/langgraph/middleware_schema.py,sha256=6RgHZlOPc4vgibRL0XOj5HX8gbgAgPlRN0jclq2OWnc,22040
11
+ threetears/langgraph/middleware_summarize.py,sha256=AQHMs0_bgo19Rx3DF_MJUBBa8hM3iO50m-qm78KKQ_0,8719
12
+ threetears/langgraph/offload.py,sha256=ozG6yyz7Nx7l03ZGWec62yjWf6Y8o6tFrWT8q4jFKVE,8448
13
+ threetears/langgraph/protocols.py,sha256=frQi7bnYCMfuVYf3euKYUWHaY7xTPkqFTSZyHjjxcyI,6409
14
+ threetears/langgraph/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
+ threetears/langgraph/serde.py,sha256=zPI7N8PE93H4iZm476dfaDjURpN12o3WFaPBjkLIAVk,3033
16
+ threetears/langgraph/state.py,sha256=HWrzFTT3kZBWsE9xGqm4eQF8PSIRhJ-fGA6mADYDdUs,2175
17
+ threetears/langgraph/streaming.py,sha256=xzBTw8V-vHSi1PLDUjbh7QNcF_YAWq9gDSXF5s7SWM8,45559
18
+ threetears/langgraph/summarize.py,sha256=zrAAc3sMQhdta6hiGcE_jA31w-AfhY4rVQapMWgiako,6430
19
+ threetears/langgraph/util.py,sha256=V7dwclg8H73FdR7udMxN3gd2Z6Aw0tLOCx5J9zyVnyM,1350
20
+ threetears/langgraph/migrations/__init__.py,sha256=09yU3eQBTLE2RdukRedcpzb5076WgqzjZT3AdsS1fUQ,1434
21
+ threetears/langgraph/migrations/v001_create_checkpoint_tables.py,sha256=6mdYRRYkeivLS1xOMizd4V-5wqsnFs3zDQNIQ5UdqiM,2079
22
+ 3tears_langgraph-0.14.0.dist-info/METADATA,sha256=VGFMkg9bFktDfALGpKhFvw3IpwvMuuqXCRl3SMjappo,6146
23
+ 3tears_langgraph-0.14.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
24
+ 3tears_langgraph-0.14.0.dist-info/licenses/LICENSE,sha256=7GWEoEOcFJenZLt4LDzqH2K7QLxo_2m8rzG7Vv8VGXo,1066
25
+ 3tears_langgraph-0.14.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.30.1
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mark Pace
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,158 @@
1
+ """3tears-langgraph: LangGraph integration with three-tier persistence.
2
+
3
+ provides checkpoint savers, graph builders, and context management
4
+ for building LangGraph agents backed by 3tears infrastructure.
5
+ """
6
+
7
+ # Version derived from pyproject.toml so the metadata is the single
8
+ # source of truth -- a future release that bumps pyproject without
9
+ # updating ``__init__.py`` can't drift the runtime ``__version__``.
10
+ # The except guard handles the rare case where the package isn't
11
+ # installed via importlib.metadata (e.g. running directly from a
12
+ # checked-out source tree without ``uv sync``); the fallback keeps
13
+ # imports working but reports ``unknown`` rather than crashing.
14
+ from importlib.metadata import PackageNotFoundError as _PackageNotFoundError
15
+ from importlib.metadata import version as _version
16
+
17
+ try:
18
+ __version__ = _version("3tears-langgraph")
19
+ except _PackageNotFoundError: # pragma: no cover - dev fallback
20
+ __version__ = "unknown"
21
+
22
+ from threetears.langgraph.caching import (
23
+ ChatModelCapabilities,
24
+ annotate_system_prompt,
25
+ compute_tool_key,
26
+ detect_capabilities,
27
+ extract_cache_usage,
28
+ should_bind_tools_fresh,
29
+ )
30
+ from threetears.langgraph.catalog import ObjectCataloger
31
+ from threetears.langgraph.checkpoint import ThreeTierCheckpointSaver
32
+ from threetears.langgraph.events import (
33
+ FrameworkEvent,
34
+ FrameworkEventRegistry,
35
+ ImageGeneratedEvent,
36
+ PromptBuiltEvent,
37
+ ReasoningStreamedEvent,
38
+ ResponseCompletedEvent,
39
+ ResponseFailedEvent,
40
+ ToolCompletedEvent,
41
+ ToolDispatchedEvent,
42
+ ToolStartedEvent,
43
+ WorkflowCompletedEvent,
44
+ WorkflowStartedEvent,
45
+ WorkflowStepCompletedEvent,
46
+ default_registry,
47
+ dispatch_event,
48
+ )
49
+ from threetears.langgraph.middleware import PromptCachingMiddleware
50
+ from threetears.langgraph.middleware_catalog import ObjectCatalogMiddleware
51
+ from threetears.langgraph.middleware_context import (
52
+ ContextMergeMiddleware,
53
+ ConversationContextProvider,
54
+ )
55
+ from threetears.langgraph.middleware_offload import ToolResultOffloadMiddleware
56
+ from threetears.langgraph.middleware_schema import SchemaPrimingMiddleware
57
+ from threetears.langgraph.middleware_summarize import SummarizationMiddleware
58
+ from threetears.langgraph.offload import (
59
+ DEFAULT_OFFLOAD_THRESHOLD_CHARS,
60
+ NEVER_OFFLOAD_TOOLS,
61
+ OffloadResult,
62
+ ToolResultOffloader,
63
+ format_offload_handle,
64
+ has_offload_handle,
65
+ is_never_offload_tool,
66
+ )
67
+ from threetears.langgraph.protocols import (
68
+ AsyncpgPoolAdapter,
69
+ AsyncQueryExecutor,
70
+ CheckpointL1Cache,
71
+ CheckpointL2Cache,
72
+ FlushCallback,
73
+ )
74
+ from threetears.langgraph.serde import UUIDSafeSerializer
75
+ from threetears.langgraph.state import merge_metadata
76
+ from threetears.langgraph.streaming import (
77
+ NOSTREAM_TAG,
78
+ StreamEndEvent,
79
+ StreamErrorEvent,
80
+ StreamEvent,
81
+ StreamingResponse,
82
+ StreamingResponseError,
83
+ StreamStartEvent,
84
+ StreamTokenEvent,
85
+ StreamTransport,
86
+ ToolCallEndEvent,
87
+ ToolCallProgressEvent,
88
+ ToolCallStartEvent,
89
+ parse_stream_event,
90
+ )
91
+ from threetears.langgraph.summarize import (
92
+ DEFAULT_SUMMARIZATION_PROMPT,
93
+ summarize_older_messages,
94
+ )
95
+ from threetears.langgraph.util import summarize_args
96
+
97
+ __all__ = [
98
+ "DEFAULT_OFFLOAD_THRESHOLD_CHARS",
99
+ "DEFAULT_SUMMARIZATION_PROMPT",
100
+ "NOSTREAM_TAG",
101
+ "AsyncQueryExecutor",
102
+ "AsyncpgPoolAdapter",
103
+ "ChatModelCapabilities",
104
+ "CheckpointL1Cache",
105
+ "CheckpointL2Cache",
106
+ "ContextMergeMiddleware",
107
+ "ConversationContextProvider",
108
+ "FlushCallback",
109
+ "FrameworkEvent",
110
+ "FrameworkEventRegistry",
111
+ "ImageGeneratedEvent",
112
+ "NEVER_OFFLOAD_TOOLS",
113
+ "ObjectCataloger",
114
+ "ObjectCatalogMiddleware",
115
+ "OffloadResult",
116
+ "PromptBuiltEvent",
117
+ "PromptCachingMiddleware",
118
+ "ReasoningStreamedEvent",
119
+ "ResponseCompletedEvent",
120
+ "ResponseFailedEvent",
121
+ "SchemaPrimingMiddleware",
122
+ "StreamEndEvent",
123
+ "StreamErrorEvent",
124
+ "StreamEvent",
125
+ "StreamStartEvent",
126
+ "StreamTokenEvent",
127
+ "StreamTransport",
128
+ "StreamingResponse",
129
+ "StreamingResponseError",
130
+ "SummarizationMiddleware",
131
+ "ThreeTierCheckpointSaver",
132
+ "ToolCallEndEvent",
133
+ "ToolCallProgressEvent",
134
+ "ToolCallStartEvent",
135
+ "ToolCompletedEvent",
136
+ "ToolDispatchedEvent",
137
+ "ToolResultOffloadMiddleware",
138
+ "ToolResultOffloader",
139
+ "ToolStartedEvent",
140
+ "UUIDSafeSerializer",
141
+ "WorkflowCompletedEvent",
142
+ "WorkflowStartedEvent",
143
+ "WorkflowStepCompletedEvent",
144
+ "annotate_system_prompt",
145
+ "compute_tool_key",
146
+ "default_registry",
147
+ "detect_capabilities",
148
+ "dispatch_event",
149
+ "extract_cache_usage",
150
+ "format_offload_handle",
151
+ "has_offload_handle",
152
+ "is_never_offload_tool",
153
+ "merge_metadata",
154
+ "parse_stream_event",
155
+ "should_bind_tools_fresh",
156
+ "summarize_args",
157
+ "summarize_older_messages",
158
+ ]