跳到主内容
智客 ZICQ

技能库 智客分类:Agent 工作流 develop-ai-functions-example

Develop Ai Functions Example

为 AI SDK 函数开发示例. 在实例/ai函数/src下创建、运行或修改示例时, 用于验证提供者支持, 显示特性, 或创建测试定点符 .

1806 安装量

官方网址:skills.sh

技能介绍

先看中文介绍;官方 description 原文单独保留,不改写 SKILL.md。

做什么

为 AI SDK 函数开发示例

何时用

在实例/ai-函数/src下创建、运行或修改示例,以验证提供者支持、显示特性或创建测试定点器

代理如何加载

按 Agent Skills 渐进披露:启动时只加载 name 与 description(约 100 token);任务匹配后才读入整份 SKILL.md 正文;scripts/、references/、assets/ 仅在需要时再读。 本文件正文结构:AI Functions Examples、Example Categories、File Naming Convention、Example Structure、Basic Template、Streaming Template。 其中含规范建议的小节:输入输出示例。

文件分析

文件分析:这是一份仅含 SKILL.md 的指令型技能,代理激活后整份正文进入上下文。

官方 description(原文)

Develop examples for AI SDK functions. Use when creating, running, or modifying examples under examples/ai-functions/src to validate provider support, demonstrate features, or create test fixtures.

AI Functions ExamplesExample CategoriesFile Naming ConventionExample StructureBasic TemplateStreaming TemplateTool Calling TemplateStructured Output TemplateRunning ExamplesWhen to Write ExamplesUtility HelpersUsing print utilities

来源分类:skills.sh agent-skill

SKILL.md 与 Agent 调用

官方规范 ↗
name
develop-ai-functions-example
description
Develop examples for AI SDK functions. Use when creating, running, or modifying examples under examples/ai-functions/src to validate provider support, demonstrate features, or create test fixtures.
  1. 发现技能客户端向 Agent 提供名称与描述目录。
  2. 匹配与调用用户指定或任务匹配后,载入 SKILL.md 指令。
  3. 按需加载按步骤读取参考文档、使用脚本与素材。

具体调用语法与可用工具以目标 Agent 客户端为准。 查看调用机制说明 ↗

安装这个技能

Skills CLI ↗

先选择目标 Agent 和安装范围,保留技能包的附属文件,安装后检查客户端能否发现该技能。

交给 Agent 安装

复制安装指令给支持 Agent Skills 的代理,确认其中的目标目录与客户端匹配。

把 Agent Skill「develop-ai-functions-example」安装到我的项目:SKILL.md 原文与官方 description 见 https://zicq.com/zh/skills/skl-dbf34814b829e3b4-%E5%BC%80%E5%8F%91-Ai-%E5%87%BD%E6%95%B0%E7%A4%BA%E4%BE%8B.html
请存为 .cursor/skills/develop-ai-functions-example/SKILL.md 或 .claude/skills/develop-ai-functions-example/SKILL.md,frontmatter 的 name 与 description 保持原样,不要改写。

GitHub 完整包 ↗

终端安装 · Skills CLI

需要 Node.js 与 npx。先查看仓库技能列表,确认实际名称。

npx skills add 'https://github.com/vercel/ai' --list

npx skills add 'https://github.com/vercel/ai' --skill 'develop-ai-functions-example'

CLI 会交互选择目标 Agent,默认安装到项目;用户级安装使用 -g。先通过查看命令核对仓库内容,再用 npx skills list 检查已安装技能。

