Skip to main content

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.

Release files for actiongate-langchain 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for actiongate-langchain 0.2.0
File Size Uploaded
actiongate_langchain-0.2.0.tar.gz 9.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for actiongate-langchain 0.2.0
File Interpreter ABI Platform
actiongate_langchain-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 18.9 kB

Release files / actiongate_langchain-0.2.0.tar.gz

Download URL actiongate_langchain-0.2.0.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
fa9063a8d741838661d70c1ce53a4a27342be177551ad16e34c47ee35aec1877
BLAKE2b-256 checksum
How to use checksums
31d9b236219c73f60dd4dd9ed868e1a4bbb80d6977661e56f08b32ab8f04488e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / actiongate_langchain-0.2.0-py3-none-any.whl

Download URL actiongate_langchain-0.2.0-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ebd1573541b90285aadd81441e600bb12060dd100856e8136823298bccf5b52f
BLAKE2b-256 checksum
How to use checksums
41f8fd26ea6a541881c90f918a16ca8fec5ee2b98d553447a189697057f691a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page