skills/ai-sdk-agents/SKILL.md
Expert guidance for building AI agents with ToolLoopAgent (AI SDK v6+). Use when creating agents, configuring stopWhen/prepareStep, callOptionsSchema/prepareCall, dynamic tool selection, tool loops, or agent workflows (sequential, routing, evaluator-optimizer, orchestrator-worker). Triggers: ToolLoopAgent, agent loop, stopWhen, stepCountIs, prepareStep, callOptionsSchema, prepareCall, hasToolCall, InferAgentUIMessage, agent workflows.
npx skillsauth add bjornmelin/dev-skills ai-sdk-agentsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Build autonomous agents with ToolLoopAgent: reusable model + tools + loop control.
Assume Zod v4.3.5 for schema typing.
import { ToolLoopAgent, tool } from 'ai';
import { anthropic } from '@ai-sdk/anthropic';
import { z } from 'zod';
const weatherAgent = new ToolLoopAgent({
model: anthropic('claude-sonnet-4-20250514'),
tools: {
weather: tool({
description: 'Get the weather in a location (F)',
inputSchema: z.object({ location: z.string() }),
execute: async ({ location }) => ({ location, temperature: 72 }),
}),
},
});
const result = await weatherAgent.generate({
prompt: 'What is the weather in San Francisco?',
});
import { ToolLoopAgent, Output } from 'ai';
import { z } from 'zod';
const analysisAgent = new ToolLoopAgent({
model: 'openai/gpt-4o',
output: Output.object({
schema: z.object({
sentiment: z.enum(['positive', 'neutral', 'negative']),
summary: z.string(),
}),
}),
});
const stream = myAgent.stream({ prompt: 'Summarize this report' });
for await (const chunk of stream.textStream) {
process.stdout.write(chunk);
}
import { createAgentUIStreamResponse } from 'ai';
export async function POST(request: Request) {
const { messages } = await request.json();
return createAgentUIStreamResponse({ agent: myAgent, messages });
}
import { ToolLoopAgent, InferAgentUIMessage } from 'ai';
const myAgent = new ToolLoopAgent({ model, tools });
export type MyAgentUIMessage = InferAgentUIMessage<typeof myAgent>;
stopWhen (default: stepCountIs(20)) for safety.hasToolCall('finalAnswer') to stop on terminal actions.prepareStep to swap models, compress messages, or limit tools per step.callOptionsSchema to define type-safe runtime options.prepareCall to select model/tools or inject RAG context once per call.prepareStep for per-step decisions (budget limits, dynamic tools).Run the local scanner before agent-loop audits or migrations:
python3 skills/ai-sdk-agents/scripts/ai_stack_scan.py --root <repo> --pretty
It emits ai_stack_scan.v1, uses no network by default, skips symlinks, and
flags likely agent-loop risks such as missing explicit stopWhen on
ToolLoopAgent. Verify signals against current AI SDK docs/source before
changing behavior. Keep full scanner JSON local; share only specific redacted
signals externally.
| Reference | When to Use |
|-----------|-------------|
| references/fundamentals.md | ToolLoopAgent basics, Output types, streaming |
| references/loop-control.md | stopWhen, hasToolCall, prepareStep patterns |
| references/configuration.md | callOptionsSchema, prepareCall vs prepareStep |
| references/workflow-patterns.md | multi-agent workflows and routing |
| references/real-world.md | RAG, multimodal, file processing |
| references/production.md | monitoring, safety, cost control |
| references/migration.md | v6 migration notes |
development
Repo/monorepo modernization: dependency upgrades, security fixes, deprecation cleanup, framework migrations, dependency-native refactors, and verified hard-cut simplification.
development
Use this skill for Browser Web Animations API: Element.animate(), Animation, KeyframeEffect, playback control, generated keyframes, cancel/finish, commitStyles, and cleanup. Trigger on Element.animate, WAAPI, Web Animations API, KeyframeEffect, Animation object, commitStyles. Do not use for near-miss tasks outside these boundaries; route to adjacent motion or platform skills when they own the implementation.
tools
Use this skill for Three.js, React Three Fiber, Drei, Canvas/createRoot lifecycle, loaders, GLTF, useFrame, disposal, SSR/client boundaries, DPR, and browser proof. Trigger on Three.js, THREE, @react-three/fiber, @react-three/drei, R3F Canvas, useFrame, GLTF, WebGLRenderer. Do not use for near-miss tasks outside these boundaries; route to adjacent motion or platform skills when they own the implementation.
development
Use this skill for Tailwind CSS v4 transition, animation, duration, easing, motion-safe/motion-reduce, @theme motion tokens, and static class safety. Trigger on Tailwind animation, transition-all, motion-safe, motion-reduce, @theme, animate-, duration-. Do not use for near-miss tasks outside these boundaries; route to adjacent motion or platform skills when they own the implementation.