-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Documentation: Add agentic flow and storybook ai command docs #34560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kylegach
merged 5 commits into
project/sb-agentic-setup
from
yann/storybook-ai-api-docs
Apr 17, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c473959
First pass at agentic flow docs
yannbf 2ec3044
Improve agentic setup docs: style, structure, and links
kylegach 12ae3fe
Address feedback and format
kylegach 809ba4e
Add new page to "more resources" list
kylegach a6355f4
Merge branch 'project/sb-agentic-setup' into yann/storybook-ai-api-docs
kylegach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| ```shell renderer="common" language="js" packageManager="npm" | ||
| npx storybook ai setup --output storybook-setup.md | ||
| ``` | ||
|
|
||
| ```shell renderer="common" language="js" packageManager="pnpm" | ||
| pnpm exec storybook ai setup --output storybook-setup.md | ||
| ``` | ||
|
|
||
| ```shell renderer="common" language="js" packageManager="yarn" | ||
| yarn exec storybook ai setup --output storybook-setup.md | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| --- | ||
| title: Agentic setup | ||
| sidebar: | ||
| order: 4 | ||
| --- | ||
|
|
||
| <Callout variant="info" icon="🧪"> | ||
|
|
||
| Storybook's agentic setup is currently only available for projects using the [React](?renderer=react) renderer with the [Vite](../builders/vite.mdx) builder. Support for additional renderers and builders will follow. | ||
|
|
||
| The API may change in future releases. We welcome feedback and contributions to help improve this feature. | ||
|
|
||
| </Callout> | ||
|
|
||
| <If renderer={['react']}> | ||
|
|
||
| Getting Storybook wired up to an existing application (configuring providers, mocking side effects, and writing the first few real stories) is the kind of repetitive, project-specific work that AI agents are well suited for. The **agentic setup** flow uses the [`storybook ai setup`](../api/cli-options.mdx#ai) command to generate a detailed, project-aware instruction set that an AI agent can follow to make Storybook fully functional in your project. | ||
|
|
||
| The command analyzes your Storybook configuration (framework, renderer, builder, language, addons) and produces a Markdown prompt containing step-by-step instructions tailored to your project, covering everything from configuring your preview file to writing and verifying stories. See [what the generated prompt covers](#what-the-generated-prompt-covers) for the full list of steps. | ||
|
|
||
| ## Starting from `storybook init` | ||
|
|
||
| When an agent runs [`storybook init`](../api/cli-options.mdx#init) to add Storybook to a new project, the output instructs the agent to continue with `storybook ai setup`. No extra prompting is needed; the agent will pick up the agentic setup flow automatically. | ||
|
|
||
| If Storybook is already installed, you can kick off the flow yourself using one of the two approaches below. | ||
|
|
||
| ## Agent-initiated setup | ||
|
|
||
| In this flow, you ask your agent to run `storybook ai setup`. For example: | ||
|
|
||
| ```txt | ||
| Use Storybook's agentic setup command to configure Storybook for this project and write some initial stories. | ||
| ``` | ||
|
|
||
| The agent will run the command from your project root, read the generated prompt from stdout, and follow the steps in order: analyzing your codebase, updating `preview.tsx`, and writing stories. After each story, it runs Vitest to verify that the story renders and fixes any failures before moving on. | ||
|
|
||
| This flow works best when your agent has access to a terminal in your project (most modern coding agents do). No flags or additional configuration is required. The generated instructions are self-contained. | ||
|
|
||
| ## User-initiated setup | ||
|
|
||
| If you'd rather drive the process yourself, you can run the command manually and hand the output to any agent, even one that can't execute shell commands. | ||
|
|
||
| 1. From your project root, run: | ||
|
|
||
| <CodeSnippets path="ai-setup-output.md" /> | ||
|
|
||
| This writes the instructions to `storybook-setup.md` instead of printing them to your terminal. Omit `--output` to print to stdout and pipe it elsewhere. | ||
|
|
||
| 2. Open the generated file and paste its contents into your agent's chat, or attach it as context. The prompt is designed to be self-contained: it references your specific `configDir`, framework, and renderer, and links back to the relevant Storybook docs in Markdown form. | ||
|
|
||
| 3. Let the agent work through the steps. You can review each change as the agent applies it. | ||
|
|
||
| Use this flow when you want tighter control over what the agent does, when you're working with an agent that doesn't have shell access, or when you want to save the prompt to reuse across projects. | ||
|
|
||
| ## What the generated prompt covers | ||
|
|
||
| Regardless of how the flow is initiated, the generated Markdown prompt walks the agent through the same ordered steps: | ||
|
|
||
| 1. **Analyze the codebase:** read providers, global CSS, portals, and data-fetching patterns. | ||
| 2. **Configure the [preview](../configure/story-rendering.mdx):** set up [decorators](../writing-stories/decorators.mdx), global styles, and any framework-level providers in `preview.tsx`. | ||
| 3. **Support portals:** ensure portal roots exist in the Storybook preview DOM. | ||
| 4. **Mock side effects:** intercept [network requests](../writing-stories/mocking-data-and-modules/mocking-network-requests.mdx) (via MSW), storage, timers, and navigation at the preview level rather than per-story. | ||
| 5. **Write [stories](../writing-stories/index.mdx):** copy real usage patterns from the app, [tagging](../writing-stories/tags.mdx) generated stories with `ai-generated` and `needs-work` so you can review them later. | ||
| 6. **Add [play functions](../writing-stories/play-function.mdx):** implement interaction tests for the most important flows. | ||
| 7. **Cover additional patterns:** expand coverage across the components the agent has already touched. | ||
| 8. **Verify:** run [Vitest](../writing-tests/integrations/vitest-addon/index.mdx) against every new story to confirm it renders, and run the type checker. | ||
|
|
||
| <Callout variant="info"> | ||
|
|
||
| The command snapshots your `preview` file so that subsequent runs of `storybook dev`, `storybook build`, and `storybook doctor` can detect progress the agent made and report it via telemetry. If you'd prefer not to share this data, pass `--disable-telemetry` (see [telemetry](../configure/telemetry.mdx)). | ||
|
|
||
| </Callout> | ||
|
|
||
| ## Next steps | ||
|
|
||
| Once the agent has completed the setup: | ||
|
|
||
| - Connect the [Storybook MCP server](./mcp/overview.mdx) to your agent so it can continue reading manifests, generating stories, and running tests against your live Storybook. | ||
| - Review the stories tagged `ai-generated` and `needs-work`, and remove those tags once you've validated each one. | ||
| - Follow the [best practices](./best-practices.mdx) to make your stories and documentation maximally useful to both humans and agents. | ||
|
|
||
| </If> | ||
| {/* End supported renderers */} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Availability statement does not match current command gating logic.
Line 294 says
ai setupis only available for React+Vite, butcode/lib/cli-storybook/src/ai/index.ts(Lines 69-85) currently checks with&&, which allows execution when either side matches. This will mislead users about what is actually blocked.Suggested doc-side mitigation (until CLI check is corrected)
📝 Committable suggestion
🤖 Prompt for AI Agents