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, KlockHttpClient now auto-starts the local server 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)

Then wrap your tool:

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

klock = KlockHttpClient(base_url="http://localhost:3100")
klock.register_agent("agent-a", 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.1.tar.gz (8.9 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.1-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: klock_langchain-0.1.1.tar.gz
  • Upload date:
  • Size: 8.9 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.1.tar.gz
Algorithm Hash digest
SHA256 d69e2f94d71a45ef7e18731dd26202fa332f380e11bfc4f0bc4bc8fc02b5a293
MD5 8a81d9e672ba4bbac8fe0824758bb3ee
BLAKE2b-256 1817e318c174a2b479a2095ac4ab69ee4b35ca329b764c668df9654ce8d3f62c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for klock_langchain-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0563160bbc2643f5c193b2d8bf9b9c0d0d263d80785fb6a40c92ffb29cd2dba5
MD5 44131cbad26de58b88f3002176989bd4
BLAKE2b-256 74454d0c14bafae179094f2fef98962cc878516deee4188ae85586dcafc7ddc5

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