当前位置: 首页 > 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.rkmt.cn/news/115014.html

相关文章:

  • CentOS 9 vs RHEL 9:性能与效率全面对比
  • EmotiVoice能否生成带有口音特色的角色语音?
  • 压力扫描阀详解:从核心原理到精准选型指南
  • 1小时打造个性化Flutter面试APP原型
  • 5个实际场景下eval的替代方案
  • AI如何自动清理Windows系统垃圾文件
  • 2025长沙美甲美睫培训学校TOP5权威推荐:速成班费用与优 - myqiye
  • CH585 CH584 CH592 RF PHY/Basic 2.4G 包格式
  • 忘记密码?3分钟快速解锁密码锁的技巧
  • 2025年内衬不锈钢复合管品牌推荐:新澎内衬不锈钢复合管质量 - mypinpai
  • 用Packet Tracer快速验证网络架构设计的3种方法
  • 如何用AI一键生成Jupyter Notebook环境配置脚本
  • CMHHP实战:构建智能慢性病管理系统
  • 工程优化- Tenacity库用于重试机制及使用示例
  • 传统VS现代:EasyPlayer开发效率提升300%的秘密
  • 用TSX快速构建产品原型的5个技巧
  • 告别传统测速:AI如何将网络诊断效率提升10倍
  • 互联网档案馆使用指南:小白也能懂的历史网页查询
  • 建筑渗漏治理的标准化实践:基于上海芮生建设14年经验与“六步法”的技术解析 - shruisheng
  • 告别重复代码:Java自定义注解效率提升300%的秘诀
  • Python小白必看:5分钟掌握Switch Case的Python式写法
  • 快速验证:CentOS7换源对软件安装速度的影响
  • 2025 年 12 月管道电预热厂家权威推荐榜:专业解决热力管网应力难题,高效施工与长效稳定运行口碑之选 - 品牌企业推荐师(官方)
  • 追踪链路--使用iptables/ipvs来记录后端pod真实ip
  • Arthas,阿里巴巴开款的Java诊断神器!
  • 比传统traceroute快10倍:新一代网络诊断工具
  • EmotiVoice语音合成能否实现跨语言情感迁移?研究进展
  • 5分钟构建API错误监控原型:从500错误开始
  • 高表现力TTS新星:EmotiVoice让机器说话更有人情味
  • 企业级项目实战:Yarn安装失败的5种应急方案