Skip to main content

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


Download files

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

Source Distribution

actiongate_openai-0.2.0.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

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

actiongate_openai-0.2.0-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for actiongate_openai-0.2.0.tar.gz
Algorithm Hash digest
SHA256 2088e4dd35c5ffc043bc3bf6a36f1c653be1ea9249c5ee8001a8656bc328d085
MD5 b7f16bc4baaafcde80540cea8dced093
BLAKE2b-256 0741b59c7ab345ca395eaa1d7a6cb8f75197fffe63542947c97b3dd1986f074e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for actiongate_openai-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7bc5112dcf86db39e6858b4ab2c96aa85a0fc1dda5b30c22e4b0f2822d57a95a
MD5 ecf3e1f392373f8e2e29ed4c649d6b2d
BLAKE2b-256 b35bada39a1442fbbcc04c97ded6c898ee6f6aca74558ae2b28e87e5e11a2c00

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