OpenAI Agents + Tork Governance
Add AI safety guardrails to OpenAI Agents SDK. Validate inputs and outputs, block dangerous tool calls, and maintain compliance with automatic receipts.
I/O Governance
Validate all inputs and outputs
Tool Safety
Block dangerous tool calls
Streaming
Works with streaming responses
Compliance
Automatic audit receipts
Installation
Install Tork with OpenAI Agents SDK dependencies.
The Tork SDK includes OpenAI Agents adapters in tork.adapters.openai_agents.
TorkOpenAIAgentsMiddleware
Central middleware for governing OpenAI Agents.
The middleware wraps OpenAI Agents to evaluate inputs before processing and outputs after. Use wrap_agent() to add governance to any agent.
GovernedOpenAIAgent
Wrapper that adds governance to any OpenAI Agent.
GovernedOpenAIAgent wraps an agent and intercepts all runs. Exceptions are raised when policies are violated, allowing graceful error handling.
Tool Call Governance
Validate and block dangerous tool invocations.
Use check_tool_call() to validate tool calls before execution. Dangerous tools like shell execution are blocked automatically.
Blocked Tools (Default)
GovernedRunner
Run multiple agents with shared governance.
Use create_governed_runner() to create a runner that can execute any agent with governance. Useful for multi-agent workflows.
Manual Input/Output Processing
Direct governance for custom implementations.
Use process_input() and process_output() for fine-grained control when integrating with custom agent implementations.
Streaming Support
Governance with streaming responses.
For streaming responses, validate input before streaming starts, then validate the complete output after streaming completes.
Multi-Agent Workflows
Govern complex agent teams and routing.
Use shared middleware across multiple specialized agents. All agents are governed by the same policies, ensuring consistent safety.
Advanced Patterns
Async execution and compliance receipts
Best Practices
Wrap all agents with shared middleware
Use a single middleware instance to ensure consistent governance across your system.
Validate tool calls before execution
Use check_tool_call() for sensitive operations. Dangerous tools are blocked by default.
Handle exceptions gracefully
Catch InputBlockedError, OutputBlockedError, and ToolCallBlockedError for user-friendly errors.
Use async for concurrent agents
The run_async() method enables efficient parallel execution of multiple agents.
Store compliance receipts
Export receipts to your audit system. Each receipt includes a cryptographic hash for integrity.
Exception Types
| OpenAIAgentGovernanceError | Base exception for all governance errors |
| InputBlockedError | Raised when user input violates policies |
| OutputBlockedError | Raised when agent output violates policies |
| ToolCallBlockedError | Raised when a tool call is blocked |
Imports Reference
Next Steps
Configure policies in the dashboard and explore other framework integrations.