← All integrations
LANGCHAIN · NATIVE AGENTMIDDLEWARE · PYPI v0.1.0

Guarded LangChain tool calls, with evidence you can verify.

Keep LangChain responsible for agent planning and native tool dispatch. LoopGrid records signed decision evidence and evaluates the real Core policy before consequential tools run. Your trusted application supplies authority, verifies human review and observes external outcomes.

loopgrid-langchain==0.1.0 · Python 3.10+ · LangChain >=1.2,<2 · validated with LangChain 1.4.5 and Core 0.8.1-design-partner.

NATIVE AGENT TOOL EVIDENCE FLOW
01Observed model proposes a native tool call
02Host identity + exact arguments committed
03Core policy + authenticated human review
04Shared lease + signed dispatch reservation
05Native result; optional trusted external receipt
06Separately observed outcome + verification

A tool result is not a payment receipt. The middleware records native handler returns separately from verified external execution and business outcomes.

01 · INSTALL

Install the released native LangChain middleware.

python -m pip install loopgrid-langchain==0.1.0

Use create_loopgrid_middleware() with a LangChain 1.x create_agent. This is a native AgentMiddleware integration with both wrap_tool_call and awrap_tool_call, not a renamed LangGraph StateGraph adapter. The Python package needs a running LoopGrid Core service, an authorized workspace/service key and a host-managed policy for actual evidence recording.

Already using StateGraph nodes or checkpoint interrupt/resume? Keep the separate LangGraph integration. Neither integration requires replacing the other.

02 · NATIVE CREATE_AGENT INTEGRATION

Attach the guard to the real tool-execution boundary.

from langchain.agents import create_agent
from loopgrid_langchain import (
    CoreClient, LangChainBridge, HostBinding,
    create_loopgrid_middleware,
    LocalSqliteDispatchLease, LocalAsyncSqliteDispatchLease,
)

# Replace host-provided values with authentic application configuration.
client = CoreClient(
    base_url=CORE_URL,
    workspace_id=WORKSPACE_ID,
    service_key=SERVICE_KEY,
)
# Single-host development only, not a distributed lease.
lease_file = "./sandbox-dispatch.sqlite"
bridge = LangChainBridge(
    client,
    dispatch_lease=LocalSqliteDispatchLease(lease_file),
    async_dispatch_lease=LocalAsyncSqliteDispatchLease(lease_file),
)

def host_binding(request):
    # Never read authority, policy, or reviewer identity from model text.
    return HostBinding(
        run_id=RUN_ID,
        agent_id="sandbox-agent",
        policy_id=APPLICATION_POLICY_ID,
        authority={"role": "sandbox"},
        model={"name": "host-selected-model"},
        context={"prompt_version": "v1"},
    )

middleware = create_loopgrid_middleware(bridge, host_binding)
agent = create_agent(
    model=MODEL, tools=[SANDBOX_TOOL], middleware=[middleware],
)

Host-integration sketch, not standalone runnable code: CORE_URL, WORKSPACE_ID, SERVICE_KEY, RUN_ID, APPLICATION_POLICY_ID, MODEL and SANDBOX_TOOL must come from your application. Use only disposable sandbox tools until policy and reviewer authentication are tested. The upstream native E2E script ↗ is an executable no-provider-key example with synthetic model output.

Place the LoopGrid middleware last/innermost if other middleware rewrites native tool arguments. The default guards all tool names; an optional protected_tools selection intentionally excludes other tools, so it must be chosen carefully.

03 · SIGNED ACTION LIFECYCLE

One consequential tool call, distinct evidence claims.

01Authentic proposal + authority

Read the actual LangChain tool call and host-supplied run, model, policy, identity and delegation. Commit an exact immutable argument snapshot and SHA-256 digest. Model text cannot grant authority.

02Policy + real human review

Core returns signed versioned policy evidence. Where approval is required, only an authenticated host review recorded by Core can authorize continued execution. A signed rejection remains terminal.

