Add fail-closed OpenAI Agents adapter - #36
Conversation
|
Warning Review limit reached
Next review available in: 33 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (10)
Summary by CodeRabbit
WalkthroughChangesOpenAI Agents SDK integration
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant Application
participant OpenAIAgentsToolPolicy
participant FunctionTool
participant BoundToolGate
participant ApprovalStore
Application->>OpenAIAgentsToolPolicy: protect FunctionTool
OpenAIAgentsToolPolicy->>FunctionTool: install input guardrail
FunctionTool->>OpenAIAgentsToolPolicy: provide raw tool arguments
OpenAIAgentsToolPolicy->>BoundToolGate: evaluate policy and approval
OpenAIAgentsToolPolicy->>ApprovalStore: store or retrieve call fingerprint
OpenAIAgentsToolPolicy->>FunctionTool: allow or block execution
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.github/workflows/ci.yml:
- Around line 463-472: The contract dependency installation must reference an
existing requirement artifact consistently. In .github/workflows/ci.yml lines
463-472, update the cache dependency path and install command to use the chosen
requirement filename; in requirements-openai-agents.txt lines 1-2, either
replace it with a fully hashed lock file named requirements-openai-agents.lock,
or rename it consistently and remove --require-hashes from the workflow,
ensuring all direct and transitive requirements are covered.
- Around line 473-474: Update the “Test exact OpenAI Agents SDK contract” step
in the CI workflow to also execute examples/openai_agents_guardrail_demo.py
after installing the SDK, while preserving the existing integration test command
so this SDK-specific job validates both the adapter contract and the example.
In `@docs/OPENAI_AGENTS.md`:
- Around line 15-17: Limit the documented openai-agents support range to the
tested version by updating the SDK dependency declaration and corresponding
documentation from the broad >=0.18.3,<0.19 range to exactly 0.18.3. Keep the
existing contract-test setup aligned with that pinned version.
In `@integration_tests/test_openai_agents_sdk.py`:
- Around line 100-112: Add a concise comment immediately before the
on_invoke_tool assertion explaining that direct adapter calls bypass
input-guardrail enforcement, while the SDK runner enforces the blocked
raise_exception result; preserve the existing assertion and behavior.
In `@src/samsarix_ethics/openai_agents.py`:
- Around line 29-79: Add a lifecycle method such as forget or complete to
OpenAIAgentsApprovalStore and implement it in _InMemoryApprovalStore to remove
the (tool_name, tool_call_id) entry safely under the existing lock. Invoke this
method after the guardrail resolves a reviewed call, and ensure the
MAX_PENDING_OPENAI_APPROVALS failure is recorded or surfaced rather than
swallowed by _needs_approval.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: b87cde6d-9da5-41d9-9bd5-9a121d432442
⛔ Files ignored due to path filters (1)
requirements-openai-agents.lockis excluded by!**/*.lock
📒 Files selected for processing (18)
.github/workflows/ci.ymlCHANGELOG.mdREADME.mdROADMAP.mdSECURITY.mddocs/ADOPTION.mddocs/API.mddocs/ARCHITECTURE.mddocs/OPENAI_AGENTS.mddocs/PRODUCTIZATION.mdexamples/openai_agents_guardrail_demo.pyintegration_tests/test_openai_agents_sdk.pypyproject.tomlrequirements-openai-agents.txtsrc/samsarix_ethics/__init__.pysrc/samsarix_ethics/openai_agents.pytests/test_openai_agents.pytests/test_public_api.py
What changed
FunctionToolobjectsreviewoutcomes into native SDK interruptions and re-enforce with fresh application facts immediately before executionopenai-agents==0.18.3hashed integration lane, a no-network example, and public architecture/security/adoption documentationWhy
The core library had strong framework-neutral tool gating but no public, reproducible integration with a popular agent runtime. This closes that credibility and adoption gap without adding runtime dependencies to the base package or overstating unsupported hosted/built-in execution paths.
Validation
python -m pytest -q— 517 passed, 95.75% branch-aware coveragepython -m ruff format --check .python -m ruff check .python -m mypyopenai-agents==0.18.3graphtwine checkagentsdistribution installed and no unconditional dependenciesBoundaries
This adapter covers strict top-level Python
FunctionToolobjects only. Hosted and built-in tools, MCP-hosted tools, handoffs, namespaces, andAgent.as_tool()remain outside this interception path and are documented as such.