> ## Documentation Index
> Fetch the complete documentation index at: https://docs.devin.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 将功能提示的 ACU 用量从 42 降至 12

export const UseCaseHero = ({title, description, prompt, category, features, devinUrl, agent, intent, playbookId, type}) => {
  const encodedPrompt = encodeURIComponent(prompt || '');
  const tag = 'docs-use-case-gallery';
  const utm = 'utm_source=docs&utm_medium=use-case-gallery&utm_campaign=hero-cta';
  const agentParams = (agent ? '&agent=' + agent : '') + (intent ? '&intent=' + intent : '') + (playbookId ? '&playbookId=' + playbookId : '');
  const devinHref = type === 'schedule' ? 'https://app.devin.ai/settings/schedules/create?' + utm + agentParams + (prompt ? '&prompt=' + encodedPrompt : '') : type === 'review' ? 'https://app.devin.ai/review?' + utm : agent === 'ada' ? 'https://app.devin.ai/search?' + utm + '&noSubmit=true' + (prompt ? '&prompt=' + encodedPrompt : '') : devinUrl ? devinUrl.includes('?') ? devinUrl + '&' + utm + agentParams : devinUrl + '?' + utm + agentParams : prompt ? 'https://app.devin.ai/?tags=' + tag + '&' + utm + agentParams + '&prompt=' + encodedPrompt : 'https://app.devin.ai/?' + utm + agentParams;
  const buttonLabel = type === 'schedule' ? 'Schedule in Devin ↗' : type === 'review' ? 'Set Up Devin Review ↗' : agent === 'advanced' ? 'Try in Devin ↗' : agent === 'dana' ? 'Try in Dana ↗' : agent === 'ada' ? 'Try in Ask Devin ↗' : 'Try in Devin ↗';
  const featureList = features ? features.split(',').map(f => f.trim()) : [];
  return <div className="uc-hero">
      <div className="uc-hero-inner">
        <div className="uc-hero-left">
          <h1 className="uc-hero-title">{title}</h1>
          <p className="uc-hero-desc">{description}</p>
          <div>
            <a href={devinHref} target="_blank" rel="noopener noreferrer" className="try-in-devin-btn">
              {buttonLabel}
            </a>
          </div>
        </div>
        <div className="uc-hero-meta">
          <div className="uc-meta-item">
            <span className="uc-meta-label">Author</span>
            <span className="uc-meta-value">Cognition</span>
          </div>
          <div className="uc-meta-item">
            <span className="uc-meta-label">Category</span>
            <span className="uc-meta-value">{category}</span>
          </div>
          {featureList.length > 0 && <div className="uc-meta-item">
              <span className="uc-meta-label">Features</span>
              <span className="uc-meta-value">{featureList.join(', ')}</span>
            </div>}
        </div>
      </div>
    </div>;
};

export const PromptBlock = ({children, type, agent, intent, playbookId}) => {
  var utm = 'utm_source=docs&utm_medium=use-case-gallery&utm_campaign=prompt-block';
  var tag = 'docs-use-case-gallery';
  var agentParams = (agent ? '&agent=' + agent : '') + (intent ? '&intent=' + intent : '') + (playbookId ? '&playbookId=' + playbookId : '');
  var label = type === 'schedule' ? 'Schedule in Devin' : type === 'playbook' ? 'Create Playbook' : type === 'knowledge' ? 'Add to Knowledge' : agent === 'advanced' ? 'Try in Devin' : agent === 'dana' ? 'Try in Dana' : agent === 'ada' ? 'Try in Ask Devin' : 'Try in Devin';
  var buildUrl = function (text) {
    var encoded = encodeURIComponent(text);
    if (type === 'schedule') return 'https://app.devin.ai/settings/schedules/create?' + utm + agentParams + '&prompt=' + encoded;
    if (type === 'playbook') return 'https://app.devin.ai/settings/playbooks/create?' + utm + '&body=' + encoded;
    if (type === 'knowledge') return 'https://app.devin.ai/knowledge?' + utm + '&body=' + encoded;
    if (agent === 'ada') return 'https://app.devin.ai/search?' + utm + '&noSubmit=true&prompt=' + encoded;
    return 'https://app.devin.ai/?tags=' + tag + '&' + utm + agentParams + '&prompt=' + encoded;
  };
  const ref = React.useRef(null);
  const [href, setHref] = React.useState('#');
  React.useEffect(() => {
    if (!ref.current) return;
    var codeEl = ref.current.querySelector('pre code');
    if (codeEl) {
      var text = codeEl.textContent.trim();
      if (text) setHref(buildUrl(text));
    }
    var header = ref.current.querySelector('[data-component-part="code-block-header"]');
    if (header && !header.querySelector('.prompt-block-devin-link')) {
      var link = document.createElement('a');
      link.href = href;
      link.target = '_blank';
      link.rel = 'noopener noreferrer';
      link.className = 'prompt-block-devin-link';
      link.style.cssText = 'display:inline-flex;align-items:center;gap:6px;text-decoration:none;color:#fff;font-size:11px;font-weight:500;padding:4px 10px;border-radius:6px;white-space:nowrap;background:#317CFF;transition:background 0.2s;margin-left:8px;';
      link.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg> ' + label;
      link.onmouseenter = function () {
        link.style.background = '#2968D9';
      };
      link.onmouseleave = function () {
        link.style.background = '#317CFF';
      };
      header.appendChild(link);
    }
    var existingLink = ref.current.querySelector('.prompt-block-devin-link');
    if (existingLink && href !== '#') existingLink.href = href;
  });
  return <div className="prompt-block" ref={ref}>{children}</div>;
};

