尧图网站建设 尧图网络
  • 首页
  • 关于我们
  • 服务项目
  • 案例展示
  • 建站流程
  • 资讯中心
  • 联系我们
首页/资讯中心/详情

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

《60天AI学习计划启动 | Day 39: Agent 执行过程可视化(思考 / 工具 / 观察 / 回答》
📅 发布时间:2026/6/18 0:22:12

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 接口方便在不同项目里快速接入

相关新闻

  • CentOS 9 vs RHEL 9:性能与效率全面对比
  • EmotiVoice能否生成带有口音特色的角色语音?
  • 压力扫描阀详解:从核心原理到精准选型指南

最新新闻

  • 如何快速备份微信聊天记录:终极本地存储解决方案
  • 2026 齐齐哈尔防水修缮优选:吉修匠深耕松嫩平原嫩江鹤城腹地,专攻卫生间超极寒冻土黑土冻胀内陆苏打盐碱西部丘陵裂隙长效止水 - 吉修匠
  • PHP 双门双向门禁控制板实时监控源码
  • 寄快递怎么选更便宜?2026省钱技巧全攻略 - 快递物流资讯
  • Microchip嵌入式开发资源导航:从官方工具链到实战调试全指南
  • 3大突破性策略:让Perfetto性能分析从被动监控到主动优化的跨越式升级

日新闻

  • 2026年不锈钢卷板厂家推荐排行榜:冷轧热轧/304/201不锈钢卷板,高颜值耐腐蚀源头厂家实力精选 - 企业推荐官【官方】
  • FLUX.1-dev FP8模型实战指南:24GB以下显卡高效部署方案
  • 2026佛山长途搬家价目表:跨省跨市搬家费用完整计算指南 - 从来都是英雄出少年

周新闻

  • 3步解锁iOS设备:applera1n激活锁绕过完全指南
  • 39 2026 人工智能证书终极盘点,普通人选 AI 证书可以从这些方向入手
  • Redis 暴露公网有多危险?从端口检查到补救步骤

月新闻

  • 【总结】入门篇:50句话让你记住架构核心概念
  • WeChatMsg技术方案解析:实现Mac微信数据自主管理的完整解决方案
  • WeChatMsg:革新性微信数据备份方案,打造你的专属数字记忆库

关于尧图

  • 公司简介
  • 团队介绍
  • 企业文化
  • 荣誉资质

服务项目

  • 定制开发
  • 电商建站
  • UI 设计
  • 运维服务

快速链接

  • 案例展示
  • 建站流程
  • 常见问题
  • 资讯中心

联系方式

  • 📍北京市朝阳区互联网产业园 A 座 10 层
  • 📞400-888-8888
  • ✉️contact@rkmt.cn
  • 🕐周一至周日 9:00-21:00

© 2024 北京尧图网络科技有限公司 版权所有 | 京 ICP 备 XXXXXXXX 号