03Guarded request before dispatch

A required shared lease and tool_requested reservation precede the native sync/async tool handler. An ambiguous dispatch must be reconciled, not automatically replayed.

04Native tool result

The ToolMessage or supported native Command is recorded as tool_result. A successful handler return alone is not evidence of a confirmed external transaction.

05Independent action receipt + outcome

After checking an external provider, a trusted host can call record_execution() to record a confirmed receipt and later record_outcome() for separately observed state.

06Signed Core verification

Core verifies the signed workspace chain and captured lifecycle. To make an independent offline cryptographic claim, export the evidence and use a separately pinned signer public key and offline verifier.

04 · APPROVAL + REPLAY PROTECTION

Approval cannot be invented by the model; retries cannot duplicate an action.

Application policyA current, versioned Core policy must match the exact proposed action before the handler runs.
Signed reviewMissing approval blocks the guarded call. Authentic host reviewer identity is required outside the LLM.
Lease required by defaultA single-host SQLite lease is provided for development. Production multi-worker deployments need an atomic durable distributed host lease and downstream idempotency.
Ambiguous resultA prior tool_requested or unknown result is a no-replay barrier. Reconcile with the authoritative external system.

Not globally exactly-once: a distributed lease, provider idempotency and external reconciliation remain the host application's responsibility. The adapter does not authenticate users or control unwrapped agent tools.

05 · PRIVACY + TRUST

Keep credentials, external truth and reviewer identity with the host.

Raw service credentials must never be included in prompts, tool calls or signed evidence. Redacted fields are tied to source values using commitments; SHA-256 is not anonymization for low-entropy data. Use HTTPS for remote Core. Signed integrity authenticates captured records; it does not prove that the underlying model claim is true, every action was captured, or a financial transaction settled.

Model observationCall observe_model() only for genuinely observed completed model output, not an inferred or simulated provider response.
Native tool resultHandler returns are tool_result; do not relabel them as third-party execution receipts.
Scope of protectionOnly native tool calls traversing this middleware instance are guarded. The application owns all other side effects.
Independent verificationCore-signed workspace checks differ from pinned-key offline verification of exported evidence.
06 · v0.1.0 RELEASE VALIDATION

Native LangChain, real Core and public PyPI passed.

Unit + security suite114/114 tests passed with 94.81% statement coverage (90% required).
Hosted GitHub CI9/9 OS/Python test jobs passed on Ubuntu, Windows and macOS using Python 3.10, 3.12 and 3.13, plus a clean-wheel consumer job.
Native agentReal installed LangChain create_agent passed synchronous and asynchronous guarded synthetic tool execution and replay refusal.
Core E2ELocal Core 0.8.1 signed policy/review and a combined native LangChain/Core execution passed with evidence_complete, signed verification true and no failures.
Public releaseGitHub v0.1.0, Trusted Publishing workflow and public PyPI installation passed. The maintainer demonstrated a public registry import, although its global Python environment had unrelated dependency conflicts.

Tests used deterministic synthetic model outputs and synthetic external actions: no actual money moved, and no live paid model-provider invocation was demonstrated. See the validation record ↗, integration contract ↗ and security boundaries ↗.

07 · NEXT STEPS

Start with synthetic tools. Connect authoritative evidence later.

Run native_agent_e2e.py ↗ against an installed LangChain SDK, then test native_core_agent_e2e.py ↗ on a disposable Core workspace. Add real application policy and authenticated review, use a production shared lease and provider idempotency, and only then connect downstream business actions with independently checked receipts and outcomes.

Unlike the separate LangGraph StateGraph adapter, this integration protects LangChain create_agent native tool middleware. It is an independent, community-built integration; no official LangChain endorsement or certification is claimed.

LANGCHAIN + LOOPGRID

Give consequential tool calls a signed evidence trail.

Begin with a real Core workspace, a synthetic LangChain tool and trusted host policy. Keep authorization and downstream business truth separate from model output.