Gate OpenAI function/tool calls through ActionGate primitives before execution.
Project description
actiongate-openai
Gate OpenAI function/tool calls through ActionGate primitives before execution.
pip install actiongate-openai
What it does
Sits between the model's tool_call and your function. Checks rate limits, budgets, and policies before the function runs. If any gate blocks, the function never executes.
Model → tool_call → GatedToolRunner.call() → your function
↓ (if blocked)
GateResult(allowed=False)
Quick start
from actiongate import Engine, Gate, Policy
from actiongate_openai import GatedToolRunner
engine = Engine()
runner = GatedToolRunner(actiongate=engine)
runner.register(
"search_web", search_fn,
gate=Gate("tools", "search_web", "agent:1"),
policy=Policy(max_calls=10, window=60),
)
# In your tool execution loop:
for tool_call in response.choices[0].message.tool_calls:
result = runner.call_from_openai(tool_call)
if result.allowed:
# send result.result back to model
else:
# send result.message as error
Works with both Chat Completions API and Responses API tool calls.
Add more gates
Each gate is optional. Install what you need:
pip install actiongate-openai[budget] # + spend control
pip install actiongate-openai[all] # + spend, policy, audit
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 auditgate import Engine as Audit, Trail
from actiongate_openai import GatedToolRunner
from decimal import Decimal
def no_pii(ctx: Context) -> bool:
return "ssn" not in str(ctx.kwargs).lower()
runner = GatedToolRunner(
actiongate=AG(),
budgetgate=BG(),
rulegate=RG(),
auditgate=Audit(recorded_by="agent:1"),
)
runner.register(
"search_web", search_fn,
# Rate limit: 10 calls per minute
gate=Gate("tools", "search_web", "agent:1"),
policy=Policy(max_calls=10, window=60),
# Budget: $5 per hour
ledger=Ledger("openai", "search", "agent:1"),
budget=Budget(max_spend=Decimal("5.00"), window=3600),
cost=Decimal("0.01"),
# Policy: no PII in queries
rule=Rule("tools", "search_web", "agent:1"),
ruleset=Ruleset(predicates=(no_pii,)),
# Audit: log every decision
trail=Trail("tools", "search_web", "agent:1"),
)
Gates evaluate in order: ActionGate → BudgetGate → RuleGate → execute → AuditGate. First block stops the pipeline.
GateResult
Every call returns a GateResult:
result = runner.call("search_web", {"query": "latest news"})
result.allowed # bool
result.result # function return value (None if blocked)
result.blocked_by # "actiongate" | "budgetgate" | "rulegate" | None
result.message # human-readable block reason
result.decisions # dict of gate decisions for inspection
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_openai-0.1.0.tar.gz.
File metadata
- Download URL: actiongate_openai-0.1.0.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02c3e54dce8b2a9f02685f55e9ae5dd8cb1b6a8b6e8fc4037cfa26e50448f728
|
|
| MD5 |
a03b3203a4dfb74c23ec82958e443e94
|
|
| BLAKE2b-256 |
727c432996567981e152ce9af96ff5721f66fa42d7bdca609665949f36865690
|
File details
Details for the file actiongate_openai-0.1.0-py3-none-any.whl.
File metadata
- Download URL: actiongate_openai-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.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 |
4836aed7128c7a472fadf95f447e6e93984225fd2d2f4698629268a813e8fb45
|
|
| MD5 |
9ec0263da910c9de58e59d060b9d84c5
|
|
| BLAKE2b-256 |
ceaa796c7da6012c029da7456b5840ecebeef1ea9afc47f606183ed4e5662407
|