Skip to Content
IntegrationsLangChain

LangChain

beav3r-sdk-langchain lets LangChain tools route through Beav3r before execution.

Use it when tool calls must be approved, denied, or blocked by policy before the handler runs.

Install

python3 -m pip install beav3r-sdk beav3r-sdk-langchain langchain-openai

Required environment

For the included example script (examples/simple_agent.py):

  • BEAV3R_BASE_URL
  • BEAV3R_API_KEY
  • OPENAI_API_KEY
  • optional OPENAI_BASE_URL (defaults to https://api.openai.com/v1)
  • optional MODEL_NAME (defaults to gpt-4.1-mini)
  • optional BEAV3R_TIMEOUT_MS

Example middleware wiring

from beav3r_sdk import Beav3r from langchain.agents import create_agent from langchain_openai import ChatOpenAI from langchain_beav3r import Beav3rApprovalMiddleware, Beav3rToolConfig def send_usdt(amount: int, recipient: str) -> str: return f"Sent {amount} USDT to {recipient}" client = Beav3r( base_url=base_url, api_key=api_key, agent_id="langchain_demo", ) model = ChatOpenAI( model=model_name, api_key=provider_api_key, base_url=provider_base_url, temperature=0, ) agent = create_agent( model=model, tools=[send_usdt], middleware=[ Beav3rApprovalMiddleware( client, tool_configs={ "send_usdt": Beav3rToolConfig(action_type="payments.send_usdt"), }, timeout_ms=timeout_ms, ) ], )

This matches examples/simple_agent.py in beav3r-sdk-langchain.

Run the example

export BEAV3R_BASE_URL=https://staging.server.beav3r.ai export BEAV3R_API_KEY=bvr_test_... export OPENAI_API_KEY=... # optional # export OPENAI_BASE_URL=https://api.openai.com/v1 # export MODEL_NAME=gpt-4.1-mini # export BEAV3R_TIMEOUT_MS=300000 python3 examples/simple_agent.py

Runtime outcomes

  • approved or executed: tool runs
  • denied, rejected, or expired: tool is blocked
  • still pending: Beav3rApprovalPendingError is raised

Docker path

bash scripts/run_simple_agent_docker.sh

The Docker script installs sibling beav3r-sdk-py, installs this adapter, and runs the same example.