Skip to content

Commit 2ab584c

Browse files
fix: Address review comments
- Add output_info=None when guardrail passes (fixes TypeError) - Clarify that tool policies require manual check_tool() calls - Add Tool Policy Enforcement section to README
1 parent 4a37fd7 commit 2ab584c

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

src/agents/contrib/README.md

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ Kernel-level guardrails and policy enforcement for OpenAI Agents SDK using [Agen
44

55
## Features
66

7-
- **Output Guardrails**: Block dangerous patterns in agent outputs
8-
- **Input Validation**: Filter malicious inputs before processing
9-
- **Tool Control**: Limit which tools agents can use
10-
- **Rate Limiting**: Cap tool invocations per run
7+
- **Output Guardrails**: Block dangerous patterns in agent outputs (automatic)
8+
- **Input Validation**: Filter malicious inputs before processing (automatic)
9+
- **Tool Policy**: Define allowed/blocked tools (requires manual `check_tool()` calls)
1110
- **Violation Handling**: Callbacks for policy violations
1211

1312
## Installation
@@ -27,8 +26,8 @@ from agents.contrib import create_governance_guardrail
2726
# Create guardrail with simple config
2827
guardrail = create_governance_guardrail(
2928
blocked_patterns=["DROP TABLE", "rm -rf", "DELETE FROM"],
30-
blocked_tools=["shell_execute"],
31-
max_tool_calls=10,
29+
blocked_tools=["shell_execute"], # Use with check_tool() for enforcement
30+
max_tool_calls=10, # Use with check_tool() for enforcement
3231
)
3332

3433
# Create agent with guardrail
@@ -126,6 +125,29 @@ else:
126125
result = await Runner.run(agent, user_input)
127126
```
128127

128+
### Tool Policy Enforcement
129+
130+
Tool policies (`blocked_tools`, `allowed_tools`, `max_tool_calls`) are not automatically
131+
enforced during agent execution. Use `check_tool()` in your tool implementations:
132+
133+
```python
134+
from agents.contrib import GovernanceGuardrail, GovernancePolicy
135+
136+
policy = GovernancePolicy(
137+
blocked_tools=["dangerous_tool"],
138+
max_tool_calls=10,
139+
)
140+
141+
guardrail = GovernanceGuardrail(policy)
142+
143+
# In your tool implementation:
144+
def my_tool(name: str, args: dict):
145+
violation = guardrail.check_tool(name)
146+
if violation:
147+
raise ValueError(f"Tool blocked: {violation.description}")
148+
# ... execute tool
149+
```
150+
129151
## Integration with Agent-OS Kernel
130152

131153
For full kernel-level governance:

src/agents/contrib/_governance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class GuardrailFunctionOutput:
152152
tripwire_triggered=True,
153153
)
154154

155-
return GuardrailFunctionOutput(tripwire_triggered=False)
155+
return GuardrailFunctionOutput(output_info=None, tripwire_triggered=False)
156156

157157
def check_tool(self, tool_name: str) -> Optional[PolicyViolation]:
158158
"""Check if a tool is allowed by policy.

0 commit comments

Comments
 (0)