Vercel AI SDK agents can call o11 through ordinary server-side tool functions. The AI SDK handles the model-facing schema and tool loop; a small HTTP adapter handles o11’s discovery, inspection, and invocation operations. This keeps provider access separate from the model provider you choose.
The walkthrough targets AI SDK 6. Start with a working capability-planning tool, then add an application-owned execution boundary for the task your product needs. You keep the useful parts of your existing agent loop while giving it a consistent path to external services and recoverable results.
Separate the model and tool clients
Keep your existing model provider configuration. The model generates proposed actions; the tool function calls o11 from your server. You do not need to make the model provider and tool provider the same product.
Reuse createO11Http from the custom agent tutorial. It sends authenticated JSON requests to POST /v1/{operation}, returns unknown data for validation, and throws a typed HTTP error for rejected requests.
Set O11_TOOLS_URL to the configured HTTPS origin and O11_API_KEY to a scoped application key. Never expose that key in a browser bundle or user-supplied prompt.
This example assumes your project already has its reviewed AI SDK and Zod dependencies. It does not require the private @o11/tool-sdk workspace package. Follow your repository’s dependency process and retain its version policy; no package installation is necessary to understand the adapter boundary.
The example was checked against the installed 6.0.208 exports and official 6.0.209 tagged documentation. That versioned reference establishes tool, inputSchema, execute, generateText, and stepCountIs; latest documentation may describe another major version. AI SDK 6 tool documentation. The planning example does not invoke a paid supplier. Add execution only after supplier access, pricing, and task authority are configured.
Add read-oriented planning tools
The following function accepts your already configured LanguageModel. It gives the model a narrow way to discover and inspect tool definitions.
import { generateText, stepCountIs, tool, type LanguageModel } from "ai";
import { z } from "zod";
import { createO11Http } from "./o11-http";
export async function planToolAccess(model: LanguageModel, task: string) {
const origin = process.env.O11_TOOLS_URL;
const key = process.env.O11_API_KEY;
if (!origin || !key) throw new Error("Missing o11 configuration");
const call = createO11Http(origin, key);
return generateText({
model,
system: "Inspect capabilities for the task. Do not claim execution.",
prompt: task,
tools: {
findTools: tool({
description: "Find eligible operations by name or provider.",
inputSchema: z.object({ query: z.string().max(200) }),
execute: async ({ query }) => call("discover", { query }),
}),
inspectTool: tool({
description: "Read the contract for an actual discovered tool ID.",
inputSchema: z.object({ id: z.string().min(1) }),
execute: async ({ id }) => call("inspect", { id }),
}),
},
stopWhen: stepCountIs(4),
});
} The AI SDK 6 tool interface uses the input schema for model-facing parameters and validation, then calls execute for accepted inputs. stepCountIs bounds the multi-step model loop. It is not a dollar budget or a limit on supplier calls across the whole application. AI SDK 6 stop condition source.
The discovery result remains provider data. Before storing or consuming specific fields, validate those fields with application schemas. Do not convert a TypeScript assertion into claimed runtime validation.
Evaluate the planning result
Use a concrete prompt such as: “Find an eligible operation to extract one approved public page and explain its required inputs, account mode, pricing evidence, and completion behavior.”
The result should identify an actual returned operation and cite its inspected requirements. It should not invent a provider identifier, claim a supplier call succeeded, or interpret a reference price as a settled charge.
Check that the model selected the right capability. Search, extraction, and research workflows return different kinds of information. A candidate with a familiar brand name may still be the wrong operation for the task.
If the model cannot find an eligible operation, expose that limitation to the caller. An unsupported result is better than a fabricated configuration. The tool discovery guide provides an evaluation rubric for these choices.
For a production workflow with a fixed capability, move the chosen identifier and mapping into reviewed configuration. Dynamic discovery can remain an exploration feature rather than silently choosing a new supplier for every user request.
Introduce a domain execution tool
After planning is understood, add an application-owned execution function. Keep its model-facing input narrow, such as an approved URL and evidence type. Translate that input to the exact inspected provider schema on the server.
The server should supply the tool identifier, credential mode, allowed connection, spending ceiling, and permissions from trusted task configuration. Do not expose a generic invoke function that lets the model alter all of those fields unless the application has a carefully designed authorization flow.
Persist one approved intent before execution. That record needs the stable idempotency key and unchanged submitted inputs. Replaying the AI SDK loop must not generate a new key for the same purchase.
An invocation request includes toolId, idempotencyKey, input, credentialMode, and maxCostMicros. The input envelope contains path parameters, query parameters, optional body, and headers. Use the selected operation’s actual contract rather than a generic example body.
The result of the execution tool should be a domain state: completed evidence, pending invocation, known failure, or uncertainty requiring recovery. This makes the next model turn more reliable than handing it an opaque receipt and hoping it interprets it correctly.
Separate approval from enforcement
AI SDK 6 supports approval-related tool behavior, but your application’s permission and spending boundary still belongs on the server. A model-visible approval flow does not replace workspace access checks or the policy attached to the execution credential.
For a simple product, collect approval before creating the durable execution intent. Bind that approval to the operation, inputs, account choice, and maximum. If any material field changes, obtain a new decision rather than reusing an old approval label.
Keep recurring services separate from one-time operations. A user agreeing to one generated asset has not necessarily agreed to a renewable resource. Keep write effects and recurring consent explicit.
Likewise, distinguish a provider-account call from a wallet-funded call. Customer mode can avoid a wallet debit while still consuming the customer’s supplier quota or budget. Your approval description should identify that context.
The spending controls guide discusses limits at the task and execution boundaries.
Handle asynchronous work outside the text loop
An image or research job can outlast a model turn. Do not keep calling the model just to ask whether an external job has finished. Persist the invocation identifier and use a bounded application status path.
When a receipt is queued, executing, or waiting, return a pending domain result. The user can see that work is accepted while a background process retrieves the existing invocation. Completion can then trigger a new model step if synthesis is needed.
For an unknown outcome, stop automatic replacement. Retain the original invocation and use the supported reconciliation route. A fresh model tool call with a new key can create a duplicate purchase.
If only an optional step fails, keep completed work. A source-backed brief can be returned even when narration is pending. Store accepted outputs independently so resumption does not repeat every earlier supplier operation.
The asynchronous jobs guide covers state transitions and artifact retrieval in more detail.
Observe the two execution layers
Record the AI SDK tool call and the o11 invocation as separate but linked events. The first tells you what the model requested. The second tells you what external work was accepted and how it settled.
Include an application task identifier, tool name, sanitized input summary, invocation identifier, lifecycle state, and accepted output reference. Keep provider and model credentials out of telemetry.
This separation makes failures diagnosable. A malformed model argument differs from a forbidden request; a supplier timeout differs from a poor final summary. Each needs a different fix.
Use the SDK’s normal error handling for model and function failures, but do not let an automated loop blindly turn every external error into another purchase. The durable intent record is the source of truth for whether work already exists.
Verify before expanding the tool set
First verify the adapter locally against controlled responses and the request contract. Confirm malformed data is rejected, pending receipts remain pending, and unknown outcomes do not trigger replacement calls.
Then exercise discovery and inspection in your authorized environment. Paid supplier verification comes later, after account activation, reviewed pricing, and a bounded execution decision. Record actual outcomes rather than inferring success from code compilation.
The code here was checked against AI SDK 6 tagged documentation and o11’s current public contract. No paid supplier calls were performed for this article. A newer AI SDK major version may require different APIs, so verify its own documentation before adapting the example.
If several agents need the same capability, move the domain adapter into a reusable tool layer. Keep model-facing tools small and let the shared layer handle transport, validation, provenance, and recovery consistently.





