> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tracelane.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Approvals in agent frameworks

> Send an agent's tool call through the Tracelane gateway from the OpenAI Agents SDK, LangGraph, CrewAI, Pydantic AI, Google ADK, the Vercel AI SDK or the Claude Agent SDK, so a person approves that exact call in Tracelane.

These adapters send a tool call from your agent to a tool server registered in the Tracelane gateway. When a workspace policy holds the call, a person approves or denies it in Tracelane, and the adapter retries the identical call. **Tracelane decides**: the approval is bound to the exact call, can be used once, and the person who approves must differ from the requester. The tool itself runs at the tool server, not in your agent process.

> [!NOTE]
>
> **Not in a published release yet.** These adapters ship in the next SDK release (Python `tracelane` and npm `@tracelanedev/sdk`, after 0.4.0, unreleased). Until then, install from source in the open-source repository.

> [!NOTE]
>
> Approval holds for MCP tool calls are a **Preview** and are turned on per workspace. The adapters below are Preview too, and none of them is published to PyPI or npm yet. Their tests and examples run against a mock gateway, not a real workspace. The frameworks do not provide any of this themselves, and we make no claim about what they guarantee.

## Before you start

Follow [Protect a payment tool](https://docs.tracelane.dev/quickstart-approvals.md) first: it creates the API key (MCP scope), the tool server and the policy these adapters call. A protected tool needs the Streamable HTTP transport.

## How a call flows

1. The adapter sends `tools/call` to `POST /v1/mcp/<server>` with your API key and an `Idempotency-Key` that is a new UUID for each distinct call.
2. If the policy holds it, the gateway answers `409 approval_required`. The adapter waits for the decision inside the tool call, or, in LangGraph, pauses the graph with `interrupt()`.
3. After approval the adapter retries the **same call** with the **same key** and the approval id. If the arguments changed, the adapter treats it as a new call: a new key, no approval id, and the gateway holds it again.
4. A denied, expired, mismatched or wrong-reviewer answer (for example `403 separation_required`) is passed back as a refusal. The tool does not run. An approval that was already used (`approval_consumed`) is different: an identical call may have performed the action, so it is worded "may have run" and its key is kept. If the request fails before it is sent (connection refused, DNS), nothing ran. If it times out or resets after it was sent, or the gateway answers 5xx or reports the outcome as unknown, the action may have run: the adapter keeps the same `Idempotency-Key`, so a retry replays that call instead of creating a new hold, and the model is told to check Tracelane before retrying. A call the gateway ran is reported as performed with its execution id; a failed one is reported as failed.

Once a call may have run, that stays true for the call: a later refusal or an unreachable gateway on the same call is still worded "may have run", and its key is kept until a settling receipt arrives or you call `resolve()` (Python `resolve(name, arguments, scope=..., principal=...)`, TypeScript `resolve(name, args, scope, principal)`) after checking Tracelane. `resolve()` drops the key, so the next identical call is a new call; use it only once a person has reconciled the earlier one. The adapter remembers at most 1,024 in-flight calls and drops the oldest one that did not run first. If all 1,024 may have run, it refuses a new call and says why.

`scope` only separates this adapter's local key cache. It is not sent to the gateway. To keep end users' approvals apart at the gateway, pass `principal` (sent as the `tracelane-principal` header). One adapter shared by several users must pass both, as `scope=` and `principal=` on `call`/`attempt`/`langgraph_tool_call`, or as `scope(ctx)` and `principal(ctx)` functions on the framework adapters (`openai_agents_tool`, `pydantic_ai_tool`, `google_adk_tool`, `gatewayExecute`, `vercelAiTool`, `claudeAgentToolHandler`). Otherwise use one adapter per run. The default request timeout is 130 seconds. The gateway can spend up to 120 seconds in each of its reserve, forward and finish steps, so a slow call can still return "may have run".

`principal` is an end user's token and is checked before anything is sent: it must be a compact token of three dot-separated parts, at most 8,192 characters, with nothing trimmed. Anything else is refused as `principal_malformed` without sending a request, and the error never contains the value. The local key cache is keyed by scope, principal and call, so two principals under one scope never share a key.

## OpenAI Agents SDK (Python)

```python theme={"system"}
from tracelane.gateway_tools import GatewayTool, openai_agents_tool

gw = GatewayTool("payments", base_url="https://gateway.tracelane.dev", api_key=KEY)
release_payment = openai_agents_tool(
    gw, name="release_payment", description="Release a payment", parameters=SCHEMA
)
agent = Agent(name="payer", tools=[release_payment])
```

Install with `pip install "tracelane[openai-agents]"`. `needs_approval` is left off on purpose: the SDK's own approval is a yes or no inside your process, and here Tracelane decides. The run waits inside the tool call, up to `wait_timeout` (300 seconds by default). A refusal comes back to the model as text, and the run continues: "not performed" only when nothing can have run, otherwise "may have run; check Tracelane before retrying".

## OpenAI Agents SDK (TypeScript)

```ts theme={"system"}
import { tool } from "@openai/agents";
import { createGatewayTool, gatewayExecute } from "@tracelanedev/sdk/gateway_tools";

const gw = createGatewayTool({ server: "payments", baseUrl: "https://gateway.tracelane.dev", apiKey: KEY });
const releasePayment = tool({
  name: "release_payment",
  description: "Release a payment",
  parameters,
  execute: gatewayExecute(gw, "release_payment"),
});
```

## LangGraph (Python)

```python theme={"system"}
from tracelane.gateway_tools import GatewayTool, langgraph_tool_call

def pay(state):
    return {"out": langgraph_tool_call(gw, "release_payment", state["args"])}
```

Install with `pip install "tracelane[langgraph]"`. A held call raises `interrupt()` with `{"type": "tracelane.approval_required", "approval_id": ...}`. Resume with `Command(resume={"decision": "approved"})` after `wait_for_decision` returns `approved`; any other answer ends the call as not approved, except `consumed` (the approval was already used), which ends it as "may have run" and keeps the key. LangGraph runs the node again on resume, and the adapter reuses the same key, so that run is the retry. The key and approval id are kept in memory. After a restart the adapter sends the same call with no approval id, and the gateway looks for an unexpired, unconsumed approval for the same requester, call and policy: it returns the existing pending one (the same approval id) or, if it was already approved, runs the call. If a denied approval exists for the same call, the retry gets `approval_denied`. If there is none, it opens a new hold. A call that was already sent under the lost key is not replayed, so check Tracelane for a call that may have run. Keep side effects out of the node before the call.

## CrewAI (Python)

```python theme={"system"}
from tracelane.gateway_tools import GatewayTool, crewai_tool

pay = crewai_tool(gw, name="release_payment", description="Release a payment",
                  args_schema=PaymentArgs, scope="run-42")
agent = Agent(role="payer", goal="...", backstory="...", tools=[pay])
```

`args_schema` is the pydantic model the model fills in; CrewAI validates against it first and the adapter sends the validated arguments. CrewAI gives a tool no run context, so `scope` and `principal` are fixed strings: build one tool per user or run when they differ. The tool answers through `_run` and `_arun`, and the run waits inside the call.

## Pydantic AI (Python)

```python theme={"system"}
from tracelane.gateway_tools import GatewayTool, pydantic_ai_tool

pay = pydantic_ai_tool(gw, name="release_payment", description="Release a payment",
                       parameters=SCHEMA, scope=lambda ctx: ctx.run_id or "")
agent = Agent(model, tools=[pay])
```

The tool is built with `Tool.from_schema`, so the model sees your JSON `parameters`. `scope(ctx)` and `principal(ctx)` receive the run's `RunContext`.

## Google ADK (Python)

```python theme={"system"}
from tracelane.gateway_tools import GatewayTool, google_adk_tool

def release_payment(amount: int, currency: str, beneficiary: str) -> str:
    """Release a payment."""
    raise AssertionError("never runs")

tool = google_adk_tool(gw, release_payment)   # LlmAgent(tools=[tool])
```

ADK builds the model's schema from a function's name, docstring and type hints, so you pass a function that only declares the tool. **It is never called.** Give it JSON-typed parameters (`str`, `int`, `float`, `bool`, `list`, `dict`). A `tool_context` parameter is handed to `scope(tool_context)` and `principal(tool_context)` and is not sent to the gateway.

## Vercel AI SDK (TypeScript)

```ts theme={"system"}
import { tool } from "ai";
import { createGatewayTool, vercelAiTool } from "@tracelanedev/sdk/gateway_tools";

const releasePayment = tool(
  vercelAiTool(gw, { name: "release_payment", description: "Release a payment", inputSchema: schema }),
);
```

Leave `toolApproval` off for this tool: the SDK's own approval is a local yes or no. `scope(options)` and `principal(options)` receive the options object the SDK passes to `execute`.

## Claude Agent SDK (TypeScript)

```ts theme={"system"}
import { createSdkMcpServer, tool } from "@anthropic-ai/claude-agent-sdk";
import { claudeAgentToolHandler, createGatewayTool } from "@tracelanedev/sdk/gateway_tools";

const releasePayment = tool("release_payment", "Release a payment", shape,
  claudeAgentToolHandler(gw, "release_payment"));
const server = createSdkMcpServer({ name: "tracelane", tools: [releasePayment] });
```

The handler returns one text block, with `isError: true` for every refusal. It governs only the tool you register: the SDK's built-in tools are not routed through Tracelane, so leave the ones you do not want in `disallowedTools`.

## Refusals you may see

From the gateway (its own code, in the response `error`): `approval_denied`, `approval_expired`, `approval_mismatch`, `approval_not_approved`, `idempotency_mismatch`, `separation_required`, `control_changed`, `key_revoked`, `principal_required`, `principal_invalid`, `mcp_tool_definition_changed`, `protected_execution_unavailable` and the other refusal codes of the protected endpoint.

Added by the adapter: `approval_pending` (still pending after an approved answer), `approval_timeout` (the wait deadline passed; the approval may still be pending), `approval_consumed` (the approval was already used; the action may have run), `http_NNN` (a status with no gateway code), `execution_failed` and `execution_unknown` (from the receipt state; unknown includes in-flight), `invalid_response` (a 200 that could not be read), `tool_error` (a non-protected tool reported an error) `principal_malformed` (the principal failed the check above) and `unconfirmed_calls_limit` (1,024 earlier calls may have run).

The model is told "not performed" only when nothing can have run. Every code above except the pre-send failures can carry the "may have run; check Tracelane before retrying" wording once the call may have run. The adapter never includes the response body or your key.

## Limits

The test suite runs the adapters against stand-ins of each framework's tool interface and a mock gateway. Tests against the real libraries run only when the framework is installed, and no other versions were tested. LangGraph for TypeScript is not covered. The calls are not streamed, and one retry is made after approval. Holds are a Preview, and the signed approval record is a Preview too: see [Approvals for held tool calls](https://docs.tracelane.dev/integrations/approvals.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.