Skip to main content

ory-openai-agents

Ory Agent Security for the OpenAI Agents SDK.

Authorizes every tool call against Ory Permissions via a tool-input guardrail, records invocations, and propagates user → agent identity — built on ory-argus.

pip install ory-openai-agents
from uuid import uuid4

from agents import Agent, Runner, function_tool
from ory_argus import OryAgentClient, with_hook_context
from ory_openai_agents import ory_tool_input_guardrail, ory_run_hooks

ory = OryAgentClient.from_env("openai-agents")
ory_guardrail = ory_tool_input_guardrail(client=ory)

@function_tool(tool_input_guardrails=[ory_guardrail])
def search(query: str) -> str:
    """Search the application's approved data source."""
    return search_backend(query)

agent = Agent(
    name="assistant",
    tools=[search],
)
with with_hook_context(ory, session_id=uuid4().hex):
    status = "error"
    try:
        result = Runner.run_sync(agent, "…", hooks=ory_run_hooks(client=ory))
        status = "ok"
    finally:
        ory.logger.activity(
            "session.end",
            status,
            attributes={"harness": "openai-agents"},
        )
        ory.flush_events(timeout=3)

Attach the guardrail to every side-effecting FunctionTool; installing the package alone does not gate tools. Hosted and built-in tools do not pass through this function-tool guardrail. Reuse one OryAgentClient for guardrails and run hooks. Scope each Runner invocation with with_hook_context so session, tool, and completion events share one Agent Security session ID. Prefer a stable job or conversation ID supplied by the deployment controller; generate a new opaque ID when each invocation is a distinct session.

MCP servers

Tools listed from an MCPServer are checked as McpServer:<server> and McpTool:<server>:<tool> instead of plain tools when the server carries the MCP guardrail:

from agents.mcp import MCPServerStdio, MCPServerStreamableHttp
from ory_openai_agents import guard_mcp_server

github = guard_mcp_server(
    MCPServerStreamableHttp(params={"url": "https://api.githubcopilot.com/mcp/"}, name="github"),
    client=ory,
)
playwright = guard_mcp_server(
    MCPServerStdio(params={"command": "npx", "args": ["-y", "@playwright/mcp"]}),
    client=ory,
)
agent = Agent(name="assistant", mcp_servers=[github, playwright])

guard_mcp_server appends ory_mcp_tool_input_guardrail(server) to the server's tool_input_guardrails, which the SDK copies onto every tool it lists from that server; do this before the run lists tools. Each call reports the name you gave the server, the server's raw tool name (the mcp_<server>__ prefix that include_server_in_tool_names adds is removed), and hashed fingerprints of the URL host or launched package, so Agent Security matches the server to its catalog whatever it is named. The SDK's default names (stdio: <command>, streamable_http: <url>) embed the launch command or URL, so an unnamed server is reported as unknown and identified only by its fingerprints; name servers explicitly (github) to see them by name in Observe. Fingerprints are hashes; no URL, command, or argument is sent. A plain ory_tool_input_guardrail() attached to an MCP server still gates its tools, but as plain tools.

  • observe (default): denied tools still run; a permission.observe_deny activity event is recorded.
  • enforce: denied tools are rejected — the model receives the denial and the tool never executes.

Credentials are read from the shared ~/.config/ory-agent-plugins/config.json, so a login from any Ory harness or ory-argus login is reused automatically.

For a headless Agent Security deployment, inject ORY_PROJECT_URL, ORY_AGENT_SECURITY_URL, and ORY_AGENT_API_KEY into the Agent process. Startup resolves the administrator-provisioned subject and opaque root from Agent Security, skips browser login, and keeps that context only in memory. ORY_AGENT_SUBJECT_ID and ORY_AGENT_ROOT_DELEGATION are compatibility overrides for older packages. The application still supplies the OpenAI Agents type; do not inject ORY_USER_OAUTH2_TOKEN.

Metadata

Release files for ory-openai-agents 1.9.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ory-openai-agents 1.9.2
File Size Uploaded Provenance Actions
ory_openai_agents-1.9.2.tar.gz 9.1 kB Without provenance Details for ory_openai_agents-1.9.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ory-openai-agents 1.9.2
File Interpreter ABI Platform Actions
ory_openai_agents-1.9.2-py3-none-any.whl Python 3 none any Details for ory_openai_agents-1.9.2-py3-none-any.whl

Total release size: 16.4 kB

Release files / ory_openai_agents-1.9.2.tar.gz

Download URL ory_openai_agents-1.9.2.tar.gz
Size 9.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f0f2c0737c6ecd126231cd036a9620b5a58236dc20cd3cce9128b29daad612fd
BLAKE2b-256 checksum
How to use checksums
7812e76ff8f33fdb49a9de251f8bb62bcc1e74f7d4d27e4bd1213601db931df1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / ory_openai_agents-1.9.2-py3-none-any.whl

Download URL ory_openai_agents-1.9.2-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b225e3092d2e4f1d16f7153e93c8fc6b62137bbfc64cf3446cc299721d5b9138
BLAKE2b-256 checksum
How to use checksums
3bffba2a1175f1bbae65f4af9fe8928b725f2d1410e88d4da3578864ed1d6392
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for ory-openai-agents 1.9.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.9.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page