你正在 进阶版 · 🤖 智能体实验室 · ← 回到学院 · 进阶版主页 · 总入口

← 十二个项目

项目 07 · 观察驱动设计

不靠想象。不靠用户访谈。陪一个真人 8 小时。每一次他卡住的时刻都记下来。然后做一个智能体专门解决最高频的那个卡点。

怎么算"成"?

有一份 8 小时的观察日志(带时间戳);有一份排序后的"卡点清单";做出来的智能体专门解决了 #1 那个。

步骤 1 · 选对象、约时间

选一个你能陪 8 小时的真人。不是问"我能给你做什么"——是说"我想看你工作一天,我不打扰"。

步骤 2 · 观察日志

带本子或电子记录。每次他卡住(停下来想、问别人、放弃、转去做别的、生气)就写一行:

09:23  打开邮件,找昨天的会议记录,找了 4 分钟没找到,问助手。
10:11  写报告里要塞一段数据,要切到另一个软件,等了 15 秒才打开。
...

步骤 3 · 排序

8 小时下来你应该有 30+ 条。按"频率 × 痛苦度"打分。最高分的那条,就是你的智能体的题目。

步骤 4 · 做一个专门解决那一卡的智能体

不要做"通用助手"。专做一件事。用智谱清言 / Ollama 实现。

步骤 5 · 第二天回到那个人身边,陪他一小时

看你做的智能体在他真实工作流里怎么样。这不是 demo。是真用。

← 上一个下一个 →

工程测验 什么是「观察驱动设计」(Designed from watching)?
你要设计一个 agent。下面哪个做法最符合「观察驱动」的原则?
解释:「观察驱动」的意思是:不要猜测,要看真实的人怎么用东西。比如,你观察到用户经常问「这个功能有什么风险?」,那 agent 的设计就应该主动提示风险,而不是等用户问。
分步引导 设计一个 agent 的 3 个观察维度
  1. 记录「用户卡住的地方」。他们问的问题、犯的错误、放弃的时刻。
    看参考

    例:用户问「我能用这个工具做 X 吗?」—— 说明 agent 的能力边界不清晰,应该在 system prompt 里明确列出「能做的」和「不能做的」。

  2. 观察「用户重复做的事」。如果很多人都反复做同一件事,agent 应该提供快捷方式。
    看参考

    例:用户每次都要手动拷贝结果 → agent 应该加一个「一键拷贝」的功能。

  3. 记录「用户信任问题」。他们什么时候不敢点按钮、什么时候要求确认、什么时候问「这靠谱吗」。
    看参考

    例:用户在删除操作前都会犹豫 → agent 应该在删除前提示「确认删除吗?」,甚至显示「删除后的效果」。

动手 写一个 Agent State Machine(状态机)
任务:实现一个简单的 agent 状态机。状态包括:waiting、processing、asking_user、done。每个状态有入场动作、出场条件、转移规则。
参考实现

工程级参考答案(带完整注释):

// 生产级 Agent State Machine 实现
type AgentState = 'idle' | 'thinking' | 'awaiting_confirmation' | 'executing' | 'complete' | 'error';

interface AgentContext {
  userInput: string;
  action: string;
  requiresConfirmation: boolean;
  confirmationPrompt: string;
  result?: any;
  error?: Error;
}

class ProductionAgentSM {
  private state: AgentState = 'idle';
  private context: AgentContext;
  private stateHandlers: Map Promise>;
  
  constructor() {
    this.context = {
      userInput: '',
      action: '',
      requiresConfirmation: false,
      confirmationPrompt: ''
    };
    
    this.stateHandlers = new Map([
      ['idle', this.onIdle.bind(this)],
      ['thinking', this.onThinking.bind(this)],
      ['awaiting_confirmation', this.onAwaitingConfirmation.bind(this)],
      ['executing', this.onExecuting.bind(this)],
      ['complete', this.onComplete.bind(this)],
      ['error', this.onError.bind(this)],
    ]);
  }
  
  async process(userInput: string): Promise {
    this.context.userInput = userInput;
    this.state = 'thinking';
    
    try {
      await this.stateHandlers.get(this.state)?.(this.context);
      return this.getResponse();
    } catch (err) {
      this.state = 'error';
      this.context.error = err as Error;
      return `出错了:${this.context.error.message}`;
    }
  }
  
  private async onIdle(ctx: AgentContext) { /* ... */ }
  private async onThinking(ctx: AgentContext) {
    // 分析用户输入,决定是否需要确认
    if (this.requiresConfirmation(ctx.userInput)) {
      ctx.requiresConfirmation = true;
      this.state = 'awaiting_confirmation';
    } else {
      this.state = 'executing';
    }
  }
  private async onAwaitingConfirmation(ctx: AgentContext) { /* ... */ }
  private async onExecuting(ctx: AgentContext) {
    ctx.result = await this.execute(ctx.action);
    this.state = 'complete';
  }
  private async onComplete(ctx: AgentContext) { /* ... */ }
  private async onError(ctx: AgentContext) { /* ... */ }
  
  private requiresConfirmation(input: string): boolean {
    return /删除|清空|重置|发送/.test(input);
  }
  
  private async execute(action: string): Promise {
    // 实际执行逻辑
    return { success: true };
  }
  
  private getResponse(): string {
    // 根据当前状态返回用户友好的消息
    return `[${this.state}] Agent 状态已更新`;
  }
}
动手 根据观察写一个 Agent 的行为设计文档
任务:你观察了 3–5 个真实用户,记录他们用 AI 工具时的困惑、害怕、重复操作。根据这些观察,为一个 agent 写一份设计文档,定义它应该主动做什么(主动提示风险、主动确认、主动给示例)。

在下面框里写你自己的 prompt(可以用中文):

→ 打开通义千问粘贴试 已复制 ✓
看参考 prompt

参考 prompt(这是一个模板,你可以改细节):

你是一个领域专家。请基于以下规则回答问题:

1. 只基于你的专业知识和常见做法回答,不编造。
2. 如果问题超出你的领域,明确说「这不在我的专业范围内」。
3. 给出的建议应该包括「为什么」和「什么时候不应该这样做」。
4. 对于有争议的做法,列出不同观点。

现在,开始回答用户的问题。