Skip to main content

OpenAI adapter for decision learning for AI agent actions with BIGHUB.

Project description

bighub-openai

Better decisions for OpenAI tool calls.

Beta release: this is the first public Better Decision OpenAI adapter beta.

bighub-openai adds BIGHUB's Better Decision layer to OpenAI agents before they execute risky IT tool calls, turning proposed IT actions into better decisions before execution.

OpenAI Responses API  ->  bighub-openai          ->  BIGHUB
tool call             ->  proposed IT action     ->  Decision Packet + DecisionBrain
runtime               ->  decision signals       ->  execution mode or review
outcome later         ->  optional report        ->  future decisions improve

Use it when your OpenAI agent can take actions such as:

  • granting Okta or IAM access
  • triggering CI/CD deploys
  • running Terraform, Kubernetes, or Argo CD actions
  • rotating credentials
  • posting incident updates
  • continuing after Trivy, Syft, or SBOM security checks
  • calling internal APIs that change production state
pip install --pre bighub-openai

For future stable releases, use:

pip install bighub-openai

Requires Python 3.9+.

Dependencies:

  • bighub>=0.1.0b2,<0.2.0
  • openai>=2.0.0,<3.0.0

Quickstart

import os
from bighub_openai import BighubOpenAI


agent = BighubOpenAI(
    openai_api_key=os.getenv("OPENAI_API_KEY"),
    bighub_api_key=os.getenv("BIGHUB_API_KEY"),
    actor="ops-agent",
    domain="it_actions",
)


@agent.action(system="okta", risk="high", environment="production")
def grant_access(user_id: str, group: str, duration: str) -> dict:
    return {"ok": True, "user_id": user_id, "group": group, "duration": duration}


response = agent.run(
    messages=[{"role": "user", "content": "Grant Alice temporary Okta admin access for 48h"}],
    model="gpt-5.5",
)

last = response["execution"]["last"]
print(last["status"])                   # executed, blocked, approval_required, tool_error
print(last["decision"].get("mode"))    # review, autonomous, constrained, blocked, needs_context
print(last["decision"].get("risk"))
print(last["decision"].get("reason"))

agent.action(...) auto-generates a strict JSON schema from the Python function signature and attaches system context. GuardedOpenAI remains available as a compatibility alias.


When to use bighub-openai

Use this adapter when your OpenAI-based agent makes tool calls that:

  • change infrastructure or production state
  • may require review depending on system, scope, environment, or timing
  • benefit from decision-time and polled operational context
  • should stop, pause for review, or ask for more context before risky execution

If your agent only reads data or produces text, you probably do not need this adapter.


How it works

For every tool call, the adapter follows the same loop:

  1. The model proposes a tool call.
  2. The adapter captures action, arguments, actor, domain, and system metadata.
  3. BIGHUB evaluates the action and may return a Decision Packet, DecisionBrain signals, and execution guidance.
  4. The adapter resolves the execution result: execute, block, or require approval.
  5. If enabled, optional outcome reporting and memory ingestion happen after execution.

Recommended mental model:

OpenAI tool call -> proposed IT action -> Decision Packet -> DecisionBrain -> execution mode / review -> optional outcome reporting


Response Shape

Representative shape from run():

{
  "llm_response": {...},
  "execution": {
    "events": [...],
    "last": {
      "tool": "grant_access",
      "status": "approval_required",
      "decision": {
        "request_id": "req_abc123",
        "better_action": "Grant scoped Okta admin access for 2h instead of 48h",
        "mode": "review",
        "can_run": False,
        "needs_review": True,
        "needs_more_context": False,
        "should_not_run": False,
        "risk": 0.78,
        "reason": "Production admin access for 48h is broader than necessary.",
        "decision_packet": {...},
        "decision_brain": {...}
      },
      "recommendation": "review_recommended",
      "risk_score": 0.78,
      "enforcement_mode": "review"
    }
  }
}

The adapter returns the full raw BIGHUB decision under last["decision"]. When the backend returns the newer Better Decision fields, those remain the preferred application surface.

Primary decision signals

Field Description
better_action A real backend-produced alternative when available; otherwise None
mode Execution mode such as autonomous, constrained, review, blocked, or needs_context
can_run Whether the tool call can execute now
needs_review Whether a human review should happen first
needs_more_context Whether the agent should collect more information
should_not_run Whether BIGHUB recommends not executing
risk Top-level risk score when provided
reason Human-readable reason when provided
decision_packet Structured context used for the decision
decision_brain DecisionBrain reasoning summary and related signals

Execution statuses

Status Description
executed Tool ran successfully
blocked Runtime prevented execution
approval_required Waiting for human approval
tool_error Tool raised an exception during execution

Compatibility signals

For backward compatibility, last may also expose convenience fields such as recommendation, risk_score, enforcement_mode, and legacy decision payload keys like allowed, result, or reason. Prefer the structured fields inside last["decision"] when they are present.


Configuration

agent = BighubOpenAI(
    bighub_api_key="bh_live_xxx",
    openai_api_key="sk-xxx",
    actor="ops-agent",
    domain="it_actions",
    decision_mode="submit",      # or "submit_payload"
    fail_mode="closed",          # fail safe on BIGHUB errors
    max_tool_rounds=8,
    model_selection="auto",
    provider_timeout_seconds=30.0,
    provider_max_retries=2,
    outcome_reporting=True,
    memory_enabled=True,
)

