Skip to main content

Gate LangChain tool execution through ActionGate primitives before execution.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

actiongate_langchain-0.2.0.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

actiongate_langchain-0.2.0-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file actiongate_langchain-0.2.0.tar.gz.

File metadata

  • Download URL: actiongate_langchain-0.2.0.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for actiongate_langchain-0.2.0.tar.gz
Algorithm Hash digest
SHA256 fa9063a8d741838661d70c1ce53a4a27342be177551ad16e34c47ee35aec1877
MD5 acbd250cfac30403fdc129bd93ce2a9a
BLAKE2b-256 31d9b236219c73f60dd4dd9ed868e1a4bbb80d6977661e56f08b32ab8f04488e

See more details on using hashes here.

File details

Details for the file actiongate_langchain-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for actiongate_langchain-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ebd1573541b90285aadd81441e600bb12060dd100856e8136823298bccf5b52f
MD5 7c498bcdf15b11174d99cf82e4e312d1
BLAKE2b-256 41f8fd26ea6a541881c90f918a16ca8fec5ee2b98d553447a189697057f691a7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page