Integrations
OpenAI Agents Integration
OpenAI Agents and Swarm multi-agent governance patterns.
OpenAI Agents Integration
Overview
AgentTrust provides agent_guard, OpenAIAgentsGuard, and SwarmGuard for the OpenAI Agents SDK and Swarm multi-agent patterns.
Tier: Team+
Why It Matters
OpenAI's agent framework runs tool-use loops and multi-agent handoffs. Guards validate outputs at handoff boundaries.
Prerequisites
pip install agentrust-py
# Team+ API key
# openai-agents or swarm packageStep-by-Step Guide
The decorator is re-exported under a different name
agent_guard is exported at package level as openai_agent_guard to avoid a name
clash. from agentrust_sdk import agent_guard raises ImportError. Use the aliased
name, or import the original from the adapter module.
from agentrust_sdk import openai_agent_guard, OpenAIAgentsGuard, SwarmGuard
# equivalently: from agentrust_sdk.adapters.openai_agents import agent_guard
# Single agent — guard.run() awaits Runner.run() and validates the result
guard = OpenAIAgentsGuard(
agent_id="openai-agent",
base_url="http://127.0.0.1:8765", # adapter default is :8000
)
result = await guard.run(my_agent, "process invoice #42")
# Synchronous callers:
result = guard.run_sync(my_agent, "process invoice #42")
# Swarm multi-agent — pass the Swarm client, the agent, and the message list
swarm_guard = SwarmGuard(agent_id="swarm-orchestrator")
response = swarm_guard.run(swarm_client, agent, [{"role": "user", "content": query}])
# Decorator style — wraps your own runner function (sync or async)
@openai_agent_guard(agent_id="my-openai-agent")
async def run_agent(query: str):
return await Runner.run(agent, query)Examples
For basic OpenAI SDK (non-Agents), use auto_instrument() — see OpenAI Direct example.
Best Practices
- Use
SwarmGuardfor multi-agent handoff validation - Distinguish OpenAI SDK (
auto_instrument) from OpenAI Agents SDK (this adapter) - Set per-agent IDs in swarm configurations
Common Mistakes
- Using
auto_instrument()for OpenAI Agents SDK (different package) - Missing Team API key
from agentrust_sdk import agent_guard— the exported name isopenai_agent_guard
Troubleshooting
| Issue | Fix |
|---|---|
RuntimeError: [AgentTrust] OpenAI Agents adapter requires Team tier… | Upgrade to Team tier (this is not a TierGateError) |
| Handoff not validated | Call SwarmGuard.run(client, agent, messages) rather than client.run(...) |
ImportError: cannot import name 'agent_guard' | Import openai_agent_guard from agentrust_sdk |