Gate LangChain tool execution through ActionGate primitives.
Project description
actiongate-langchain
Gate LangChain tool execution through ActionGate primitives.
pip install actiongate-langchain
Quick start
from actiongate import Engine, Gate, Policy
from actiongate_langchain import gated_tool
ag = Engine()
@gated_tool(
actiongate=ag,
gate=Gate("tools", "search", "agent:1"),
policy=Policy(max_calls=10, window=60),
)
def search_web(query: str) -> str:
"""Search the web for a query."""
return api.search(query)
# Use with any LangChain agent
agent = create_react_agent(llm, [search_web], prompt)
The tool checks all gates before execution. If any gate blocks, it raises ToolException with the block reason — LangChain agents handle this automatically.
Add more gates
pip install actiongate-langchain[all]
from actiongate import Engine as AG, Gate, Policy
from budgetgate import Engine as BG, Ledger, Budget
from rulegate import Engine as RG, Rule, Ruleset, Context
from actiongate_langchain import gated_tool
from decimal import Decimal
def no_pii(ctx: Context) -> bool:
return "ssn" not in str(ctx.kwargs).lower()
ag, bg, rg = AG(), BG(), RG()
@gated_tool(
actiongate=ag,
gate=Gate("tools", "search", "agent:1"),
policy=Policy(max_calls=10, window=60),
budgetgate=bg,
ledger=Ledger("openai", "search", "agent:1"),
budget=Budget(max_spend=Decimal("5.00"), window=3600),
cost=Decimal("0.01"),
rulegate=rg,
rule=Rule("tools", "search"),
ruleset=Ruleset(predicates=(no_pii,)),
)
def search_web(query: str) -> str:
"""Search the web for a query."""
return api.search(query)
Gates evaluate in order: ActionGate → BudgetGate → RuleGate → execute → AuditGate.
GatedTool class
For more control, use GatedTool.from_function() directly:
from actiongate_langchain import GatedTool
tool = GatedTool.from_function(
func=search_fn,
name="search_web",
description="Search the web",
actiongate=ag,
gate=Gate("tools", "search", "agent:1"),
policy=Policy(max_calls=10, window=60),
)
License
Apache-2.0. ActionGate and BudgetGate are Apache-2.0. RuleGate and AuditGate are BSL-1.1.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file actiongate_langchain-0.1.0.tar.gz.
File metadata
- Download URL: actiongate_langchain-0.1.0.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81febc14ed7183bbf63b1f2fb2d35250dc5317329179e61f6177537bcc9896b4
|
|
| MD5 |
379f5bb77fd376bead8fe520dedf02ff
|
|
| BLAKE2b-256 |
d0c758a4386e042f467b3dac7cbd084b36d0b0006486da3ae57884a05bf5dd43
|
File details
Details for the file actiongate_langchain-0.1.0-py3-none-any.whl.
File metadata
- Download URL: actiongate_langchain-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
87ddc01c3f327af953b7a3a291b37b7dec69d68c14e98182a234eb9b75119300
|
|
| MD5 |
eee1f00b61830aabc4811a34826c4bac
|
|
| BLAKE2b-256 |
17439b07bb677fad3d5baaa85981472375d053b7215feb54e15fd2f8ed7edb60
|