# AI SDK-style issue delivery

URL: https://docs.usestitch.ai/docs/factory/samples/ai-sdk



Inspired by Vercel's [Building a software factory for AI SDK](https://vercel.com/blog/building-a-software-factory-for-ai-sdk).
This is a Stitch adaptation, not Vercel's original configuration.

## Workflow [#workflow]

| Step                    | Starts on                                          | Successful handoff                      |
| ----------------------- | -------------------------------------------------- | --------------------------------------- |
| Classify                | Issue opened                                       | `bug`, `feature`, or `documentation`    |
| Reproduce bug           | `bug` added to issue                               | Draft PR with `reproduced`              |
| Fix bug                 | `reproduced` added to PR                           | PR ready for review                     |
| Analyze feature         | `feature` added to issue                           | `feature-ready`                         |
| Implement feature       | `feature-ready` added to issue                     | PR ready for review                     |
| Implement documentation | `documentation` added to issue                     | PR for human review and merge           |
| Review                  | Bug or feature PR opened, marked ready, or updated | Readiness comment or `work_needed`      |
| Revise                  | `work_needed` added to PR                          | Updated PR for another review           |
| Backport                | Feature PR merged with `backport-needed`           | Backport PRs for human review and merge |

Each step is a separate sandbox-backed agent run. GitHub labels and events connect
the runs. Store evidence in issue comments and PRs, and code in pushed branches,
not in local workspace state that the next run cannot access.

Review can send bugs and features back for revision, up to twice per PR.
Documentation changes go directly to human review. All paths require human merge.

## Prerequisites [#prerequisites]

* Configure a harness with key `coding-agent` and a sandbox with key `workspace` in
  [stitch-factory.yaml](/docs/factory), including their required credentials.
* Make the `build` and `review` agents available, or replace these IDs with your agents.
* Replace `your-org/your-repo` in every trigger with your connected GitHub repository name.
* Create repository labels: `bug`, `feature`, `documentation`, `feature-ready`,
  `reproduced`, `work_needed`, and `backport-needed` before full validation.
  Restrict label management to maintainers and the factory bot.
* Give the GitHub integration the access needed to read issues and PRs, post comments
  and reviews, manage labels, push branches, and open PRs. Use `gh` for the agent's
  GitHub operations.
* Define a backport policy that lists supported release branches and target-selection rules.
* Require passing checks and human approval through GitHub rules. Do not let the bot
  bypass those rules or merge automatically.

<Callout type="warning">
  Issue text, repository code, and install scripts are untrusted. A sandbox does not make arbitrary
  code safe to run with credentials. Review external sources and expose only necessary secrets.
  Prompt instructions are not a security boundary.
</Callout>

## Trigger sample [#trigger-sample]

Add these entries to your factory's `triggers` section. Keep your configured `execution`,
`harnesses`, and `sandboxes` sections. All triggers are enabled; complete setup and
validate the configuration before pushing it to the default branch.

Bot events are allowed downstream so agent-applied labels and pushed commits can start
the next step. Step agents must save and verify their work before applying a handoff
label or marking a draft PR ready for review.

