Skip to main content

OpenAI Assistants API integration for Interven AI firewall. Scan tool calls the assistant decides to make before your code executes them.

Project description

interven-openai-assistants

OpenAI Assistants API integration for Interven. Scan every tool call the assistant decides to make before your code dispatches it.

Install

pip install interven-openai-assistants

How it fits in the Assistants loop

OpenAI Assistants runs in a loop: create thread → run assistant → if the assistant wants to call tools, the run transitions to requires_action → you dispatch the tools → submit outputs → assistant continues.

interven-openai-assistants inserts Interven between step 3 and step 4. You scan every tool_call the assistant returned; Interven tells you what to do with each.

Example

from openai import OpenAI
from interven_openai_assistants import scan_tool_calls

client = OpenAI()
run = client.beta.threads.runs.create_and_poll(thread_id=TID, assistant_id=AID)

if run.status == "requires_action":
    tool_calls = run.required_action.submit_tool_outputs.tool_calls
    decisions = scan_tool_calls(tool_calls, api_key="iv_live_...")

    outputs = []
    for scanned in decisions:
        call = scanned.tool_call
        scan = scanned.scan

        if scan.decision == "ALLOW":
            result = run_my_tool(call.function.name, scanned.effective_arguments)
            outputs.append({"tool_call_id": call.id, "output": result})

        elif scan.decision == "SANITIZE":
            # effective_arguments contains the redacted version
            result = run_my_tool(call.function.name, scanned.effective_arguments)
            outputs.append({"tool_call_id": call.id, "output": result})

        elif scan.decision == "DENY":
            outputs.append({
                "tool_call_id": call.id,
                "output": f"Tool blocked by Interven: {', '.join(scan.reason_codes)}",
            })

        elif scan.decision == "REQUIRE_APPROVAL":
            outputs.append({
                "tool_call_id": call.id,
                "output": f"Action requires human approval at {scan.raw.get('approval_url')}. Retry in a few minutes.",
            })

    client.beta.threads.runs.submit_tool_outputs(
        thread_id=TID, run_id=run.id, tool_outputs=outputs,
    )

What Interven understands

scan_tool_calls does best-effort mapping of common Assistants function names to real tool categories so policies fire correctly:

Function name contains Mapped to
slack / post_message / webhook Slack
github / pull_request / commit GitHub
drive / gdrive / share_file Google Drive
fetch / http / request Generic HTTP
anything else Generic tool with body scanning

For non-obvious function names, pass a url arg in your function schema and Interven will use it directly.

Options

scan_tool_calls(
    tool_calls,
    api_key="iv_live_...",   # or set INTERVEN_API_KEY env var
    gateway_url=None,         # defaults to https://api.intervensecurity.com
    timeout=30.0,
)

License

MIT

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

interven_openai_assistants-0.1.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

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

interven_openai_assistants-0.1.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file interven_openai_assistants-0.1.0.tar.gz.

File metadata

File hashes

Hashes for interven_openai_assistants-0.1.0.tar.gz
Algorithm Hash digest
SHA256 94be4e1a01360148679c16f60fe92a55421ee8de3dfb96db0100fcd05c19d439
MD5 982bae9c00bd378c0c04212da9d8c68c
BLAKE2b-256 77768f8f5b2f1d0b7a10ce149eaf84fc67cd95f78480ea8d989d09461328a6cf

See more details on using hashes here.

File details

Details for the file interven_openai_assistants-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for interven_openai_assistants-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b173aeab777bab2183e7324a2f3a48d46ace4e7f859f16d44382f85d832f903d
MD5 55e5fb703a292d177973e3b8521058bb
BLAKE2b-256 e18c45793a5c2208cb5d5fc75ec4e8398dfc9e817b695f682b31f8ecebe93b8e

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