你的起点:构建你的第一个自主智能体

我的理解

这一课完整演示”竞争对手雷达”的构建,把前两课的方法论落到具体步骤。产品定义阶段确立监测 Company X 动向的北极星目标、单按钮 Web 应用 MVP(手动触发两阶段扫描)、含精准度(High Importance 必须与 background.md 战略目标直接相关)与可行动性(干净结构化 JSON)的 OKR。构建阶段委派 AI 实现含 /run-scan 端点、background.md 战略上下文、严格 JSON schema 的前后端。关键澄清:那段详尽的”怪兽级” prompt 并非一气呵成,而是管理者与 AI 多轮”委派—复盘”迭代的最终契约。评估迭代阶段对照 OKR 分析根因(background.md 太笼统 vs 提示词不够具体)并持续优化。

相关链接


原文

Lesson 37 of 46 你的起点:构建你的第一个自主智能体 / Your Starting Point: Building Your First Autonomous Agent

现在是时候把这套工作流付诸实践了。我们将完整走一遍构建”竞争对手雷达(Competitor Radar)“的示例——这是一个能够替你监测市场动态的自主智能体。

首先,打开我们的笔记本,定义我们的北极星目标。

核心问题:我需要持续了解我在 AI 视频生成赛道的主要竞争对手 Company X 的动向,但我没有时间每天读新闻。

MVP(最小可行产品):一个只有一个按钮的 Web 应用。点击该按钮即手动触发两阶段扫描(Two-Stage Scan)工作流。该工作流会读取本地的 background.md 文件以获取战略上下文,执行扫描,并在前端渲染一份结构化的 JSON 调研报告。(注意:真正主动型的 agent 应当按定时器自动运行,但手动触发是验证核心逻辑的完美 MVP。)

OKR:

Objective(目标):交付高质量、与战略相关的预警情报。

Key Result 1(精准度):最终报告中所有被标记为 High Importance(高重要性)的新闻条目,必须 100% 与 background.md 中定义的战略目标直接相关。

Key Result 2(可行动性):最终报告必须是一份干净、结构化的 JSON,便于前端解析与展示。

简报准备就绪,我们就可以向 AI 伙伴下达指令了。接下来你将看到一段非常详尽、分多部分的提示词(prompt),它定义了整个后端与前端逻辑。它看起来可能令人望而生畏,仿佛是一气呵成的英雄式产物。

让我们说清楚:现实中并非如此。这份打磨完善的任务简报,是一位管理者(你)和一位 AI 下属之间多轮对话后的最终产物。这场对话很可能始于一个简单得多的请求:

你:“创建一个 FastAPI 端点,用来运行一个两阶段扫描。“(AI 给出第一版草稿。)

你(反馈):“开头不错,但你理解错了阶段划分。Stage 1 应当只基于 background.md 生成搜索主题,而不是执行搜索。我们来修正这一点。”

你(细化):“很好。现在,对于 Stage 2,要确保针对每篇文章的分析提示词都同时包含内部上下文和外部信息,并且最终输出是一个严格遵循以下 schema 的 JSON 对象:{importance, summary, reasoning}。”

这种”委派—复盘”的迭代循环,正是”管理与创造”工作流(manage-and-create workflow)的核心。下面这段”怪兽级”提示词,不过是这一过程产出的最终、毫无歧义的契约。我们将其完整呈现,是为了给你一个清晰的、黄金标准级别的 AI Architect 终极委派范例。

I need to build the MVP for a “Strategic Information Radar” application. This is a full-stack application using FastAPI and a simple HTML/JS front-end.

  1. Core Context & Goal: At the root of the project, create a file named background.md. In it, write: “Our project’s primary strategic focus is on competitor breakthroughs related to ‘video lip-sync’ and ‘real-time generation’ technologies.” My goal is to run a workflow that finds external news relevant to this background.

  2. Technology & Tools: You must interact with the AI Builder Student Portal API. The OpenAPI specification is at https://space.ai-builders.com/backend/openapi.json. The API Key is [PASTE YOUR COPIED API KEY HERE]. Do not hardcode this key in the source code; load it from a .env file using python-dotenv. Create a .env file with the key SUPER_MIND_API_KEY. All AI calls must use the openai SDK, point to the correct base URL, and use the model supermind-agent-v1.

  3. Backend Implementation (FastAPI): Create a single POST endpoint at /run-scan. When called, it will execute the following Two-Stage Scan workflow:

Stage 1: Broad Scan

  • Read the content of background.md.
  • Make the first LLM call: Your prompt should instruct the AI: “Based on the following strategic background, survey 3-5 relevant areas for a broad news search.”
  • Store these results as the Broad Scan Report.

Stage 2: Deep Dive Analysis

  • Iterate through each article URL found in Stage 1.
  • For each URL, make a second LLM call with a prompt structured like this:
    • Internal Context: The content of background.md.
    • External Information: The full text content extracted from the article URL.
    • Analytical Task: “Based on the internal context, evaluate the strategic importance of the external information. Return a single JSON object with the following fields: importance (a string: ‘High’, ‘Medium’, or ‘Low’), summary (a one-sentence summary), and reasoning (a brief explanation for your importance rating).”
  • Collect all these JSON objects into a list, which forms the “Deep Dive Report.”
  • The /run-scan endpoint must finally return a single large JSON object containing both the Broad Scan Report and the Deep Dive Report.
  1. Front-End Implementation (HTML/JS): Create a simple web interface served by the FastAPI backend.
  • It should have a single button: Start Scan.
  • Clicking the button calls the /run-scan endpoint.
  • When the result is returned, render the structured JSON report in a clean, readable format, clearly separating the Broad Scan and Deep Dive sections.

运行你的 MVP。检视 Deep Dive Report。那些被标记为 High Importance 的条目真的重要吗?如果不重要,你的 MVP 也并非失败——这正是你扮演管理者角色的时刻。

分析根因。是 background.md 文件写得太笼统?还是分析任务的提示词不够具体?用这些洞察去迭代你的提示词与上下文文件。这种”构建—度量—优化”的迭代循环,才是打造强大 AI 系统的真正引擎。