Skip to main content

LangChain integration for Klock

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

klock_langchain-0.1.3.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

klock_langchain-0.1.3-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file klock_langchain-0.1.3.tar.gz.

File metadata

  • Download URL: klock_langchain-0.1.3.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for klock_langchain-0.1.3.tar.gz
Algorithm Hash digest
SHA256 28c81f612684d6f102dd26942bca9d1f814a6ec6c6a44d2022c6b88bd3c702e6
MD5 b0220e9723abaecf3637fda319ef3b20
BLAKE2b-256 f035b33473bccbaffdacec22ec0a38ac494d14a92431541625778551cc2ab48d

See more details on using hashes here.

File details

Details for the file klock_langchain-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for klock_langchain-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 65352ea30328f498b1d90814512f9bed5d3f9a6ef7e8b06ff63a48036781c7ac
MD5 3ea8f1d384f782e809a7603d072b61e2
BLAKE2b-256 b021b01105190a4d261d6213b20ac0f04fcf1aa35de89b88226b0500ae0f26d3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page