LabBeginner~10 min

Connect OpenAI Agents SDK workflow

SupportedPython 3.12+OpenAI Agents SDK 0.22.2Agents RuntimeMODEL_CALL + TOOL_CALL

Connect a real OpenAI agent, let it use a local policy lookup tool, and review its model turns and activity record in AIGP.

Last updated
Execution evidence SUCCEEDED
Policy Validation Agentobserved
model turn 1observed
lookup_policyobserved
model turn 2observed

2 MODEL_CALL · 1 TOOL_CALL · 2 WORKFLOW_STEP events

Overview

Observe the run. Keep the Agents SDK in control.

The lab uses one OpenAI agent and one real local function tool. The OpenAI Agents SDK owns model routing, tool execution, output, and exceptions. Platform receives a separate, one-way record of completed runtime boundaries.

You will learn

How public Agents SDK lifecycle hooks map an agent, model calls, and a real tool call to runtime evidence.

You will build

One correlated execution for one Runner invocation, with no custom SDK internals or tracing interception.

Architecture

A small agent with one actual tool call.

Execution plane

OpenAI Agents SDK

Runs the agent, model turns, and local function tool.

Evidence plane

BHANUJ Agents Runtime

Records ordered lifecycle evidence only.

Agent startedModel 1lookup_policyModel 2Agent completed

The first model turn is publicly configured with named tool_choice="lookup_policy". The SDK resets that choice after the local tool runs, then performs its normal final model turn.

Prerequisites

What you need.

  • Python 3.12 or later and pip.
  • An OpenAI API key and an available model.
  • The BHANUJ OSS repository only when you want to send runtime evidence.

Run locally

Run the agent without BHANUJ OSS first.

The lab pins openai-agents==0.22.2. It needs an OpenAI API key, but no database, cloud infrastructure, or Detailed Tool Calls platform connection.

terminal
git clone https://github.com/Bhanuj-AI/labs.git
cd labs/agent-frameworks/openai/openai-agents-tool-intg
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
export OPENAI_API_KEY=...
export OPENAI_MODEL=gpt-5-mini
terminal
python app.py
expected model result
Agent result: Policy POL-100: ACTIVE.

Enable evidence

Connect the unchanged run to BHANUJ OSS.

Start BHANUJ OSS in development mode, then set the three runtime-scope variables and run the same app. The OpenAI application remains independently owned by the SDK.

terminal · AI Governance OSS
cd /path/to/ai-governance-oss
AI_GOVERNANCE_AUTH_MODE=development \
  uv run uvicorn ai_governance.api.app:app --reload
terminal · lab repository
export AI_GOVERNANCE_BASE_URL=http://localhost:8000
export AI_GOVERNANCE_ORGANIZATION_ID=org_default
export AI_GOVERNANCE_PROJECT_ID=project_default
python app.py
expected governed output
Agent result: Policy POL-100: ACTIVE.
BHANUJ execution ID: <execution-id>
BHANUJ evidence status: SUCCEEDED
Failure isolation: evidence delivery is fail-open and uses one short, non-retrying attempt. An unavailable API cannot change the local tool result, SDK routing, model output, or application exception—and it never fabricates successful evidence.

Inspect the execution

One execution ID connects the full run.

The CLI prints the execution ID after the start request succeeds. Find that exact ID in Agents Runtime to inspect the ordered evidence below.

Agents Runtime timeline SUCCEEDED
  1. 1Policy Validation Agent · Step StartedWORKFLOW_STEP
  2. 2gpt-5-mini · Model Completed · 1MODEL_CALL
  3. 3lookup_policy · Tool CompletedTOOL_CALL
  4. 4gpt-5-mini · Model Completed · 2MODEL_CALL
  5. 5Policy Validation Agent · Step CompletedWORKFLOW_STEP

The execution also contains the platform-generated EXECUTION_STARTED and successful completion records. No prompt text, tool arguments, tool output, model output, reasoning, or raw SDK payload is sent.

OpenAI Agents SDK references

Ready to run it?

Fork the lab, run the real agent and local tool, then enable runtime evidence when BHANUJ OSS is available.