This page is a complete, implementation-oriented guide for adding MachineID enforcement to OpenAI Agents: systems where a model can request tool calls and your application executes them.
- Exact enforcement boundaries for hosted agent execution
- A tool-server gating model (the canonical integration point)
- Device identity patterns for multi-tool and multi-surface setups
- Fail-closed behavior and stop latency design
- A “soft guardrails” tutorial
- A usage metering guide
- A best-effort policy pattern
Everything reduces to one invariant:
Register. Validate. Work.
If validation fails, work does not begin.In OpenAI Agents, your strongest “work begins” boundary is when your application is about to execute a tool call.
- Add one hard gate to your tool server
- Revoke that device in the dashboard
- Confirm the next tool call is denied (fail closed)
The modern OpenAI direction is the Agents SDK paired with the Responses API tool-calling model: a model requests tools, and your application executes them and returns outputs. :contentReference[oaicite:3]{index=3}
- You cannot rely on in-process flags inside a hosted agent runtime
- You can always gate your own tool execution server-side
- Revoke/disable becomes effective at the next tool boundary
Tool calling is a multi-step interaction: you send tools the model may call, the model requests a tool, your application executes code, then you send tool results back. :contentReference[oaicite:4]{index=4}
- Validate immediately before executing a tool function
- Validate again immediately before high-risk side effects (payments/email/writes)
- Fail closed on timeout/network failure
- Tool boundary (mandatory): validate before each tool executes
- Side-effect boundary: validate immediately before irreversible actions
- Resume boundary: validate before resuming paused/delayed execution
Revoke/disable is realized on the next validate. In Agents systems, that typically means: the next time the model requests a tool call and your server is about to execute it.
- Validate before every tool call
- Validate at loop re-entry points (if you have server-side loops)
- Validate before side effects even if the tool is already gated
OpenAI has deprecated the Assistants API and published a sunset date of August 26, 2026. :contentReference[oaicite:5]{index=5} For new builds, the Responses API + Agents SDK direction is the safer default. :contentReference[oaicite:6]{index=6}
pip install machineid-ioimport os
from machineid import MachineID
m = MachineID.from_env()
DEVICE_ID = os.getenv("MACHINEID_DEVICE_ID", "openai-agent:prod:tool-server:01")
def must_be_allowed(boundary: str):
m.register(DEVICE_ID) # idempotent
d = m.validate(DEVICE_ID)
if not d["allowed"]:
raise RuntimeError(f"Denied at {boundary}: {d.get('code')} {d.get('request_id')}")
return dregister(device_id),validate(device_id)list_devices(),usage()revoke(device_id),unrevoke(device_id)(alias:restore)remove(device_id)
If you want minimal dependencies, call the canonical endpoints directly using the x-org-key header.
POST https://machineid.io/api/v1/devices/register
Headers:
x-org-key: org_...
Body:
{"deviceId":"openai-agent:prod:tool-server:01"}POST https://machineid.io/api/v1/devices/validate
Headers:
x-org-key: org_...
Body:
{"deviceId":"openai-agent:prod:tool-server:01"}def guarded_tool(tool_fn):
def _inner(*args, **kwargs):
must_be_allowed("before_tool_call")
return tool_fn(*args, **kwargs)
return _innerdef commit_side_effect(do_effect):
must_be_allowed("before_side_effect")
return do_effect()openai-agent:{env}:{surface}:{instance}Examples:
openai-agent:dev:tool-server:01openai-agent:prod:tool-server:03openai-agent:prod:payments:01openai-agent:prod:email:01
- Device IDs are identifiers, not secrets
- Map devices to execution surfaces you want to stop independently
- Short client timeout (for example, 1–3 seconds)
- Timeout/network failure treated as not allowed
- Tool does not execute; return an error to the agent
openai-agent:dev:tool-server:01— gates all tools for a single environmentopenai-agent:dev:payments:01— isolate high-risk side effectsopenai-agent:dev:email:01— isolate outbound messaging
- 10 tool servers:
openai-agent:prod:tool-server:01…:10 - 8 specialized tool surfaces:
openai-agent:prod:payments:01…:04,openai-agent:prod:email:01…:04 - 7 event/cron triggers:
openai-agent:prod:cron:01…:07
- Autoscaling tool servers / multi-region execution
- Per-tenant or per-workflow tool surfaces
- High fan-out tool usage under load
- Prefer per-replica identity (avoid one fleet device)
- Validate before tools + before side effects
- No fallback authority paths
The console at machineid.io/dashboard is external to the agent runtime, so you can intervene from anywhere.
- Does not change device revoked/restored state
- Causes validate to deny across the org
- Takes effect at the next validate boundary (tool execution)
- Proceed anyway on validation timeout or error
- Cache “allowed” decisions for long windows
- Validate only once at startup
- Fallback to internal flags as alternate authority
- Your tool server is not validating at tool boundaries
- Add validate before every tool and before every side effect
- Inspect
codeandrequest_id - Confirm device is not revoked; confirm org-wide disable is not enabled
- Confirm device cap is not exceeded (new unique device IDs)
I have an OpenAI Agents / Responses API integration where the model calls tools and my server executes them.
Constraints:
- I will gate tool execution using MachineID (register + validate).
- Fail closed with short timeout.
- Device ID pattern: openai-agent:{env}:{surface}:{instance}
Required boundaries:
1) Before every tool call
2) Before irreversible side effects (payments/email/writes)
3) Before resuming delayed/paused work
Please provide:
- Exact code locations to add enforcement
- Copy/paste snippets (SDK and direct HTTP variants)
- A test plan: revoke device, restore, org-wide disable, verify stops at next tool boundary- Tool execution is gated (validate before tool runs)
- Side effects are gated (validate before irreversible actions)
- Fail-closed policy (timeouts deny)
- Denials logged (include request_id)
- Device model supports surgical revoke
- OpenAI Agents SDK guide: platform.openai.com/docs/guides/agents-sdk
- Tool calling (function calling): platform.openai.com/docs/guides/function-calling
- Responses API reference: platform.openai.com/docs/api-reference/responses
- Assistants deprecation notice: platform.openai.com/docs/deprecations
- MachineID Python SDK: github.com/machineid-io/python-sdk