给智能体合适的上下文,构建一个小版本,再检查它的行为。

告诉智能体你在构建什么、用的是哪个框架,以及组件应该如何表现。它可以用 ui-sdk 的组件和行为把它组装起来。

给它文档

每个包都附带与你所安装版本匹配的 Markdown 文档。在页面顶部选择你的框架,然后从下面这段开始:

This project uses React and ui-sdk. Read
node_modules/@ui-sdk/react/docs/llms.txt to see what's available.

For a custom component, read the relevant sections of docs/core.md
and docs/rendering.md in the same package.

llms.txt 涵盖你所用框架的 API。core.md 涵盖各种行为,rendering.md 则说明如何在你的框架中渲染原语。

Core 指南 会带你过一遍代码。所有行为 帮智能体为每种交互找到合适的构建块。

添加技能

如果你的智能体支持技能,安装 ui-sdk:

npx skills@latest add vercel-labs/ui --skill ui-sdk

它给智能体一套工作流:挑选行为、定义原语、渲染并测试。同一个技能也随 @ui-sdk/core 发布在 node_modules/@ui-sdk/core/skills/ 中,所以不支持技能的智能体可以直接在那里读取它。技能 介绍了如何使用它。你也可以直接照着文档来做。

描述交互

给智能体一个具体的例子,说明用户应该能做到什么。以表情符号选择器为例:

Build an emoji picker in React using ui-sdk.

Add a search input and a grid of emoji. Down from the search input
should move focus to the first result. Arrow keys move through the
grid, and Enter selects an emoji. Announce the selection to screen readers.

Use our existing styles.

把对你的应用重要的细节写进去,比如选择器是否在浮层中打开,或者选中的值是否由父组件持有。智能体可以根据这些要求来挑选行为。

从小处开始

先要一个能运行的例子:

Start with a small, fixed list of emoji and one example page.
Reuse public ui-sdk components and behaviors where they fit.

试试这个版本,然后提出一个具体的修改:

When a search has no results, show "No emoji found" and keep focus
in the search input. Keep the input in the same position as results change.

这样,随着组件逐渐成形,你始终有东西可以审查。

检查结果

让智能体测试你描述过的交互:

Test moving from search into the grid, navigating with arrow keys,
and selecting with Enter. Check the empty search state and the
selection announcement too.

Run the project's typecheck and relevant tests. Tell me what passed
and anything you couldn't check.

测试指南 介绍了如何用 @ui-sdk/core/testing 检查原语。

你也可以自己试试这个例子:用 Tab 进入搜索输入框,搜索一个表情符号,按向下键,用方向键移动,再按 Enter 选择。然后试一次没有结果的搜索。这些正是智能体的测试应该覆盖的交互。