<UseCaseHero title="将某功能 Prompt 的 ACU 消耗从 42 降到 12" description="逐步分析一个在分页任务上消耗了预期 3 倍 ACU 的真实会话，找出三个根本原因，并重写 Prompt 以节省 70% 的消耗。" prompt="这个会话为了给 GET /api/users 添加分页功能消耗了 42 ACU，但我原本预期大约是 12。请拆解 Devin 将最多时间花在哪些步骤上，它尝试了哪些死胡同或错误思路，以及我的 Prompt 中缺少了哪些关键信息。请给我一个修订后的结构化 Prompt，能避免这些问题。" category="Devin 优化" features="Advanced" agent="advanced" intent="analyze" />

<div className="uc-detail-wrapper">
  <Tip>不想手动设置？把此页面的链接粘贴到 Devin 会话中，然后让它帮你完成所有设置。</Tip>

  <Steps>
    <Step title="触发本次调查的会话">
      一位开发者让 Devin 为一个 API 端点添加分页功能。这个提示词很简短，看起来也很合理：

      <PromptBlock>
        ```txt 原始提示（不明确） theme={null}
        Add pagination to GET /api/users. Run the tests when done.
        ```
      </PromptBlock>

      这次会话顺利完成——测试通过，拉取请求 (pull request，PR) 看起来也不错。但它消耗了 **42 ACU**，而这本该是一个 **约 12 ACU** 的任务。成本是预期的三倍半，而这个功能在代码库的其他地方已经有可复用的实现模式。

      下面介绍如何找出问题所在，并确保这种情况不再发生。
    </Step>

    <Step title="从 Session Insights 入手">
      每个已完成的会话都可以进行一次免费的 [Session Insights](/zh/product-guides/session-insights) 分析。点击任意已完成会话顶栏中的 **灯泡图标**，然后点击 **Generate Analysis** 即可触发分析，无需高级会话。

      对于这个分页会话，Session Insights 标记了：

      * **Issue Timeline** — 在第 14 分钟和第 28 分钟处有红色标记，表示 Devin 在这些时间点完全更换了实现思路。
      * **Issues Detected** — “错误的代码库假设：在 `src/utils/paginate.ts` 已经存在的情况下仍从零实现分页功能”和 “错误的实现类型：使用了游标分页，但测试期望的是基于偏移量的分页。”
      * **Improved Prompt** — 填补了缺失上下文的重写版本，可直接复制使用。
      * **ACU Usage** — 使用了 42 个 ACU，被标记为相对于任务范围而言不成比例。

      对于许多会话来说，这就足够了。复制改进后的提示词，开启新会话并对比结果。但如果你希望看到按阶段划分的完整成本拆解，可以进一步深入查看。
    </Step>

    <Step title="获得逐阶段的拆解分析">
      在 Session Insights 面板中点击 **Investigate with Devin**，即可启动一个预加载了原始会话完整历史的 Devin 会话。你也可以手动启动一个新会话，并描述你希望分析的内容：

      <PromptBlock agent="advanced" intent="analyze">
        ```txt Analyze the pagination session theme={null}
        This session used 42 ACUs to add pagination to GET /api/users.
        I expected ~12. Break down:
        1. Where did Devin spend an abnormally long time?
        2. What dead ends or wrong approaches did it try?
        3. What could it have done more efficiently?
        4. What context was missing from my prompt?
        5. Give me a revised, structured prompt that would avoid these issues.
        ```
      </PromptBlock>

      Devin 会审查原始会话中的每一步操作，并找出时间使用低效的地方：

      ```
      会话分析 | 任务：为 GET /api/users 添加分页功能
      实际消耗：42 ACUs | 预期消耗：~12 ACUs

      已发现的低效问题：

      1. 不必要的探索 — 调查阶段耗时异常过长
         Devin 浏览了 23 个文件以寻找分页辅助工具。
         它从头构建了分页功能，随后才发现
         src/utils/paginate.ts，不得不重构所有内容。
         修复建议：在提示词中提及现有的工具函数。

      2. 方向错误 — 整个实现不得不重写
         Devin 实现了基于游标的分页。测试失败，
         因为该 API 使用的是基于偏移量的分页方式。它从头
         重写了整个实现。
         修复建议：在提示词中明确指定"基于偏移量"。

      3. 环境问题 — 反复安装失败
         由于私有注册表缺少 .npmrc 配置，npm install 失败了两次。
         Devin 通过变通方法重试。
         修复建议：将注册表配置添加到仓库初始化设置中。
      ```

      三个根本原因，其实只要改进提示词或代码仓库配置就都能避免。
    </Step>

    <Step title="重写提示并进行比较">
      你可以让 Devin 直接使用改进后的提示词开启一个新会话——无需手动复制粘贴。分析会生成一个结构化的提示词，准确包含之前缺失的上下文：

      <PromptBlock>
        ```txt Optimized prompt (structured) theme={null}
        Add offset-based pagination to GET /api/users.

        ## Context
        - Use our existing pagination utility at src/utils/paginate.ts
        - Follow the same pattern as GET /api/projects (already paginated)
        - Query params: page (default 1), limit (default 20, max 100)
        - Response shape: { data: User[], meta: { page, limit, total, totalPages } }

        ## Implementation
        1. Add page and limit query params with Zod validation
        2. Use paginate() from src/utils/paginate.ts to wrap the Prisma query
        3. Return the paginated response matching the shape above

        ## Testing
        - Run existing tests with npm test
        - Verify pagination works with 0 results, 1 page, and multiple pages
        - Verify invalid page/limit params return 400

        Do not open a PR until all tests pass.
        ```
      </PromptBlock>

      将这两个提示词并排对比：

      |                       | 原始版本            | 优化版本                        |
      | --------------------- | --------------- | --------------------------- |
      | **Pagination type**   | 未指定             | "offset-based"              |
      | **Existing utility**  | 未提及             | `src/utils/paginate.ts`     |
      | **Reference pattern** | 无               | "same as GET /api/projects" |
      | **Response shape**    | 未指定             | 明确的响应 schema                |
      | **Testing criteria**  | "Run the tests" | 具体的边界情况                     |
      | **ACU result**        | 42 ACUs         | \~12 ACUs                   |

      优化后的提示词消除了上述三大根本原因。Devin 无需再探索 23 个文件，一开始就选对分页类型，并且遵循经过验证的模式。
    </Step>

    <Step title="将发现转化为永久修复">
      单次提示重写只能在一个会话中节省 ACU。把这些结论转化为永久配置，则可以在所有后续会话中节省 ACU。

      **把会反复使用的上下文添加到 [Knowledge](/zh/product-guides/knowledge)。** 分页分析揭示了 Devin 会反复需要的两点信息——分页类型和工具函数的位置。把它们添加为 Knowledge 条目，这样每个会话都会自动从这些上下文开始：

      * *"所有 API 端点都使用基于偏移量的分页。公共工具函数位于 `src/utils/paginate.ts`。参考实现见 GET /api/projects。"*
      * *"使用 `npm test` 运行测试。使用 `npm run typecheck` 运行类型检查。"*

      **在 [environment configuration](/zh/onboard-devin/environment) 中修复 workspace 问题。** `npm install` 失败浪费的 3 个 ACU 是由于私有 registry 缺少 `.npmrc` 配置导致的。将 registry 配置添加到你的环境中，可以防止后续的每个会话再遇到这个错误。

      **批量分析以发现团队范围的共性模式。** 如果多名开发者都出现 ACU 消耗很高的会话，把它们一起分析以找出共同的根本原因：

      <PromptBlock agent="advanced" intent="analyze">
        ```txt 批量分析最近的会话 theme={null}
        这里是本周的 5 个会话：[粘贴会话链接]

        找出它们中 ACU 浪费的共同模式。为了防止这些问题在
        未来的每个会话中再次发生，我应该添加哪些 Knowledge 条目？
        ```
      </PromptBlock>
    </Step>
  </Steps>
</div>
