Skip to main content

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.

Release files for actiongate-openai 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-openai 0.2.0
File Size Uploaded
actiongate_openai-0.2.0.tar.gz 11.1 kB Details

Built distribution (wheel)

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

Total release size: 21.5 kB

Release files / actiongate_openai-0.2.0.tar.gz

Download URL actiongate_openai-0.2.0.tar.gz
Size 11.1 kB
Tags Source
SHA-256 checksum
How to use checksums
2088e4dd35c5ffc043bc3bf6a36f1c653be1ea9249c5ee8001a8656bc328d085
BLAKE2b-256 checksum
How to use checksums
0741b59c7ab345ca395eaa1d7a6cb8f75197fffe63542947c97b3dd1986f074e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

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

Download URL actiongate_openai-0.2.0-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7bc5112dcf86db39e6858b4ab2c96aa85a0fc1dda5b30c22e4b0f2822d57a95a
BLAKE2b-256 checksum
How to use checksums
b35bada39a1442fbbcc04c97ded6c898ee6f6aca74558ae2b28e87e5e11a2c00
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.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