How to Add Audit Logging and Governance to the OpenAI Agents SDK
The OpenAI Agents SDK is OpenAI’s framework for multi-agent systems with tools, handoffs and guardrails. Its tracing records runs, agent spans and handoffs. That is not a policy decision log, it isn’t tied to the end user’s identity, and it doesn’t check one agent’s scope against another’s.
Agentic Control Plane (ACP) adds those: a policy check on each tool call, an identity-attributed audit log, per-agent policy and budget limits. You don’t change your Agent, Runner or handoff structure.
Starter, 5-minute install. For the proxy, you don’t install anything. Point the Agents SDK’s OpenAI client at
https://api.agenticcontrolplane.com/v1with yourACP_API_KEY, and addx-acp-agent-nameheaders for per-agent attribution. For per-tool checks, use the guardrail pattern below. See the governance model or the frameworks index.
Agent-level audit vs org-level audit
This is different from OpenAI’s Admin API audit log. That log is org-level. It records API key creation, usage caps and admin actions. ACP’s log is agent-level: it records each tool call and each LLM call, per agent and per user. The two have different audiences.
The OpenAI Agents SDK is also separate from:
- Codex CLI. A terminal app, governed through hooks and MCP.
- Assistants API. The older thread-based API. Tools run server-side at OpenAI, so they are hard to instrument.
- AgentKit’s Agent Builder. A visual builder that is being wound down. OpenAI announced in June 2026 that Agent Builder and Evals shut down on November 30, 2026, with the Agents SDK as the recommended migration path.
If you run the agents Python library in your own infrastructure, this is the right page.
Two ways to connect
Pick based on what you want to check.
| Pattern | Where it fires | Use when |
|---|---|---|
| Tool-layer guardrails (recommended for SDK code) | Before and after each tool call, through the SDK’s tool_input_guardrails and tool_output_guardrails |
You want a decision, output redaction and an audit row for each tool call |
| LLM proxy | On every chat-completion request, through AsyncOpenAI(base_url=ACP) |
You want LLM-call audit, per-agent attribution with x-acp-agent-name, and budget and rate limits at the model layer |
You can use both. They catch different events. The starter at acp-governance-sdks/examples/starters/openai-agents-sdk shows the tool-layer pattern.
Pattern 1: tool-layer guardrails
OpenAI Agents SDK v0.14+ accepts tool_input_guardrails and tool_output_guardrails on @function_tool. ACP’s Python SDK gives you three functions (pre_tool_use, post_tool_output, set_context) that you wire into a guardrail pair:
import os
from acp_governance import configure, post_tool_output, pre_tool_use, set_context
from agents import (
Agent, Runner,
ToolGuardrailFunctionOutput, ToolInputGuardrailData, ToolOutputGuardrailData,
function_tool, tool_input_guardrail, tool_output_guardrail,
)
configure(base_url="https://api.agenticcontrolplane.com")
@tool_input_guardrail(name="acp_pre_tool_use")
def acp_input_guardrail(data: ToolInputGuardrailData) -> ToolGuardrailFunctionOutput:
allowed, reason = pre_tool_use(data.context.tool_name, data.context.tool_arguments)
if not allowed:
return ToolGuardrailFunctionOutput.reject_content(
message=f"tool_error: {reason or 'denied by ACP policy'}",
)
return ToolGuardrailFunctionOutput.allow()
@tool_output_guardrail(name="acp_post_tool_output")
def acp_output_guardrail(data: ToolOutputGuardrailData) -> ToolGuardrailFunctionOutput:
result = post_tool_output(data.context.tool_name, data.context.tool_arguments, data.output)
if result and result.get("action") == "redact" and "modified_output" in result:
return ToolGuardrailFunctionOutput.reject_content(message=str(result["modified_output"]))
if result and result.get("action") == "block":
return ToolGuardrailFunctionOutput.reject_content(
message=f"tool_error: {result.get('reason', 'blocked by ACP policy')}",
)
return ToolGuardrailFunctionOutput.allow()
ACP_GUARDRAILS = {
"tool_input_guardrails": [acp_input_guardrail],
"tool_output_guardrails": [acp_output_guardrail],
}
@function_tool(**ACP_GUARDRAILS)
def lookup_record(id: str) -> dict:
"""Look up a record by ID."""
return db.records.find_one({"id": id})
def main():
set_context(
user_token=os.environ["ACP_USER_TOKEN"],
agent_name="my-agent",
agent_tier="background",
)
agent = Agent(
name="my-agent",
instructions="You are an ACP-governed agent.",
model="gpt-4o-mini",
tools=[lookup_record],
)
return Runner.run_sync(agent, "Look up record id=abc-123.", max_turns=6)
With this in place:
- Each tool call is checked before it runs. If ACP denies it, the tool doesn’t fire and the model sees
tool_error: <reason>. Anaskdecision comes back the same way, as a denied call. Approve it on the console, then re-run. - Each tool call is audited after it runs. The output is logged and scanned for PII and secrets, and redacted if policy says so. Every tool call has its own decision and audit row, attributed to the user token set with
set_context. - You don’t pass the token through your tool functions.
set_contextattaches the verified end-user token to every governed call. - Denials show up in SDK traces. The code uses the SDK’s own
ToolGuardrailFunctionOutput.allow()and.reject_content(...).
If ACP is unreachable, the SDK lets the call through and marks it as unchecked. A policy deny, when the check does run, always blocks.
This is the recommended pattern for SDK code in your infrastructure. The starter folder is a 30-line template to copy.
Pattern 2: LLM proxy
To audit LLM calls, attribute them per agent with x-acp-agent-name, and enforce budget and rate limits at the model layer, point the SDK’s OpenAI client at ACP’s OpenAI-compatible proxy:
from agents import Agent, Runner, set_default_openai_client
from openai import AsyncOpenAI
import os
# Route Agents SDK through ACP's OpenAI-compatible proxy
client = AsyncOpenAI(
base_url="https://api.agenticcontrolplane.com/v1",
api_key=os.environ["ACP_API_KEY"],
)
set_default_openai_client(client)
researcher = Agent(
name="researcher",
instructions="...",
tools=[web_search, hn_search],
)
writer = Agent(
name="writer",
instructions="...",
tools=[],
)
result = await Runner.run(researcher, "Research X and hand off to writer")
Every LLM call from every agent goes through ACP. Each shows up as client.name: "openai-agents-sdk" in your activity log.
Per-agent attribution
To make each Agent a separate row in the ACP dashboard, build one AsyncOpenAI client per agent with default_headers, and assign it to that agent’s model settings:
def make_client(agent_name: str) -> AsyncOpenAI:
return AsyncOpenAI(
base_url="https://api.agenticcontrolplane.com/v1",
api_key=os.environ["ACP_API_KEY"],
default_headers={"x-acp-agent-name": agent_name},
)
# One client per agent, each tagged with x-acp-agent-name
researcher_client = make_client("researcher")
writer_client = make_client("writer")
Pass each client to its Agent through the SDK’s model configuration, or use set_default_openai_client per run. Each x-acp-agent-name appears on the Agents page as its own row, with its own policy, rate limits and budget.
How the proxy works
The AsyncOpenAI client sends chat-completion requests to ACP’s OpenAI-compatible endpoint. ACP then:
- Verifies identity (the
gsk_key plus the optionalx-acp-agent-nameheader). - Runs policy, content safety, budget and rate-limit checks.
- Forwards the request to the configured upstream model (OpenAI, Anthropic, local).
- Writes a structured audit record.
The SDK’s guardrails run inside the SDK, before a request reaches the OpenAI client. ACP’s proxy policy runs after that. The stricter one wins: a guardrail denial stops the call before ACP sees it, and an ACP denial comes back as an API error.
Mapping to ACP (Pattern 2, proxy)
| OpenAI Agents SDK | ACP with the proxy |
|---|---|
Agent(name=...) |
agent_name through the x-acp-agent-name header, shown as its own row on the Agents page |
Agent.tools |
Tool calls are audited as part of the LLM call that emits them. For a decision per tool call, add Pattern 1. |
handoffs |
Each agent’s LLM calls appear independently. Showing a handoff as a link in a chain is on the roadmap. |
Runner.run() |
Root of the logical chain. The origin identity is the owner of the gsk_ key. Pattern 1 attributes calls to the user token instead. |
| Guardrails | Run before ACP, and the proxy can’t see their decisions. Guardrails that call ACP (Pattern 1) are logged by ACP. |
Verify it worked
Run any multi-agent scenario. Open cloud.agenticcontrolplane.com/activity. Within 5 seconds you should see rows with client.name: "openai-agents-sdk", one per LLM call when you use the proxy, and one per tool call when you use the guardrails. If you set x-acp-agent-name per agent, each agent appears as its own row with its own policy history.
What you’ll see in the dashboard
cloud.agenticcontrolplane.com/agents shows each x-acp-agent-name as its own row. Policy denials are rows too. With the proxy, a handoff between agents appears as separate LLM calls.
What ships today
- Pattern 1: tool-layer guardrails through the
acp-governancePython SDK. A pre-check and a post-check on each tool call, user identity throughset_context, and the SDK’s nativetool_input_guardrailsandtool_output_guardrails. The starter folder has a runnable template. - Pattern 2: the OpenAI proxy through
AsyncOpenAI(base_url=...), with per-agent attribution throughx-acp-agent-name. It works with any Agent, Runner, handoff or guardrail setup.
Limitations
- Tracing is separate. OpenAI traces go to the OpenAI dashboard and ACP audit logs are independent. They serve different audiences.
- Handoffs are not assembled into delegation chains. Each agent’s calls are recorded independently.
With the proxy only (Pattern 2):
- Tool calls are audited at the LLM-call level. Tool invocations emitted in one model response share that call’s policy decision.
- Guardrails are invisible to the proxy. They run first, inside the SDK, so ACP only sees calls that got past them.
- The origin identity is the workspace key owner. To attribute calls to the end user, use Pattern 1, or wait for the planned native adapter.
Troubleshooting
Nothing appears in the dashboard. Check that base_url ends in /v1. Test it with curl -s https://api.agenticcontrolplane.com/v1/models -H "Authorization: Bearer $ACP_API_KEY", which should return 200 with a model list.
All agents show up as one row. Per-agent attribution needs default_headers={"x-acp-agent-name": agent_name} on each agent’s AsyncOpenAI client. Without it, every agent lands on one profile.
“Why don’t my agent actions show up in OpenAI’s Admin API audit log?” They won’t. That log covers org-level events such as API key changes and usage caps. Per-call audit is ACP’s job.
Guardrails fire but ACP doesn’t. Expected with the proxy. Guardrails run first, inside the SDK, and if one denies the call the request never reaches ACP. Check the SDK’s guardrail logs.
Handoffs show as separate LLM calls instead of linked. That is how it works today. The planned native adapter will link them as a delegation chain.
Rate limits fire on runs with many handoffs. Each LLM call counts against the limit, so a handoff-heavy run can hit it fast. Raise the limit in the dashboard or reduce handoff depth.
Does this work with AgentKit? Partly. AgentKit’s hosted runtime limits what you can instrument. ACP covers LLM calls that leave AgentKit for a base URL you configure. Handoffs running on OpenAI’s infrastructure can’t be instrumented from outside.
Related integrations
- Anthropic Agent SDK: TypeScript adapter with per-tool-call interception
- OpenAI Codex CLI: OpenAI’s terminal coding agent (hooks and MCP)
- CrewAI: Python multi-agent framework, same proxy pattern
- LangGraph: graph-based multi-agent
- Agent-to-Agent governance: the delegation chain spec
- What is an Agent Delegation Chain?: background