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.2.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.2-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: klock_langchain-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 9fb1fd3b42417e6d4c8be254f1e9c05794bbb8c512c8a5793d8cff472b09b18b
MD5 7717517c7f50a40aaad4b6ac2c9ad69f
BLAKE2b-256 959f8ac0f4f4ac05522517afdc3ffc4736ef7deb553d2b26e5d0a86710e57f26

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for klock_langchain-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b2b779929333a437df47ccbce3e9db661485023522f0229907929c74d5fd23b2
MD5 0683e8b5c788ed5a1b68a1e874e481f1
BLAKE2b-256 d446d49f515ff81dc87681dd5c61d1f554e6b91d3c56cd141608c363f6ddd232

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