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.0b3,<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"))

decision = last["decision"]
print(decision.get("salient_factors"))
print(decision.get("responsible_action_space"))

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.",
        "responsible_action_space": {
          "available": [],
          "constrained": [],
          "forbidden": [],
          "information_gathering": []
        },
        "salient_factors": [
          {
            "factor": "high_blast_radius",
            "severity": "warning",
            "reason": "Production admin access has broad impact."
          }
        ],
        "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
responsible_action_space Responsible action options grouped as available, constrained, forbidden, and information_gathering when returned by BIGHUB
salient_factors Decision-time factors BIGHUB identified as important for this tool call, such as high blast radius, weak verifier coverage, unavailable rollback, active incident, or open obligations
decision_packet Structured context used for the decision
decision_brain DecisionBrain reasoning summary and related signals

responsible_action_space and salient_factors are explanatory decision signals. They do not override runtime gating. Execution is still controlled by mode, can_run, needs_review, should_not_run, recommendation, allowed, and requires_approval.

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.0b3.tar.gz (30.8 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.0b3-py3-none-any.whl (22.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bighub_openai-0.1.0b3.tar.gz
  • Upload date:
  • Size: 30.8 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.0b3.tar.gz
Algorithm Hash digest
SHA256 2f86e7563b83e5129c5e2072c24e3c14ef6337a75577a66a42d87d6870afab01
MD5 3ed47a0d01588c2ac41924dbf9a92c78
BLAKE2b-256 b14b5f312de1002db2e4c0e3ff4d06c8cad9f4b5cf5a2d5a6adf5dd1719c99f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for bighub_openai-0.1.0b3.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.0b3-py3-none-any.whl.

File metadata

  • Download URL: bighub_openai-0.1.0b3-py3-none-any.whl
  • Upload date:
  • Size: 22.8 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.0b3-py3-none-any.whl
Algorithm Hash digest
SHA256 04aede2108a38d305231182a21ab402a236d7a8d6f4fa0155dd58b412bb07fe9
MD5 cfcf6910b2306e449149792ad979f06a
BLAKE2b-256 8da09c19bf3dce3a4a8dca1f9994a5bfcdd55478d7755e40c1a9fe9c1ae22eb6

See more details on using hashes here.

Provenance

The following attestation bundles were made for bighub_openai-0.1.0b3-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