External Publication
Visit Post

Why Agents SDK needs a before tool call hook

OpenAI Developer Community June 19, 2026
Source

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.

With @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.

What I built as a workaround is a check_spend function tool that the agent calls before any paid operation:

from openai_agents_valta import make_valta_tool
from agents import Agent

guard = make_valta_tool(api_key="...", agent_id="prod-agent")

agent = Agent(
    name="Research Agent",
    instructions=(
        "Before any operation that costs money, call check_spend "
        "with the estimated cost. Only proceed if result is 'approved'."
    ),
    tools=[guard, *your_tools],
)

It works, but it relies on the model following instructions reliably — which is exactly the kind of soft enforcement that breaks under loop conditions.

Simulator showing the failure mode: Agent Loop Cost Simulator — Valta | Valta

The 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?

Discussion in the ATmosphere

Loading comments...