8000 Add Option to Run Guardrails Before Agent · Issue #866 · openai/openai-agents-python · GitHub
[go: up one dir, main page]

Skip to content
Add Option to Run Guardrails Before Agent #866
Closed
@DanielHashmi

Description

@DanielHashmi

Please read this first


Describe the feature

👉 What is the feature you're requesting?
I’m requesting an option in the SDK to control the execution mode of guardrails. Specifically, I propose adding a way to choose whether guardrails run:

  • In parallel with the agent (the current default behavior)
  • Sequentially, where the agent only starts if the guardrails pass

👉 Examples:
If guardrail_mode="sequential" or guardrails_first=True is set:

  • Guardrails would run and complete first.
  • Only if the guardrails pass then the agent start generating tokens.

👉 Why is this useful?

  • In the current design, guardrails and the agent run together using asyncio.gather. This is great for low latency, but can cause unnecessary cost if a guardrail trips, because by the time it does, the agent may have already generated tokens.
  • The proposed option would help in cases where cost efficiency is a priority (e.g., expensive models, stricter validation requirements).
  • This would give developers control over the trade-off between speed and cost protection, depending on their use case.

👉 Important note:
This request is not a complaint about the current design, the current parallel execution is great for most use cases where speed is the top priority. This is about adding flexibility for cost-sensitive scenarios.


Thank you for considering this feature request!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0