LangChain + ACP — Policy & Audit Install Guide
acp-langchain checks every tool call your LangChain agent makes against your workspace policy, then records it with the end user’s identity. If the policy says no, the tool never runs.
On langchain 1.3.3 or later, you add one line to create_agent. On older versions, you add one decorator per tool. Your tool code doesn’t change.
What you need
- A LangChain agent in Python
- An ACP Cloud workspace (sign up)
- For multi-user apps: an identity provider configured in ACP (Auth0, Okta, or Entra ID)
Install
pip install acp-langchain
langchain 1.3.3 or later: middleware
from fastapi import FastAPI, Header
from langchain.agents import create_agent
from langchain.tools import tool
from acp_langchain import ACPMiddleware, configure, set_context
configure(base_url="https://api.agenticcontrolplane.com")
app = FastAPI()
@tool
def salesforce_query(query: str) -> str:
"""Query Salesforce records using SOQL."""
return sf.query(query) # your code, your credentials
@tool
def send_email(to: str, subject: str, body: str) -> str:
"""Send an email on behalf of the user."""
return sendmail(to, subject, body)
agent = create_agent(
model="openai:gpt-4o-mini",
tools=[salesforce_query, send_email],
middleware=[ACPMiddleware()], # governs every tool
)
@app.post("/run")
def run(prompt: str, authorization: str = Header(...)):
# Bind the end user's JWT per request so every tool call
# carries the user's identity to ACP.
set_context(user_token=authorization.removeprefix("Bearer ").strip())
result = agent.invoke({"messages": [{"role": "user", "content": prompt}]})
return {"result": result["messages"][-1].content}
Deep Agents subagents are covered too. Use create_deep_agent from acp_langchain.deepagents.
Older LangChain: the @governed decorator
Stack @governed("tool_name") under @tool, closest to the plain function:
from langchain.tools import tool
from acp_langchain import governed
@tool
@governed("salesforce_query")
def salesforce_query(query: str) -> str:
"""Query Salesforce records using SOQL."""
return sf.query(query)
Coverage is per function. A tool without the decorator runs ungoverned. Don’t use the middleware and the decorator on the same tool, because the call would be checked and audited twice.
What happens on every tool call
- Pre-check. The SDK POSTs to ACP
/govern/tool-usewith the tool name, the arguments, and the user token bound byset_context. - Decide. ACP evaluates workspace policy, the user’s scopes, rate limits, and PII rules.
- Deny. The tool function is never called. The SDK returns
"tool_error: <reason>", the model sees it as the tool’s result, and the run completes normally. - Allow. Your tool runs.
- Post-audit. The result POSTs to
/govern/tool-outputand the PII scan runs.redactreplaces the output before the model sees it.blockreturns"[ACP] Blocked: <reason>". An audit row is written with the end user’s identity.
Sync and async tools are both covered.
Using LangChain’s human-in-the-loop with ACP
LangChain 1.x ships HumanInTheLoopMiddleware. It interrupts the graph before a sensitive tool runs so a human can approve, edit, or reject (with conditional when predicates since 1.3.3). Use it for the pause.
ACP adds the policy and the record: which calls are allowed at all, what was decided, and the same answers when the same user drives Claude Code or Cursor. The two work together:
from langchain.agents.middleware import HumanInTheLoopMiddleware
agent = create_agent(
model="openai:gpt-4o-mini",
tools=[salesforce_query, send_email],
middleware=[
ACPMiddleware(),
HumanInTheLoopMiddleware(interrupt_on={"send_email": True}), # the pause
],
)
The human approval comes first, after the model proposes a call. The ACP check runs when the call executes, so a human-approved call still passes policy and lands in the audit trail.
On the legacy stack (langchain-classic)
LangChain 1.0 split the package. Legacy chains and agents (AgentExecutor, create_tool_calling_agent, and friends) now live in langchain-classic, and langgraph.prebuilt.create_react_agent is deprecated in favor of create_agent. @governed doesn’t care which constructor calls the decorated function, so use the decorator from the section above unchanged. It also works inside a custom StateGraph’s ToolNode.
Alternative: use tools from ACP’s MCP endpoint
If you want ACP to hold the backend credentials, connect LangChain to your workspace’s MCP endpoint instead. ACP runs the tools on its side with per-user OAuth tokens and records every call.
tools/list returns the tools enabled for the workspace, the same list for every user. If a user calls a tool whose required scopes they lack, the call is rejected at call time with a JSON-RPC -32004 Insufficient scope error.
See MCP servers for the setup. With the SDK your tools stay in your process. With MCP they move behind ACP.
Check the audit log
Open Activity in the ACP dashboard. Every LangChain tool call shows the user (the token’s sub), the tool name, the decision (allow, deny, or redact, with the reason), the session that groups one request’s calls, and any PII findings. LangChain calls sit next to Claude Code and Cursor calls from the same user. You can export to CSV.
If ACP can’t be reached
The LangChain SDK fails open. If /govern/tool-use times out (5 seconds by default) or is unreachable, the tool runs. The SDK prints an [ACP] UNGOVERNED warning once per cause and adds the lapse to a local lapse log. The audit reason is fail-open (<cause>).
The Claude Code plugin does the same for interactive sessions. For unattended Claude Code sessions (subagents, background, API), it fails closed and blocks until the gateway answers.
Back to guides · Govern a Vercel AI SDK app → · SOC 2 audit trails →