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.

  • 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.3.0

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.3.0
File Size Uploaded
ory_openai_agents-1.3.0.tar.gz 5.6 kB Details

Built distribution (wheel)

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

Total release size: 10.1 kB

Release files / ory_openai_agents-1.3.0.tar.gz

Download URL ory_openai_agents-1.3.0.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
69f61a914adcae020a49607e9e94f4c6ac32c805efc59b44f1727faaaf61773b
BLAKE2b-256 checksum
How to use checksums
c279ed2fab97e9f6feca3f66bb85f9cf96c8efb1e288887868d5416c8a84c1d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","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.3.0-py3-none-any.whl

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

Release history Release notifications | RSS feed

1.4.8

2 release files

1.4.7

2 release files

1.4.6

2 release files

1.4.5

2 release files

1.4.4

2 release files

1.4.3

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.1

2 release files

This release

1.3.0 This release

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.14.0

2 release files

0.13.9

2 release files

0.11.1

1 release file

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