Skip to main content

klock-langchain

klock-langchain is the canonical OSS v1 integration for Klock.

It coordinates LangChain file-mutating tools so multiple agents can work in the same repo without silently overwriting each other.

This is coordination for cooperative tools that call Klock before mutating shared files. It is not yet filesystem-level enforcement.

Install

pip install klock klock-langchain langchain-core

Local workflow

For localhost workflows, use Klock.local(...). It auto-starts the local coordinator on the first lock/register/acquire operation when it can find a launch command.

When auto-start happens, the SDK logs the base URL, launch command, and PID.

Disable auto-start with:

  • KLOCK_DISABLE_AUTOSTART=1
  • KlockHttpClient(..., auto_start=False) if you use the advanced client directly

Then wrap your tool:

from klock import Klock
from klock_langchain import KlockConflictError, klock_protected
from langchain_core.tools import BaseTool

klock = Klock.local(agent_id="agent-a", session_id="repo-session-a", priority=100)

class WriteFileTool(BaseTool):
    name = "write_file"
    description = "Mutates a repo file."

    @klock_protected(
        klock_client=klock,
        agent_id="agent-a",
        session_id="repo-session-a",
        resource_type="FILE",
        resource_path_extractor=lambda kwargs: kwargs["path"],
        predicate="MUTATES",
    )
    def _run(self, path: str, content: str) -> str:
        with open(path, "w", encoding="utf-8") as handle:
            handle.write(content)
        return f"updated {path}"

Conflict behavior

klock_protected(...) uses Wait-Die semantics from the Klock server:

  • GRANT: the tool enters the critical section and runs
  • WAIT: the decorator sleeps for the server-provided backoff and retries
  • DIE: the decorator raises KlockConflictError so the caller can retry later

Example recovery loop:

try:
    tool.invoke({"path": "src/auth.js", "content": "..."})
except KlockConflictError as exc:
    if exc.reason == "DIE":
        # retry later
        ...

Proof assets

The repo includes deterministic proof scripts built around the same local-server workflow:

Run them from examples/oss_v1/README.md.

Metadata

Release files for klock-langchain 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for klock-langchain 0.1.3
File Size Uploaded
klock_langchain-0.1.3.tar.gz 10.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for klock-langchain 0.1.3
File Interpreter ABI Platform
klock_langchain-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 15.1 kB

Release files / klock_langchain-0.1.3.tar.gz

Download URL klock_langchain-0.1.3.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
28c81f612684d6f102dd26942bca9d1f814a6ec6c6a44d2022c6b88bd3c702e6
BLAKE2b-256 checksum
How to use checksums
f035b33473bccbaffdacec22ec0a38ac494d14a92431541625778551cc2ab48d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / klock_langchain-0.1.3-py3-none-any.whl

Download URL klock_langchain-0.1.3-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
65352ea30328f498b1d90814512f9bed5d3f9a6ef7e8b06ff63a48036781c7ac
BLAKE2b-256 checksum
How to use checksums
b021b01105190a4d261d6213b20ac0f04fcf1aa35de89b88226b0500ae0f26d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page