Skip to content

Use with OpenAI Agents

Install (the OpenAI Agents framework hook is the only one that needs a vendor package — openai-agents):

shell
pip install nullrun openai-agents

Wrap the Runner.run_sync call (or any sync / async runner) with @protect. The runtime + openai-agents RunHooks / RunStreamedHooks patch are attached lazily on the first @protect call:

openai_agents_protect.py
from agents import Agent, Runner

from nullrun import protect


@protect
def ask(prompt: str) -> str:
    agent = Agent(
        name="assistant",
        instructions="Answer in one sentence.",
    )
    result = Runner.run_sync(agent, prompt)
    return result.final_output


print(ask("What is the capital of France?"))

@protect tracks every tool call the agent makes and halts the run if the workflow exceeds budget, hits a sensitive tool, or is rate-limited by the policy.

See also