OpenAI Agents SDK tools let a model request controlled capabilities. Function tools wrap your Python functions and derive schemas from types and documentation; hosted tools provide platform-managed capabilities such as web or file search when supported. Your handler still owns identity, validation, timeout, authorization, redaction, and side-effect safety.
You will add a read-only SupportOps tool, inspect its boundary, and choose between application-hosted and provider-hosted capabilities.
read_tool.py:
The model chooses ticket_id; trusted host context chooses the tenant. The handler returns only fields required for the task.
Use a hosted tool when the platform capability matches your trust and data requirements and removes infrastructure you do not need to own. Use a function tool when you need private application logic, strict domain contracts, custom policy, or full control of data movement.
Before enabling any hosted tool, verify current documentation, data handling, approval options, regional/compliance fit, and trace behavior. Never assume “hosted” means automatically safe for your data.
Unit-test the function directly for valid, invalid, missing, and cross-tenant IDs. At the agent level, assert that a ticket question produces a get_ticket call with the correct argument and that unrelated questions do not.
Failure injection: Ask for T-100 while the runtime context contains another tenant. The tool must return not found; it must never trust a tenant ID supplied by the model.
Use needs_approval, idempotency keys, proposal/commit separation, current-state checks, and reconciliation. The next guardrails chapter implements the approval pause.
Add a search_knowledge function tool with tenant filters, bounded results, stable source IDs, timeout, and sanitized errors. Test prompt-injection text inside a result.