Key parameters:

  • decision_mode: submit or submit_payload
  • fail_mode: closed or open
  • outcome_reporting: optional automatic reporting after execution
  • memory_enabled: optional ingestion of tool-call decision events
  • model_selection: routing hint forwarded to BIGHUB context

Registering tools

Basic registration:

agent.tool("deploy_service", deploy_service)

With metadata extracted from arguments:

agent.tool(
    "sync_argocd_app",
    sync_argocd_app,
    domain="it_actions",
    actor="ops-agent",
    action_name="argocd_sync",
    metadata_from_args=lambda a: {
        "system": "argocd",
        "environment": a.get("environment"),
        "app": a.get("app"),
    },
)

Other common patterns:

  • value_from_args for cost-like signals
  • target_from_args for resource targeting
  • parameters_schema for custom JSON schema
  • register_tool(...) for the full lower-level API

Streaming

for event in agent.run_stream(
    messages=[{"role": "user", "content": "Sync checkout-service in Argo CD production"}],
    model="gpt-5.5",
):
    if event["type"] == "execution_event":
        print(event["event"]["tool"], event["event"]["status"])

run_stream() emits incremental model output and execution events, then finishes with the same final response shape as run().


Async

from bighub_openai import AsyncBighubOpenAI


async with AsyncBighubOpenAI(
    openai_api_key=os.getenv("OPENAI_API_KEY"),
    bighub_api_key=os.getenv("BIGHUB_API_KEY"),
    actor="ops-agent",
    domain="it_actions",
) as agent:
    agent.tool("rotate_credentials", rotate_credentials)
    response = await agent.run(
        messages=[{"role": "user", "content": "Rotate production database credentials"}],
        model="gpt-5.5",
    )

Human-in-the-loop approvals

result = agent.run_with_approval(
    messages=[{"role": "user", "content": "Grant temporary Okta admin access for 48h"}],
    model="gpt-5.5",
    on_approval_required=lambda ctx: {
        "resolution": "approved",
        "comment": "approved by on-call",
    },
)

When BIGHUB returns an approval-required decision, the adapter pauses execution and calls on_approval_required with the decision context.


Optional outcome reporting

If outcome_reporting=True, the adapter can automatically report successful execution, blocked execution, and tool errors back to BIGHUB after the tool decision resolves.

This is optional. The primary wedge is still the Better Decision before execution.


Optional decision memory

If memory_enabled=True, the adapter ingests structured events about tool calls, decisions, and outcomes into BIGHUB memory for future retrieval and pattern detection.


Compatibility

The modern path is BighubOpenAI / AsyncBighubOpenAI.

Compatibility aliases remain available:

  • GuardedOpenAI -> BighubOpenAI
  • AsyncGuardedOpenAI -> AsyncBighubOpenAI

API Reference

Method Description
tool(name, fn, **kwargs) Register a tool
register_tool(name, fn, ...) Register a tool with full options
list_tools() List registered OpenAI-compatible tool schemas
run(messages, model, ...) Run a complete evaluated interaction
run_stream(messages, model, ...) Run with streaming events
run_with_approval(messages, model, ..., on_approval_required) Run with approval callback support
close() Close the underlying BIGHUB client

Links


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

bighub_openai-0.1.0b2.tar.gz (30.0 kB view details)

Uploaded Source

Built Distribution

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

bighub_openai-0.1.0b2-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

File details

Details for the file bighub_openai-0.1.0b2.tar.gz.

File metadata

  • Download URL: bighub_openai-0.1.0b2.tar.gz
  • Upload date:
  • Size: 30.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for bighub_openai-0.1.0b2.tar.gz
Algorithm Hash digest
SHA256 74b70ad160a6700ead8ea8b1ade2cf898197b0482f57213c05f80251d7afed00
MD5 cedf0448434a6c1b54e5fe9c1e1f2fcc
BLAKE2b-256 616bbaafb0ac176098989206edc96eb3d6c18833db7dc967c809e22af8748fe9

See more details on using hashes here.

Provenance

The following attestation bundles were made for bighub_openai-0.1.0b2.tar.gz:

Publisher: publish-pypi.yml on bighub-io/bighub

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bighub_openai-0.1.0b2-py3-none-any.whl.

File metadata

  • Download URL: bighub_openai-0.1.0b2-py3-none-any.whl
  • Upload date:
  • Size: 22.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for bighub_openai-0.1.0b2-py3-none-any.whl
Algorithm Hash digest
SHA256 d3ce4b4bc1bcecc79af97e897dd9b37ca08694ae232e2a84ddcbc67a6fe9d168
MD5 b6f8367c7b229fbde2cc93a23dd686a1
BLAKE2b-256 832aae72a2e11cf2343aa05c00fee69e2402ab18d4c4ac07030d376417203fce

See more details on using hashes here.

Provenance

The following attestation bundles were made for bighub_openai-0.1.0b2-py3-none-any.whl:

Publisher: publish-pypi.yml on bighub-io/bighub

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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