langchain-recourse
LangChain tools for RecourseOS - evaluate consequences before your AI agent executes destructive actions.
Installation
pip install langchain-recourse
Requires: Node.js 18+ (for npx recourse-cli)
Quick Start
from langchain_recourse import RecourseToolkit
from langchain_openai import ChatOpenAI
from langchain.agents import create_react_agent, AgentExecutor
# Get all RecourseOS tools
toolkit = RecourseToolkit()
tools = toolkit.get_tools()
# Create your agent with consequence checking
llm = ChatOpenAI(model="gpt-4")
agent = create_react_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools)
Tools
recourse_evaluate_terraform
Evaluate Terraform plans before terraform apply.
from langchain_recourse import RecourseEvaluateTerraform
tool = RecourseEvaluateTerraform()
result = tool.invoke({
"plan_json": '{"resource_changes": [...]}'
})
# Returns: "**Risk Assessment: BLOCK** ..."
recourse_evaluate_shell
Evaluate shell commands before execution.
from langchain_recourse import RecourseEvaluateShell
tool = RecourseEvaluateShell()
result = tool.invoke({
"command": "aws s3 rm s3://prod-data --recursive"
})
# Returns: "**Risk Assessment: BLOCK** ..."
recourse_evaluate_mcp
Evaluate MCP tool calls before invocation.
from langchain_recourse import RecourseEvaluateMCP
tool = RecourseEvaluateMCP()
result = tool.invoke({
"server": "aws",
"tool": "s3.delete_bucket",
"arguments": {"bucket": "prod-data"}
})
# Returns: "**Risk Assessment: ESCALATE** ..."
Risk Levels
| Level | Meaning | Agent Behavior |
|---|---|---|
ALLOW |
Safe to proceed | Execute normally |
WARN |
Recoverable but notable | Proceed with caution |
ESCALATE |
Needs human review | Ask user to confirm |
BLOCK |
Unrecoverable data loss | Do NOT proceed |
Agent Integration Example
Here's a complete example of an agent that checks consequences before destructive actions:
from langchain_recourse import RecourseToolkit, RecourseEvaluateShell
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain.agents import create_tool_calling_agent, AgentExecutor
# System prompt that enforces consequence checking
system_prompt = """You are a helpful DevOps assistant.
IMPORTANT: Before executing ANY destructive command (delete, remove, drop, etc.),
you MUST first use the recourse_evaluate_shell tool to check consequences.
If the risk assessment is:
- BLOCK: Refuse to proceed. Explain why to the user.
- ESCALATE: Ask the user to explicitly confirm before proceeding.
- WARN: Inform the user of the risk, then proceed if they agree.
- ALLOW: Proceed normally.
Never skip the consequence check for destructive operations."""
prompt = ChatPromptTemplate.from_messages([
("system", system_prompt),
("human", "{input}"),
("placeholder", "{agent_scratchpad}"),
])
# Setup
llm = ChatOpenAI(model="gpt-4")
tools = RecourseToolkit().get_tools()
agent = create_tool_calling_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
# Run
result = executor.invoke({
"input": "Delete the S3 bucket called prod-backups"
})
With Other Tools
Combine RecourseOS tools with your existing tools:
from langchain_recourse import RecourseToolkit
from langchain_community.tools import ShellTool
# Your tools + RecourseOS tools
my_tools = [ShellTool()]
recourse_tools = RecourseToolkit().get_tools()
all_tools = my_tools + recourse_tools
Configuration
The tools use npx recourse-cli@latest under the hood. Ensure:
- Node.js 18+ is installed
npxis in PATH- Network access to npm registry (first run downloads the CLI)
License
MIT
Metadata
Release files for langchain-recourse 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| langchain_recourse-0.1.0.tar.gz | 7.0 kB | Without provenance | Details for langchain_recourse-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| langchain_recourse-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for langchain_recourse-0.1.0-py3-none-any.whl |
Total release size: 13.5 kB
Release files / langchain_recourse-0.1.0.tar.gz
| Download URL | langchain_recourse-0.1.0.tar.gz |
|---|---|
| Size | 7.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
564cbc06f52eb8ab4d4d9c7392b75b696156fa2bafba809cae9d9668dfdb31cc
|
|
BLAKE2b-256 checksum How to use checksums |
3d86b376342fc591047ca170186edb436329a2cb5cbd446fdbd076bdcf2836ee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Release files / langchain_recourse-0.1.0-py3-none-any.whl
| Download URL | langchain_recourse-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5cdb3dab2bcaa2a00ce9b234c4575cc5155dc8be84e2213351162fc629418a83
|
|
BLAKE2b-256 checksum How to use checksums |
94bc7f337de9291d55abb524032bf7fbcda2e20f679e50c42610d36420488797
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Security for langchain-recourse 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.