Vercel AI SDK
Check every tool call an AI SDK agent makes with Thoth before the tool runs.
governAiSdkTools wraps an AI SDK tool set so that each
tool call is checked with Thoth before its execute runs. Use the governed set
with generateText, streamText or an Agent, exactly as you would the
original. It needs @atensec/thoth 0.2.0 or later and AI SDK 7, and is tested
with ai 7.0.159 (framework compatibility).
Install
Register the agent in Thoth first, and give your app its connection settings:
Your first governed agent covers registering an agent and creating its key.
Govern a tool set
Each call is checked with the tool's name and its input as the arguments. The
AI SDK's call options (toolCallId, abortSignal, messages) reach your
execute unchanged. Tools without an execute, such as tools your client
runs, are passed through as they are and aren't checked.
Govern the tool set once per session, for example per request. To govern it
once at startup and serve many users, leave out userId and run each request
inside actingFor:
What each decision does
| Decision | What happens |
|---|---|
ALLOW | execute runs. |
DENY | execute never runs. The governed tool throws ThothPolicyViolation, and the AI SDK records it as that tool call's error, so the model sees the call was refused. |
STEP_UP | The call waits for a person to approve it, up to stepUpTimeoutMinutes (15 by default). If it's approved, execute runs; otherwise it's refused as for DENY. |
If Thoth can't be reached, calls are refused unless you set failOpen: true.
See error handling in the TypeScript SDK reference.
Start a new agent in observe: Thoth records what it would have decided and every call runs. Switch the agent to enforce when the observe summary shows it's ready.
Cloudflare Agents
Cloudflare's chat agents (AIChatAgent from @cloudflare/ai-chat) run tools
through the AI SDK, and this.mcp.getAITools() returns connected MCP servers'
tools as an AI SDK tool set. Govern the whole set you pass to streamText. Workers
have no process.env, so pass the connection in the config: