Skip to content

Answers

How do I add approval to tool calls in the OpenAI Agents SDK, LangGraph or the Vercel AI SDK?

Wrap the framework’s tools with Immiscible’s guard. Each tool keeps its name and schema, asks before it runs, waits for a person when the rule says so, and returns a refusal to the model as the tool’s result.

Wrap the framework’s tools with Immiscible’s guard: each tool keeps its name, description and schema, asks Immiscible before it runs, waits for a person when the rule says so, and settles afterwards. A refusal comes back to the model as the tool’s result with plain-English reasons, so the agent tells its person instead of trying another way.

#OpenAI Agents SDK

Shell
npm install @immiscible/sdk @openai/agents
TypeScript
import { Agent, run } from '@openai/agents';
import { Immiscible } from '@immiscible/sdk';
import { guardOpenAITools } from '@immiscible/sdk/openai-agents';

const immiscible = new Immiscible().run();
const agent = new Agent({
  name: 'Buyer',
  tools: guardOpenAITools([buy], {
    client: immiscible,
    mapToAction: ({ args }) => Immiscible.paymentAction({ amount: args.pence, currency: 'GBP', merchant: args.domain, provenance: [{ source: 'user' }] }),
  }),
});
await run(agent, 'Renew the team licence at vendor.example.');

The tool call id is the idempotency key, so a retried call is the same action. Python uses guard_tools from immiscible.integrations. Every option: the OpenAI Agents SDK guide.

#LangChain and LangGraph

Python
from immiscible import Immiscible
from immiscible.integrations import guard_langchain_tools

immiscible = Immiscible().run(client="langchain")
tools = guard_langchain_tools(
    [buy, search],
    client=immiscible,
    map_to_action=lambda call: None if call.name == "search"
        else Immiscible.payment_action(amount=call.args["pence"], currency="GBP", merchant=call.args["domain"]),
)

The guarded tools drop into ToolNode, bind_tools and the prebuilt agents unchanged; None from the mapper means “no decision needed”. TypeScript uses guardLangChainTools from @immiscible/sdk/langchain. See LangChain and LangGraph.

#Vercel AI SDK

TypeScript
import { Immiscible, toolAction } from '@immiscible/sdk';
import { guardAiTools } from '@immiscible/sdk/ai';

const immiscible = new Immiscible().run({ client: 'vercel-ai' });
const tools = guardAiTools({ deploy }, {
  client: immiscible,
  mapToAction: ({ name, args }) => toolAction(name, args, { domain: 'mycompany.com' }),
});

A refusal is returned as the tool’s result, and the generation’s abort signal also aborts a wait for approval. See the Vercel AI SDK.

#Already using the framework’s own approvals?

Keep them, and let Immiscible answer them. The framework still pauses the run; Immiscible decides each paused call, asking a named person when its rules say so, and the run goes on.

OpenAI Agents SDK (needsApproval / needs_approval on a tool):

TypeScript
import { run } from '@openai/agents';
import { resolveInterruptions } from '@immiscible/sdk/openai-agents';

let result = await run(agent, 'Pay invoice 2231');
while (result.interruptions?.length) {
  await resolveInterruptions(result, { client: immiscible }); // approve or reject on result.state
  result = await run(agent, result.state);
}
Python
from agents import Runner
from immiscible.integrations import resolve_interruptions

result = await Runner.run(agent, "Pay invoice 2231")
while result.interruptions:
    state = result.to_state()
    resolve_interruptions(result, state, client=immiscible)  # aresolve_interruptions off the event loop
    result = await Runner.run(agent, state)

LangChain’s HumanInTheLoopMiddleware: the resume value, decided by Immiscible, in the order of the interrupt’s action requests:

Python
from langgraph.types import Command
from immiscible.integrations import hitl_decisions

resume = hitl_decisions(result.interrupts[0], client=immiscible)  # {"decisions": [{"type": "approve"} | {"type": "reject", "message": ...}]}
agent.invoke(Command(resume=resume), config=config)

In JavaScript, hitlDecisions from @immiscible/sdk/langchain does the same with new Command({ resume }).

Google ADK: a plugin whose before_tool_callback asks Immiscible; a refused call never runs and the model reads why:

Python
from google.adk.apps import App
from google.adk.runners import InMemoryRunner
from immiscible.integrations import adk_plugin

app = App(name="payments", root_agent=agent, plugins=[adk_plugin(client=immiscible)])
runner = InMemoryRunner(app=app)

These follow the frameworks’ published interfaces and are tested against stand-ins shaped as those interfaces describe; the Python adapters use the standard library alone.

#Why not use the framework’s own approval feature?

Use it where it is enough. The OpenAI Agents SDK’s tool approvals and LangGraph’s interrupt() pause a run inside one framework for whoever is watching it. Immiscible adds a rule a person wrote outside the code, a named approver reached in the console, Slack or Teams, the same rules and kill switch for every agent whatever its framework, and a signed record of who decided what. The two combine: a framework interrupt can wait on an Immiscible decision, as above.

#What does it not do?

  • It guards the tools you wrap. A tool the agent can reach unwrapped, or a credential it holds directly, is not governed; for those use the MCP proxy.
  • mapToAction decides what the action is (a payment, a data release, a tool call); a mapper that calls a payment a lookup gets a lookup’s rule.