阅读排版
--- name: develop-ai-functions-example description: Develop examples for AI SDK functions. Use when creating, running, or modifying examples under examples/ai-functions/src to validate provider support, demonstrate features, or create test fixtures. metadata: internal: true --- ## AI Functions Examples The `examples/ai-functions/` directory contains scripts for validating, testing, and iterating on AI SDK functions across providers. ## Example Categories Examples are organized by AI SDK function in `examples/ai-functions/src/`: | Directory | Purpose | | ------------------ | ---------------------------------------------------- | | `generate-text/` | Non-streaming text generation with `generateText()` | | `stream-text/` | Streaming text generation with `streamText()` | | `generate-object/` | Structured output generation with `generateObject()` | | `stream-object/` | Streaming structured output with `streamObject()` | | `agent/` | `ToolLoopAgent` examples for agentic workflows | | `embed/` | Single embedding generation with `embed()` | | `embed-many/` | Batch embedding generation with `embedMany()` | | `generate-image/` | Image generation with `generateImage()` | | `generate-speech/` | Text-to-speech with `generateSpeech()` | | `transcribe/` | Audio transcription with `transcribe()` | | `rerank/` | Document reranking with `rerank()` | | `middleware/` | Custom middleware implementations | | `registry/` | Provider registry setup and usage | | `telemetry/` | OpenTelemetry integration | | `complex/` | Multi-component examples (agents, routers) | | `lib/` | Shared utilities (not examples) | | `tools/` | Reusable tool definitions | ## File Naming Convention Group examples by function and provider. Name the entry example `basic.ts` and use descriptive `kebab-case.ts` names for additional examples: | Pattern | Example | Description | | --------------------------------------------------- | ------------------------------------------------------ | -------------------------- | | `//basic.ts` | `generate-text/openai/basic.ts` | Basic provider usage | | `//.ts` | `stream-text/openai/tool-call.ts` | Specific feature | | `//.ts` | `stream-text/amazon-bedrock/anthropic.ts` | Provider with sub-provider | | `//-.ts` | `stream-text/google/vertex-anthropic-cache-control.ts` | Sub-provider with feature | Do not create flat provider files such as `generate-text/openai.ts`. ## Example Structure All examples use the `run()` wrapper from `lib/run.ts` which: - Loads environment variables from `.env` - Provides error handling with detailed API error logging ### Basic Template ```typescript import { providerName } from '@ai-sdk/provider-name'; import { generateText } from 'ai'; import { run } from '../../lib/run'; run(async () => { const result = await generateText({ model: providerName('model-id'), prompt: 'Your prompt here.', }); console.log(result.text); console.log('Token usage:', result.usage); console.log('Finish reason:', result.finishReason); }); ``` ### Streaming Template ```typescript import { providerName } from '@ai-sdk/provider-name'; import { streamText } from 'ai'; import { printFullStream } from '../../lib/print-full-stream'; import { run } from '../../lib/run'; run(async () => { const result = streamText({ model: providerName('model-id'), prompt: 'Your prompt here.', }); await printFullStream({ result }); }); ``` ### Tool Calling Template ```typescript import { providerName } from '@ai-sdk/provider-name'; import { generateText, tool } from 'ai'; import { z } from 'zod'; import { run } from '../../lib/run'; run(async () => { const result = await generateText({ model: providerName('model-id'), tools: { myTool: tool({ description: 'Tool description', inputSchema: z.object({ param: z.string().describe('Parameter description'), }), execute: async ({ param }) => { return { result: `Processed: ${param}` }; }, }), }, prompt: 'Use the tool to...', }); console.log(JSON.stringify(result, null, 2)); }); ``` ### Structured Output Template ```typescript import { providerName } from '@ai-sdk/provider-name'; import { generateObject } from 'ai'; import { z } from 'zod'; import { run } from '../../lib/run'; run(async () => { const result = await generateObject({ model: providerName('model-id'), schema: z.object({ name: z.string(), items: z.array(z.string()), }), prompt: 'Generate a...', }); console.log(JSON.stringify(result.object, null, 2)); console.log('Token usage:', result.usage); }); ``` ## Running Examples From the `examples/ai-functions` directory: ```bash pnpm tsx src/generate-text/openai/basic.ts pnpm tsx src/stream-text/openai/tool-call.ts pnpm tsx src/agent/openai/generate.ts ``` ## When to Write Examples Write examples when: 1. **Adding a new provider**: Create basic examples for each supported API (`generateText`, `streamText`, `generateObject`, etc.) 2. **Implementing a new feature**: Demonstrate the feature with at least one provider example 3. **Reproducing a bug**: Create an example that shows the issue for debugging 4. **Adding provider-specific options**: Show how to use `providerOptions` for provider-specific settings 5. **Creating test fixtures**: Use examples to generate API response fixtures (see `capture-api-response-test-fixture` skill) ## Utility Helpers The `lib/` directory contains shared utilities: | File | Purpose | | ---------------------- | -------------------------------------------------------- | | `run.ts` | Error-handling wrapper with `.env` loading | | `print.ts` | Clean object printing (removes undefined values) | | `print-full-stream.ts` | Colored streaming output for tool calls, reasoning, text | | `save-raw-chunks.ts` | Save streaming chunks for test fixtures | | `present-image.ts` | Display images in terminal | | `save-audio.ts` | Save audio files to disk | ### Using print utilities ```typescript import { print } from '../lib/print'; // Pretty print objects without undefined values print('Result:', result); print('Usage:', result.usage, { depth: 2 }); ``` ### Using printFullStream ```typescript import { printFullStream } from '../lib/print-full-stream'; const result = streamText({ ... }); await printFullStream({ result }); // Colored output for text, tool calls, reasoning ``` ## Reusable Tools The `tools/` directory contains reusable tool definitions: ```typescript import { weatherTool } from '../tools/weather-tool'; const result = await generateText({ model: openai('gpt-4o'), tools: { weather: weatherTool }, prompt: 'What is the weather in San Francisco?', }); ``` ## Best Practices 1. **Keep examples focused**: Each example should demonstrate one feature or use case 2. **Use descriptive prompts**: Make it clear what the example is testing 3. **Handle errors gracefully**: The `run()` wrapper handles this automatically 4. **Use realistic model IDs**: Use actual model IDs that work with the provider 5. **Add comments for complex logic**: Explain non-obvious code patterns 6. **Reuse tools when appropriate**: Use `weatherTool` or create new reusable tools in `tools/`

相关技能

Agent 工作流

Skill Creator

创造有效技能指南。 当用户想创造出新的技能(或更新现有的技能),以专业知识,工作流程,或工具集成来扩展克洛德的能力时,应该使用这种技能.

Agent 工作流

Clawdhub

使用ClawdHub CLI搜索,安装,更新并发布从taladhub.com的代理技能. 需要获取苍蝇上的新技能时使用,将安装的技能同步到最新版本或特定版本,或者发布 npm-instainddhub CLI 的新/更新的技能文件夹.

Agent 工作流

Agent Team Orchestration

管弦乐团多代理团队,任务设定周期,交接协议,审查工作流程. 使用时间: (1)建立2+特派员队伍,具有不同专业,(2)确定任务路线和生命周期(收录框_ spec_建设_审查_完成),(3)在特派员之间制定交接协议,(4)建立审查和质量关口,(5)管理特派员之间的交流和文物共享.

Agent 工作流

Superpowers

Spec-first,TDD,子代理驱动的软件开发工作流程. 当:(1)构建任何新功能或应用——触发脑暴_计划_子代理执行回路,(2)调试出一个bug或测试失败——触发系统性的根起过程,(3)用户说"让我们构建","帮助我计划","我想添加X",或"这个被打破",(4)完成一个功…