Skip to main content
Attestix
Guides

LangChain Integration

Drop Attestix into a LangChain agent with the BaseCallbackHandler. Production-ready in v0.3.0. Every tool call, LLM call, and chain step gets hash-chained and signed.

Attestix ships with a first-party BaseCallbackHandler implementation that writes every LangChain event into the Attestix audit trail and auto-issues a Verifiable Credential for each chain completion.

Install

pip install attestix[langchain]

Minimal wiring

from langchain.agents import AgentExecutor
from langchain_openai import ChatOpenAI
from attestix.integrations.langchain import AttestixCallback

callback = AttestixCallback(
    agent_id="attestix:f9bdb7a94ccb40f1",
    record_llm_tokens=True,
)

executor = AgentExecutor(
    agent=my_agent,
    tools=tools,
    callbacks=[callback],
)

result = executor.invoke({"input": "Run Q4 analysis"})

Every tool call, LLM call, and chain step is captured with the SHA-256 hash chain advancing each step.

What the callback records

EventCaptured
on_chain_startagent id, chain name, input hash
on_tool_starttool name, args hash, parent chain id
on_tool_endoutput hash, duration, prev hash
on_llm_startmodel name, prompt hash, token count
on_llm_endcompletion hash, tokens used, cost estimate
on_chain_endfinal output hash, total tokens, VC issuance
on_chain_errorexception type, stack hash

Auto-issued credentials

Set issue_vc_on_success=True (default) and Attestix issues a ChainExecutionCredential with:

  • Claim: input hash, output hash, tool chain, duration.
  • Proof: Ed25519Signature2020 over the canonicalised JSON.
  • Subject: the agent ID.

Verify it offline with any W3C VC verifier, or via:

from attestix.services.credential_service import CredentialService

credential_svc = CredentialService()
credential_svc.verify_credential(credential_id)

Delegating to sub-agents

If the chain spawns a sub-chain with its own agent, Attestix issues a UCAN delegation with capability attenuation:

callback = AttestixCallback(
    agent_id=parent_id,
    child_agent_id=child_id,
    delegate_capabilities=["summarize", "redact"],
)

Verify offline

from attestix.services.credential_service import CredentialService

credential_svc = CredentialService()
ok = credential_svc.verify_credential(credential_id)

See the offline verify guide for a full walkthrough.

Sample repository

The examples directory contains a complete LangChain agent with Attestix wired end-to-end.