{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreics5fxzmggui6kzygpqarn7pmgbzm4oodvqrrbeqnrvftil6ezrda",
"uri": "at://did:plc:lk3jfj3zq4k4wxnk474axylu/app.bsky.feed.post/3moocvxwsxs72"
},
"path": "/t/why-agents-sdk-needs-a-before-tool-call-hook/1384160#post_1",
"publishedAt": "2026-06-19T20:23:02.000Z",
"site": "https://community.openai.com",
"tags": [
"Agent Loop Cost Simulator — Valta | Valta",
"@function_tool"
],
"textContent": "Been thinking about a gap in the Agents SDK — there’s no blocking mechanism between the agent’s decision to call a tool and the tool actually executing.\n\nWith `@function_tool` you can define what tools do, but you can’t intercept the call before it fires and say “no, not this one.” In a loop failure scenario — agent retrying because it’s not confident, sub-agents spawning, context filling up — each iteration is a real API call with real cost. By the time you see it in your usage dashboard it’s already happened.\n\nWhat I built as a workaround is a `check_spend` function tool that the agent calls before any paid operation:\n\n\n from openai_agents_valta import make_valta_tool\n from agents import Agent\n\n guard = make_valta_tool(api_key=\"...\", agent_id=\"prod-agent\")\n\n agent = Agent(\n name=\"Research Agent\",\n instructions=(\n \"Before any operation that costs money, call check_spend \"\n \"with the estimated cost. Only proceed if result is 'approved'.\"\n ),\n tools=[guard, *your_tools],\n )\n\n\nIt works, but it relies on the model following instructions reliably — which is exactly the kind of soft enforcement that breaks under loop conditions.\n\nSimulator showing the failure mode: Agent Loop Cost Simulator — Valta | Valta\n\nThe real fix would be a native `before_tool_call` hook in the SDK that can return a deny response before execution. Does anyone know if something like this is on the roadmap, or is the tool-layer approach the intended pattern?",
"title": "Why Agents SDK needs a before tool call hook"
}