```yaml title="stitch-factory.yaml" lineNumbers
triggers:
  - key: classify
    name: Classify issue
    provider: github
    repository: your-org/your-repo
    harness: coding-agent
    sandbox: workspace
    agentId: build
    eventType: issues
    actions: [opened]
    ignoreBots: true
    enabled: true
    initialPrompt: >-
      Use gh for GitHub operations. Classify the issue as exactly one of
      bug, feature, or documentation. Apply only the chosen classification
      label. Do not change other labels or implement the issue.

  - key: reproduce-bug
    name: Reproduce bug
    provider: github
    repository: your-org/your-repo
    harness: coding-agent
    sandbox: workspace
    agentId: build
    eventType: issues
    actions: [labeled]
    labels: [bug]
    labelScope: changed
    ignoreBots: false
    enabled: true
    initialPrompt: >-
      Use gh for GitHub operations. Reproduce the issue with a focused
      failing regression test. Do not fix the bug yet. Commit and push
      a factory/bug/<issue-number> branch. Open a draft PR linking the
      issue and record reproduction evidence. Apply reproduced to the
      PR only after verifying the pushed test fails for the reported bug.
      If reproduction fails, report the blocker on the issue instead.

  - key: fix-bug
    name: Fix reproduced bug
    provider: github
    repository: your-org/your-repo
    harness: coding-agent
    sandbox: workspace
    agentId: build
    eventType: pull_request
    actions: [labeled]
    labels: [reproduced]
    labelScope: changed
    ignoreBots: false
    enabled: true
    initialPrompt: >-
      Use gh for GitHub operations. Check out the existing PR branch and
      read its reproduction evidence. Make the smallest fix that passes
      the regression test. Run relevant checks, commit, and push to the
      same branch. Mark the draft PR ready for review only when checks
      pass. Otherwise report the blocker and keep the PR in draft.

  - key: analyze-feature
    name: Analyze feature
    provider: github
    repository: your-org/your-repo
    harness: coding-agent
    sandbox: workspace
    agentId: build
    eventType: issues
    actions: [labeled]
    labels: [feature]
    labelScope: changed
    ignoreBots: false
    enabled: true
    initialPrompt: >-
      Use gh for GitHub operations. Analyze the feature and relevant code.
      Save an implementation plan and testable acceptance criteria in an
      issue comment, then apply feature-ready. Do not implement the feature.
      If requirements are unclear, ask for clarification on the issue and
      do not apply feature-ready.

  - key: implement-feature
    name: Implement feature
    provider: github
    repository: your-org/your-repo
    harness: coding-agent
    sandbox: workspace
    agentId: build
    eventType: issues
    actions: [labeled]
    labels: [feature-ready]
    labelScope: changed
    ignoreBots: false
    enabled: true
    initialPrompt: >-
      Use gh for GitHub operations. Read the saved plan and acceptance
      criteria. Implement and test the feature on factory/feature/<issue-number>.
      Run relevant checks, commit, push, and open a non-draft PR linking
      the issue. If blocked, explain the blocker on the issue instead.

  - key: implement-documentation
    name: Implement documentation change
    provider: github
    repository: your-org/your-repo
    harness: coding-agent
    sandbox: workspace
    agentId: build
    eventType: issues
    actions: [labeled]
    labels: [documentation]
    labelScope: changed
    ignoreBots: false
    enabled: true
    initialPrompt: >-
      Use gh for GitHub operations. Implement the documentation change
      on factory/docs/<issue-number>. Run relevant docs checks, commit,
      push, and open a PR linking the issue for human review and merge.
      Do not merge the PR.

  - key: review
    name: Review bug or feature PR
    provider: github
    repository: your-org/your-repo
    harness: coding-agent
    sandbox: workspace
    agentId: review
    eventType: pull_request
    actions: [opened, ready_for_review, synchronize]
    sourceBranches: ['factory/bug/**', 'factory/feature/**']
    ignoreBots: false
    ignoreDrafts: true
    enabled: true
    initialPrompt: >-
      Use gh for GitHub operations. Review the current PR revision for
      correctness, test coverage, scope, and unnecessary complexity.
      If actionable changes are needed, submit one review through gh api
      with event COMMENT and inline findings. Verify the review and its
      comments were saved, then apply work_needed. COMMENT avoids GitHub's
      restriction on change-request self-reviews by the PR-authoring bot.
      If no changes are needed, post a concise readiness comment.
      Do not merge or modify code. If the PR head changes during review,
      do not apply work_needed based on the stale revision.

  - key: revise
    name: Address review feedback
    provider: github
    repository: your-org/your-repo
    harness: coding-agent
    sandbox: workspace
    agentId: build
    eventType: pull_request
    actions: [labeled]
    labels: [work_needed]
    labelScope: changed
    sourceBranches: ['factory/bug/**', 'factory/feature/**']
    ignoreBots: false
    ignoreDrafts: true
    enabled: true
    concurrency:
      scope: subject
      limit: 1
    initialPrompt: >-
      Use gh for GitHub operations. Check out the existing PR branch.
      Read all actionable review feedback and unresolved threads. Fix
      the findings, run relevant checks, and commit. Resolve addressed
      threads. If all findings are addressed, remove work_needed before
      pushing to the same branch so the next review can add it again.
      If blocked, keep work_needed and explain the blocker. Do not create
      another PR, submit a review, or merge.

  - key: backport
    name: Backport merged feature
    provider: github
    repository: your-org/your-repo
    harness: coding-agent
    sandbox: workspace
    agentId: build
    eventType: pull_request
    actions: [closed]
    merged: true
    labels: [backport-needed]
    sourceBranches: ['factory/feature/**']
    ignoreBots: false
    enabled: true
    initialPrompt: >-
      Use gh for GitHub operations. Read the repository's backport policy
      and the merged PR. Create backport PRs only for the selected supported
      release branches. Run relevant checks and link each backport to the
      original PR. Report conflicts or missing policy rather than guessing.
      Do not merge automatically.
```

<Callout type="warning">
  Apply `backport-needed` before merging a feature PR. Adding it after merge does not start this
  trigger. Backport branches must not use the `factory/feature/` prefix.
</Callout>
