harness-sdk-python 0.22.0__py3-none-any.whl → 0.23.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.
- harness_sdk/__init__.py +2 -0
- harness_sdk/checkpoints.py +64 -0
- {harness_sdk_python-0.22.0.dist-info → harness_sdk_python-0.23.0.dist-info}/METADATA +1 -1
- harness_sdk_python-0.23.0.dist-info/RECORD +8 -0
- harness_sdk_python-0.22.0.dist-info/RECORD +0 -8
- {harness_sdk_python-0.22.0.dist-info → harness_sdk_python-0.23.0.dist-info}/WHEEL +0 -0
harness_sdk/__init__.py
CHANGED
|
@@ -8,6 +8,7 @@ from .checkpoints import (
|
|
|
8
8
|
Snapshot,
|
|
9
9
|
checkpoint_thread,
|
|
10
10
|
langgraph_checkpoints,
|
|
11
|
+
langgraph_switch_values,
|
|
11
12
|
)
|
|
12
13
|
from .linear_thread import linear_thread
|
|
13
14
|
from .run_manager import RunManager, RunManagerDescriptor, run_manager
|
|
@@ -24,6 +25,7 @@ __all__ = [
|
|
|
24
25
|
"Snapshot",
|
|
25
26
|
"checkpoint_thread",
|
|
26
27
|
"langgraph_checkpoints",
|
|
28
|
+
"langgraph_switch_values",
|
|
27
29
|
"linear_thread",
|
|
28
30
|
"run_manager",
|
|
29
31
|
]
|
harness_sdk/checkpoints.py
CHANGED
|
@@ -312,6 +312,26 @@ def langgraph_checkpoints(
|
|
|
312
312
|
return _Store()
|
|
313
313
|
|
|
314
314
|
|
|
315
|
+
def langgraph_switch_values(
|
|
316
|
+
transcript: list[dict[str, Any]],
|
|
317
|
+
lineage: dict[str, Any],
|
|
318
|
+
*,
|
|
319
|
+
messages_key: str = "messages",
|
|
320
|
+
lineage_key: str = "lineage",
|
|
321
|
+
) -> dict[str, Any]:
|
|
322
|
+
"""``update_state`` channel values that replace the messages channel with ``transcript`` and set ``lineage``."""
|
|
323
|
+
from langchain_core.messages import RemoveMessage, convert_to_messages
|
|
324
|
+
from langgraph.graph.message import REMOVE_ALL_MESSAGES
|
|
325
|
+
|
|
326
|
+
return {
|
|
327
|
+
messages_key: [
|
|
328
|
+
RemoveMessage(id=REMOVE_ALL_MESSAGES),
|
|
329
|
+
*convert_to_messages([_message_dict(m) for m in transcript]),
|
|
330
|
+
],
|
|
331
|
+
lineage_key: lineage,
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
|
|
315
335
|
@dataclass
|
|
316
336
|
class CheckpointThread:
|
|
317
337
|
"""One thread's current window over the store, with the sidecar index kept in step."""
|
|
@@ -351,6 +371,25 @@ class CheckpointThread:
|
|
|
351
371
|
if entry["fork_message_id"] == parent_id
|
|
352
372
|
]
|
|
353
373
|
|
|
374
|
+
def _branch_at(self, index: int) -> int:
|
|
375
|
+
branch = 0
|
|
376
|
+
for b in self._path:
|
|
377
|
+
fork_id = self.branches[b - 1]["fork_message_id"] if b != 0 else None
|
|
378
|
+
start = next(
|
|
379
|
+
(i + 1 for i, m in enumerate(self.transcript) if m["id"] == fork_id), 0
|
|
380
|
+
)
|
|
381
|
+
if start <= index:
|
|
382
|
+
branch = b
|
|
383
|
+
return branch
|
|
384
|
+
|
|
385
|
+
def sibling_info(self, message_id: str) -> tuple[int, int]:
|
|
386
|
+
"""1-based (position, count) of ``message_id`` within its sibling fan-out."""
|
|
387
|
+
entries = self.sibling_branches(message_id)
|
|
388
|
+
index = next(i for i, m in enumerate(self.transcript) if m["id"] == message_id)
|
|
389
|
+
branch = self._branch_at(index)
|
|
390
|
+
group = sorted({e["branch_id"] for e in entries} | {branch})
|
|
391
|
+
return group.index(branch) + 1, len(group)
|
|
392
|
+
|
|
354
393
|
async def plan(self, trigger: str, *, rollback_to: str | None = None) -> Plan:
|
|
355
394
|
"""The resumption for ``trigger``; a fork trigger names its last surviving message via ``rollback_to``."""
|
|
356
395
|
if trigger in _TIP_TRIGGERS:
|
|
@@ -471,6 +510,31 @@ class CheckpointThread:
|
|
|
471
510
|
"""Load the branch's subtree tip as the current window."""
|
|
472
511
|
return self._load(await self._get(self._tip_of(branch_id)))
|
|
473
512
|
|
|
513
|
+
async def _world_path(self, branch_id: int) -> list[int]:
|
|
514
|
+
path = [0]
|
|
515
|
+
while branch_id != 0:
|
|
516
|
+
path.insert(1, branch_id)
|
|
517
|
+
fork_id = self.branches[branch_id - 1]["fork_message_id"]
|
|
518
|
+
if fork_id is None:
|
|
519
|
+
break
|
|
520
|
+
row = await self._index.get_message(self._thread_id, self._ns, fork_id)
|
|
521
|
+
if row is None:
|
|
522
|
+
raise KeyError(f"fork message {fork_id!r} is not indexed")
|
|
523
|
+
branch_id = row["branch_id"]
|
|
524
|
+
return path
|
|
525
|
+
|
|
526
|
+
async def switch_state(
|
|
527
|
+
self, branch_id: int
|
|
528
|
+
) -> tuple[list[dict[str, Any]], dict[str, Any]]:
|
|
529
|
+
"""Switch like ``switch_branch`` and return (transcript, lineage) for the host to write back into graph state."""
|
|
530
|
+
await self.switch_branch(branch_id)
|
|
531
|
+
lineage = self.lineage or {
|
|
532
|
+
"branch_ids": await self._world_path(branch_id),
|
|
533
|
+
"parent_checkpoint_id": None,
|
|
534
|
+
}
|
|
535
|
+
self._path = list(lineage["branch_ids"])
|
|
536
|
+
return list(self.transcript), lineage
|
|
537
|
+
|
|
474
538
|
async def page_up(self) -> "CheckpointThread":
|
|
475
539
|
"""Load the parent world's tail checkpoint as the current window."""
|
|
476
540
|
parent = (self.lineage or {}).get("parent_checkpoint_id")
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
harness_sdk/__init__.py,sha256=7qdf9hvQhTv_Iy7C8v_JkrPfbx2vTh2yUoLkHugJOR0,708
|
|
2
|
+
harness_sdk/checkpoints.py,sha256=J0pm5pIFz0ASIj3UkzfIPoPct7ky0-gS7hdhPSTHDQA,23820
|
|
3
|
+
harness_sdk/fenced_postgres.py,sha256=hbbrMR1WaqrHTNgd4wFrXfRrzQFGnyim-c8nZXgwWp4,13235
|
|
4
|
+
harness_sdk/linear_thread.py,sha256=laDRXKLFsMlyWS4snqNAM6t38wO26gevLWXRNivhHSM,1810
|
|
5
|
+
harness_sdk/run_manager.py,sha256=xL6TsXJk_3SVyA5oNuGlPelDmCqCRmL-bWW5wsfiIBY,77028
|
|
6
|
+
harness_sdk_python-0.23.0.dist-info/METADATA,sha256=Cjli98sD7w7aJxPEP3nrViq28m-2jVU9Bz51sG-SKWo,2200
|
|
7
|
+
harness_sdk_python-0.23.0.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
|
|
8
|
+
harness_sdk_python-0.23.0.dist-info/RECORD,,
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
harness_sdk/__init__.py,sha256=SPI2A_xoIbujjhZ3Cjysq8d5aLRQfCYFMIaTLC5auOs,648
|
|
2
|
-
harness_sdk/checkpoints.py,sha256=mfLyAyyMMLCxyVG-WVsplYKEVrkYpPrVjq-WnUzno_4,21283
|
|
3
|
-
harness_sdk/fenced_postgres.py,sha256=hbbrMR1WaqrHTNgd4wFrXfRrzQFGnyim-c8nZXgwWp4,13235
|
|
4
|
-
harness_sdk/linear_thread.py,sha256=laDRXKLFsMlyWS4snqNAM6t38wO26gevLWXRNivhHSM,1810
|
|
5
|
-
harness_sdk/run_manager.py,sha256=xL6TsXJk_3SVyA5oNuGlPelDmCqCRmL-bWW5wsfiIBY,77028
|
|
6
|
-
harness_sdk_python-0.22.0.dist-info/METADATA,sha256=p_NXI7hVF6MRx3q97Z4ZtMC-HJUPHuVHMQpPPgAUXNQ,2200
|
|
7
|
-
harness_sdk_python-0.22.0.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
|
|
8
|
-
harness_sdk_python-0.22.0.dist-info/RECORD,,
|
|
File without changes
|