Ai sdk agents
AgentSkills library: reusable skills for AI coding agents (AI SDK, Codex, LangGraph, Supabase, Docker, Vitest, pytest, Streamlit, Zod).
npx -y skills add BjornMelin/dev-skills --skill ai-sdk-agentsAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
- 3 stars3 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
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.
SKILL.md
3.9 KB, as published. Nobody here has run it
AI SDK Agents
Build autonomous agents with ToolLoopAgent: reusable model + tools + loop control.
Quick Start
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?',
});
When to Use ToolLoopAgent vs Core Functions
- Use ToolLoopAgent for dynamic, multi-step tasks where the model decides which tools to call.
- Use generateText/streamText for deterministic flows or strict ordering.
Essential Patterns
Structured Output
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(),
}),
}),
});
Streaming Agent
const stream = myAgent.stream({ prompt: 'Summarize this report' });
for await (const chunk of stream.textStream) {
process.stdout.write(chunk);
}
API Route
import { createAgentUIStreamResponse } from 'ai';
export async function POST(request: Request) {
const { messages } = await request.json();
return createAgentUIStreamResponse({ agent: myAgent, messages });
}
Type-Safe Client Integration
import { ToolLoopAgent, InferAgentUIMessage } from 'ai';
const myAgent = new ToolLoopAgent({ model, tools });
export type MyAgentUIMessage = InferAgentUIMessage<typeof myAgent>;
Loop Control Checklist
- Set
stopWhen(default:stepCountIs(20)) for safety. - Use
hasToolCall('finalAnswer')to stop on terminal actions. - Use
prepareStepto swap models, compress messages, or limit tools per step.
Runtime Configuration
- Use
callOptionsSchemato define type-safe runtime options. - Use
prepareCallto select model/tools or inject RAG context once per call. - Use
prepareStepfor per-step decisions (budget limits, dynamic tools).
Offline Stack Scanner
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 Files
| 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 |