当前位置: 首页 > news >正文

《60天AI学习计划启动 | Day 39: Agent 执行过程可视化(思考 / 工具 / 观察 / 回答》

Day 39:Agent 执行过程可视化(思考 / 工具 / 观察 / 回答)

学习目标

  • 理解 ReAct / Agent 在“思考→行动→观察→总结”的执行轨迹
  • 会设计 一套前端展示结构(Timeline / Steps)
  • 实现 简单的「Agent 调用步骤时间线」组件

核心知识点

  • 1. Agent 步骤抽象

    • 一次 Agent 调用可以拆成若干 Step:
      • thought:思考/理由
      • action:调用的工具名 + 参数
      • observation:工具执行结果摘要
      • final_answer:最终回答
    • 前端抽象:
      export type AgentStepType = 'thought' | 'action' | 'observation' | 'final'export interface AgentStep {id: stringtype: AgentStepTypecontent: stringtoolName?: stringcreatedAt: number
      }
      
  • 2. 展示形态

    • 时间线 / 步骤条:
      • 按顺序展示:Step1 思考 → Step2 调用X工具 → Step3 观察 → ... → 最终回答
    • 交互:
      • 支持折叠「思考」内容(只展开有需要的)
      • 在工具步骤里高亮工具名、参数/结果要点

实战作业(附代码)

  • 作业 1:定义 Agent 执行轨迹类型
export type AgentStepType = 'thought' | 'action' | 'observation' | 'final'export interface AgentStep {id: stringtype: AgentStepTypecontent: stringtoolName?: stringcreatedAt: number
}export interface AgentTrace {id: stringquestion: stringsteps: AgentStep[]
}
  • 作业 2:简单时间线组件(React)
import React from 'react'
import type { AgentStep, AgentStepType } from './types'const typeLabel: Record<AgentStepType, string> = {thought: '思考',action: '调用工具',observation: '观察结果',final: '最终回答'
}const typeColor: Record<AgentStepType, string> = {thought: '#9e9e9e',action: '#2196f3',observation: '#4caf50',final: '#ff9800'
}interface AgentTimelineProps {steps: AgentStep[]
}export const AgentTimeline: React.FC<AgentTimelineProps> = ({ steps }) => {return (<div style={{ borderLeft: '2px solid #eee', paddingLeft: 12 }}>{steps.map((step) => (<div key={step.id} style={{ marginBottom: 12, position: 'relative' }}><divstyle={{position: 'absolute',left: -10,top: 4,width: 8,height: 8,borderRadius: '50%',background: typeColor[step.type]}}/><div style={{ fontSize: 12, color: typeColor[step.type] }}>{typeLabel[step.type]}{step.toolName && ` · ${step.toolName}`}</div><div style={{ fontSize: 12, whiteSpace: 'pre-wrap' }}>{step.content}</div><div style={{ fontSize: 10, color: '#aaa', marginTop: 2 }}>{new Date(step.createdAt).toLocaleTimeString()}</div></div>))}</div>)
}
  • 作业 3:将后端 Agent 日志映射为前端 AgentTrace(示例)
// 假设后端返回类似:
/*
{"question": "...","trace": [{ "type": "thought", "content": "需要先查天气...", "ts": 123 },{ "type": "action", "tool": "get_weather", "content": "city=Beijing", "ts": 124 },{ "type": "observation", "content": "返回温度 26℃", "ts": 125 },{ "type": "final", "content": "北京现在 26℃,建议...", "ts": 126 }]
}
*/interface BackendStep {type: AgentStepTypecontent: stringtool?: stringts: number
}export function mapBackendTrace(question: string,raw: BackendStep[]
): AgentTrace {return {id: crypto.randomUUID(),question,steps: raw.map((s, idx) => ({id: `${idx}`,type: s.type,content: s.content,toolName: s.tool,createdAt: s.ts}))}
}

明日学习计划预告(Day 40)

  • 主题:前端 AI SDK 抽象
  • 方向
    • useChat / useSSE / useRetry / useAgentTimeline 等封装成一个小 SDK 结构
    • 设计一个最小的 aiClient 接口方便在不同项目里快速接入
http://www.jsqmd.com/news/104191/

相关文章:

  • 零基础学Java:从安装到第一个程序的完整指南
  • CentOS 9 vs RHEL 9:性能与效率全面对比
  • 1小时用Promise.js打造天气预报应用原型
  • 用海拥技术1小时打造可运行的产品原型
  • 飞凌嵌入式ElfBoard-目录权限之access
  • Cursor操作效率提升:从手动到自动的进阶技巧
  • EmotiVoice能否生成带有口音特色的角色语音?
  • 压力扫描阀详解:从核心原理到精准选型指南
  • 30分钟快速验证VXLAN方案的4种方法
  • 5个实际场景下eval的替代方案
  • 2025 年 12 月热处理加工厂家权威推荐榜:温合金/CQI-9/镍基合金/真空淬火等专业工艺,匠心淬炼与精密控温典范之选 - 品牌企业推荐师(官方)
  • 《60天AI学习计划启动 | Day 40: 前端 AI SDK 抽象(aiClient + hooks)》
  • AI对比:传统刷题与智能生成Flutter面试准备
  • Spring新手必看:5步搞定Bean初始化失败的简单教程
  • 固件升级时fd一直增加,升级十几次后crash
  • AI如何自动清理Windows系统垃圾文件
  • 2025长沙美甲美睫培训学校TOP5权威推荐:速成班费用与优 - myqiye
  • 基于CentOS 9的快速开发环境搭建指南
  • CentOS 9在企业级Web服务中的实战部署
  • 2025年铝箔翅片定制厂家权威推荐榜单:铝防爆箔/亲水铝箔/铝翅片源头厂家精选 - 品牌推荐官
  • 2025年内衬不锈钢复合管品牌推荐:新澎内衬不锈钢复合管质量 - mypinpai
  • 事倍功半是蠢蛋69 TODO
  • 用Packet Tracer快速验证网络架构设计的3种方法
  • 企业级Spring Boot项目中的AutoConfiguration.imports实战
  • JookDB在电商平台中的实战应用案例
  • 《60天AI学习计划启动 | Day 38: 多会话 多 Tab 同步(前端层)》
  • 传统网页存档vs互联网档案馆:效率对比分析
  • 如何用AI一键生成Jupyter Notebook环境配置脚本
  • 企业级Python环境部署实战 - 官方源的正确使用
  • CMHHP实战:构建智能慢性病管理系统