Framework integration
LangChain
Use Quasentra middleware with LangChain create_agent so tool authorization happens immediately before supported local execution.
Before you begin: create an API key with agent:register, policy:sync and decision:create, then set QUASENTRA_API_KEY and QUASENTRA_URL.
1. Install
pip install 'quasentra[langgraph]'
2. Create local tools
Keep each business capability as a named, typed tool. Underscores in tool names become dots in policy actions.
from langchain.tools import tool
@tool
def customer_read(customer_id: str) -> str:
"""Return one customer's account status."""
return company_database[customer_id]["status"]
@tool
def email_send(recipient: str, subject: str, body: str) -> str:
"""Send an email to a customer."""
return mail_service.send(recipient, subject, body)3. Secure the agent
import os
from langchain.agents import create_agent
from langchain.chat_models import init_chat_model
from quasentra import Quasentra
security = Quasentra(api_key=os.environ["QUASENTRA_API_KEY"], base_url=os.environ["QUASENTRA_URL"])
tools = [customer_read, email_send]
middleware = security.langgraph(
agent_id="support-agent", name="Support Agent", tools=tools,
permissions={"customer.read": "ALLOW", "email.send": "REQUIRE_APPROVAL"},
)
agent = create_agent(model=init_chat_model(os.environ["AGENT_MODEL"]), tools=tools, middleware=[middleware])
result = agent.invoke(
{"messages": [{"role": "user", "content": "Read customer CUST-100"}]},
config={"configurable": {"thread_id": "support-1001"}},
)
security.close()4. Confirm enforcement
- Start the application once.
- Open Dashboard → Agents and confirm the agent and tools were discovered.
- Open Policies and confirm every action has the intended effect.
- Request an allowed action and confirm the implementation runs.
- Request a denied action and confirm it appears in Decisions but never reaches the implementation.
Runtime guarantees
- Agent and tool metadata sync idempotently at construction/startup.
- Newly discovered tools receive default-DENY.
- A denied or approval-required tool implementation does not execute.
- Authorization transport exhaustion fails closed.
Security boundary
Install middleware when the agent is created. Attaching it after construction is not a verified security boundary.
Do not keep another unwrapped path to sensitive functions. For high-impact tools, move credentials and execution into the trusted gateway.