详情

首页手游攻略 刚刚:AgentOps 开始升温:任务追踪、失败恢复和执行日志成为企业智能体新底座

刚刚:AgentOps 开始升温:任务追踪、失败恢复和执行日志成为企业智能体新底座

佚名 2026-07-20 09:05:08

刚刚,AgentOps 开始升温:任务追踪、失败恢复和执行日志成为企业智能体新底座

{"type":"doc","content":[{"type":"heading","attrs":{"id":"10771a3c-267a-43b4-bf91-06e77ec32522","textAlign":"inherit","indent":0,"level":2,"isHoverDragHandle":false},"content":[{"type":"text","text":"概述"}]},{"type":"paragraph","attrs":{"id":"4d155be9-297f-452e-b29e-a87e1e39b98a","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"2026 年,AI Agent 正在从演示阶段进入真实业务流程。"}]},{"type":"paragraph","attrs":{"id":"a945a745-bf50-49a0-90a9-991e2f2aeea1","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"过去,很多智能体应用更像一个高级聊天工具。用户输入任务,模型生成计划,再调用几个工具返回结果。这个阶段,团队更关注 Agent 能不能完成任务。"}]},{"type":"paragraph","attrs":{"id":"be0156c1-80bc-4a5d-8728-7b816cc19bd8","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"但当 Agent 开始进入客服、研发、运营、数据分析、运维和办公自动化场景后,新的问题出现了。"}]},{"type":"paragraph","attrs":{"id":"83663afe-d9bc-41cd-8b00-f154340e5fc0","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"任务执行到哪一步了?"}]},{"type":"paragraph","attrs":{"id":"a213467e-4c84-47ff-aa98-404e6f739872","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"工具调用为什么失败?"}]},{"type":"paragraph","attrs":{"id":"1b0b905f-5fa5-4398-b9fe-e48fd2359345","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"失败后是否可以重试?"}]},{"type":"paragraph","attrs":{"id":"920fab4c-4eb8-41e4-928c-4900bd982b75","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"模型生成的计划是否被记录?"}]},{"type":"paragraph","attrs":{"id":"f4daebae-3ac7-4d3b-ab43-2f491536c08d","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"一次任务消耗了多少时间和资源?"}]},{"type":"paragraph","attrs":{"id":"f8d0191b-5f7b-4794-851f-762db3a4cf4e","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"这些问题都指向一个新方向:AgentOps。"}]},{"type":"paragraph","attrs":{"id":"1ce98c3f-f52e-4a60-b349-627138b03fb8","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"AgentOps 可以理解为面向 AI Agent 的运行管理体系。它不仅关注模型回答结果,还关注智能体的任务拆解、工具调用、执行日志、失败恢复、状态流转和审计记录。"}]},{"type":"paragraph","attrs":{"id":"3c2769b4-5f56-4790-b358-3642c5e26856","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"这意味着,企业不再只需要一个“会回答的智能体”,而是需要一个“可追踪、可恢复、可治理的智能体系统”。"}]},{"type":"horizontalRule","attrs":{"id":"cf9e652a-be0b-46fa-aab5-c475fa72698f","isHoverDragHandle":false}},{"type":"heading","attrs":{"id":"30207425-cd01-40da-ac8d-50736a86fbed","textAlign":"inherit","indent":0,"level":2,"isHoverDragHandle":false},"content":[{"type":"text","text":"一、为什么 AgentOps 变重要?"}]},{"type":"paragraph","attrs":{"id":"68fde0b0-cb45-4c78-9ee0-7ee405c29e2c","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"单次对话失败,影响可能不大。"}]},{"type":"paragraph","attrs":{"id":"caf8a5a8-61e3-4687-a1a6-680e065348bf","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"但如果 Agent 正在执行真实业务任务,例如生成日报、查询数据、调用接口、更新工单、分析日志或发送通知,那么失败就不能被简单忽略。"}]},{"type":"paragraph","attrs":{"id":"aeb072a4-aecc-4c59-bb70-1df00f97b019","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"企业级 Agent 至少需要具备几个能力:"}]},{"type":"orderedList","attrs":{"id":"571bbdbb-0097-4510-b9b9-5ac8e7c1f74a","start":1,"isHoverDragHandle":false},"content":[{"type":"listItem","attrs":{"id":"5981ad7b-a0a2-4ad5-a673-91af4b00c4e8"},"content":[{"type":"paragraph","attrs":{"id":"f220e836-2f61-4437-aff2-dc9e1ee54d07","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"每个任务都有唯一 ID;"}]}]},{"type":"listItem","attrs":{"id":"6d330e87-4f61-4644-b474-3bfffb2b8699"},"content":[{"type":"paragraph","attrs":{"id":"123702a0-ef4a-4461-90bd-ad9e6b685f44","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"每个步骤都有执行状态;"}]}]},{"type":"listItem","attrs":{"id":"9669e2b4-72bb-4470-a1f0-54533f3e482e"},"content":[{"type":"paragraph","attrs":{"id":"4fce6850-18a3-4868-ab2b-1a142698e8d0","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"每次工具调用都有日志;"}]}]},{"type":"listItem","attrs":{"id":"7101c247-cb89-46fe-804a-3b75813f4905"},"content":[{"type":"paragraph","attrs":{"id":"dfcc1787-d674-4e14-9209-a8fa7473c53e","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"失败后可以自动重试;"}]}]},{"type":"listItem","attrs":{"id":"b80efef3-c01a-4a7d-a711-8697f9f808ae"},"content":[{"type":"paragraph","attrs":{"id":"81ecb76c-318c-47ab-8cb3-c49fbd31be31","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"最终结果可以被审计;"}]}]},{"type":"listItem","attrs":{"id":"1e4a25d7-bbe2-4c1a-ac0e-5e02a9af486a"},"content":[{"type":"paragraph","attrs":{"id":"daf3f786-e258-448f-8e4d-3b704d952b5b","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"历史任务可以被查询。"}]}]}]},{"type":"paragraph","attrs":{"id":"0251ae0e-7049-4f25-b21a-764301e0cf62","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"下面用 Python 写一个简化版 AgentOps 系统,模拟智能体任务追踪、工具执行、失败重试和运行报告。"}]},{"type":"horizontalRule","attrs":{"id":"37a3ffe4-e9ec-41b9-a2ae-e065b4c5506c","isHoverDragHandle":false}},{"type":"heading","attrs":{"id":"33cc9f5b-8c22-46f8-a18e-bb3a6925d39a","textAlign":"inherit","indent":0,"level":2,"isHoverDragHandle":false},"content":[{"type":"text","text":"二、基础配置:定义任务状态和工具"}]},{"type":"paragraph","attrs":{"id":"4000e054-be39-49f4-a366-4dce151d1a01","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"第一步是定义任务状态和可用工具。"}]},{"type":"paragraph","attrs":{"id":"b7e030c5-02a4-4ef1-b702-33f427401d68","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"在 AgentOps 系统中,状态非常重要。任务不能只是“成功”或“失败”,还应该记录执行中、重试中、部分失败等中间状态。"}]},{"type":"codeBlock","attrs":{"id":"91b1cbba-1894-449f-a1ec-28174ac4be1f","language":"javascript","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":"","languageByAi":"javascript"},"content":[{"type":"text","text":"import timenimport jsonnimport randomnimport hashlibnfrom datetime import datetimenfrom typing import Dict, Any, CallablennnTASK_STATUS = {n"PENDING": "等待执行",n"RUNNING": "执行中",n"RETRYING": "重试中",n"SUCCESS": "执行成功",n"FAILED": "执行失败"n}nnnTOOL_CONFIG = {n"search_tool": {n"description": "搜索技术资料",n"retry": 2n},n"summary_tool": {n"description": "生成摘要内容",n"retry": 1n},n"report_tool": {n"description": "生成结构化报告",n"retry": 1n},n"notify_tool": {n"description": "发送任务通知",n"retry": 2n}n}nnnTASK_STORE = {}nSTEP_LOGS = []n"}]},{"type":"paragraph","attrs":{"id":"a29fb568-7508-4530-ab63-ee22e317d8a6","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"这部分配置相当于 AgentOps 的基础运行环境。"}]},{"type":"paragraph","attrs":{"id":"986cdfda-c3ab-4f7b-aea9-a3ac1406ceec","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"它决定系统有哪些工具,以及每个工具失败后最多可以重试几次。"}]},{"type":"horizontalRule","attrs":{"id":"75acb134-9cd6-451b-a6ea-ad8270fbc8aa","isHoverDragHandle":false}},{"type":"heading","attrs":{"id":"0f423ce9-2133-4648-bd0d-17edd361b64f","textAlign":"inherit","indent":0,"level":2,"isHoverDragHandle":false},"content":[{"type":"text","text":"三、任务 ID:为每次执行建立唯一标识"}]},{"type":"paragraph","attrs":{"id":"29c6e9e6-4d46-437b-95ee-f8d4715a5456","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"第二步是生成任务 ID。"}]},{"type":"paragraph","attrs":{"id":"3b0ce6c9-724e-47da-a94c-9cb75fb69723","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"企业系统中,每一个 Agent 任务都应该有唯一标识,这样后续才能查询日志、定位问题和生成报告。"}]},{"type":"codeBlock","attrs":{"id":"455029f3-9bd7-4596-af78-37dc013e68ef","language":"javascript","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":"","languageByAi":"javascript"},"content":[{"type":"text","text":"def now_ms():nreturn int(time.time() * 1000)nnndef build_task_id(user_id, task_text):nraw = f"{user_id}-{task_text}-{now_ms()}"nnreturn hashlib.md5(nraw.encode("utf-8")n).hexdigest(otterly.cn)nnndef create_task(user_id, task_text):ntask_id = build_task_id(user_id, task_text)nntask = {n"task_id": task_id,n"user_id": user_id,n"task_text": task_text,n"status": "PENDING",n"steps": [],n"result": None,n"created_at": datetime.now().isoformat(),n"updated_at": datetime.now().isoformat()n}nnTASK_STORE[task_id] = tasknnreturn taskn"}]},{"type":"paragraph","attrs":{"id":"e4fde2e7-88b9-4f99-9894-e4beefe6e73e","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"任务 ID 是 AgentOps 的入口。"}]},{"type":"paragraph","attrs":{"id":"a3bad66a-5067-415f-81c9-256f74c946e2","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"只要有了任务 ID,系统就可以把计划、步骤、日志和结果关联起来。"}]},{"type":"horizontalRule","attrs":{"id":"19a47d24-b6e5-4ca2-b38f-4b9afb9e92ff","isHoverDragHandle":false}},{"type":"heading","attrs":{"id":"65209bc7-4fc1-4a26-b534-51e904f7380b","textAlign":"inherit","indent":0,"level":2,"isHoverDragHandle":false},"content":[{"type":"text","text":"四、任务规划:把用户需求拆成步骤"}]},{"type":"paragraph","attrs":{"id":"db1d64ee-0e1d-4d7f-963f-91945cabc2b9","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"第三步是任务规划。"}]},{"type":"paragraph","attrs":{"id":"8b6cd605-5b5a-4a55-b01b-af56fbbd60e0","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"这里使用简单规则模拟 Agent 计划生成。真实系统中,可以让大模型根据用户需求自动生成任务步骤。"}]},{"type":"codeBlock","attrs":{"id":"191b9743-4ed0-4191-a63a-bb2ede1f54b6","language":"javascript","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":"","languageByAi":"javascript"},"content":[{"type":"text","text":"def plan_task(task_text):nsteps = []nnif "日报" in task_text or "报告" in task_text:nsteps = [n{n"step_name": "search_news",n"tool": "search_tool",n"input": {n"query": task_textn}n},n{n"step_name": "summarize_news",n"tool": "summary_tool",n"input": {n"mode": "technology_summary"n}n},n{n"step_name": "build_report",n"tool": "report_tool",n"input": {n"format": "json"n}n},n{n"step_name": "send_notify",n"tool": "notify_tool",n"input": {n"channel": "team"n}n}n]nelse:nsteps = [n{n"step_name": "default_summary",n"tool": "summary_tool",n"input": {n"content": task_textn}n}n]nnreturn stepsn"}]},{"type":"paragraph","attrs":{"id":"68be27df-f2c4-40de-a4ff-11f455522310","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"任务规划是智能体执行的核心。"}]},{"type":"paragraph","attrs":{"id":"e28e6b96-0b50-4de1-b0c1-74d413f91b5a","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"一个复杂任务如果不拆解,就很难追踪,也很难恢复。"}]},{"type":"horizontalRule","attrs":{"id":"bb065c76-2680-4cef-8052-a6e72fa572d8","isHoverDragHandle":false}},{"type":"heading","attrs":{"id":"f9e88df5-75b6-4aeb-bd5d-c6665fe5e41a","textAlign":"inherit","indent":0,"level":2,"isHoverDragHandle":false},"content":[{"type":"text","text":"五、工具执行:模拟不同工具调用结果"}]},{"type":"paragraph","attrs":{"id":"fc240847-1e4c-4650-991c-b366b1c99f23","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"第四步是实现工具调用。"}]},{"type":"paragraph","attrs":{"id":"34797b89-a889-4d89-8d5a-a96655c4edd1","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"这里用随机失败模拟真实环境中的不稳定情况。真实系统中,失败可能来自网络超时、接口报错、权限不足、参数错误或模型输出异常。"}]},{"type":"codeBlock","attrs":{"id":"0c4aa84f-e288-4ca9-8623-ecf1381a615e","language":"javascript","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":"","languageByAi":"javascript"},"content":[{"type":"text","text":"def search_tool(query):nif random.random() < 0.15:nraise RuntimeError("搜索工具请求超时")nnreturn {n"items": [n"AI Agent 正在进入企业流程",n"RAG 系统开始重视召回质量",n"Serverless 与智能任务结合加速"n],n"query": queryn}nnndef summary_tool(content=None, mode=None):nif random.random() < 0.1:nraise RuntimeError("摘要生成失败")nnreturn {n"summary": "本次内容显示,AI 应用正在从单点能力走向工程化落地。",n"mode": mode or "default"n}nnndef report_tool(format="json"):nif random.random() < 0.1:nraise RuntimeError("报告生成失败")nnreturn {n"report_name": "AI 技术任务报告",n"format": format,n"content": "这里是结构化报告内容。"n}nnndef notify_tool(channel):nif random.random() < 0.12:nraise RuntimeError("通知发送失败")nnreturn {n"channel": channel,n"status": "sent"n}nnnTOOL_REGISTRY: Dict[str, Callable] = {n"search_tool": search_tool,n"summary_tool": summary_tool,n"report_tool": report_tool,n"notify_tool": notify_tooln}n"}]},{"type":"paragraph","attrs":{"id":"cc9b8b24-f44a-4a2d-a575-c232bc1c3c3c","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"工具失败是 Agent 系统中很常见的问题。"}]},{"type":"paragraph","attrs":{"id":"7fce7933-3ad1-4d65-b2a6-e62cf53dd0a7","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"AgentOps 的价值,就是让失败变得可见、可查、可恢复。"}]},{"type":"horizontalRule","attrs":{"id":"d515bf75-6483-47d0-9a7d-d2104935fe59","isHoverDragHandle":false}},{"type":"heading","attrs":{"id":"3e36cd4a-3dd1-4874-bfe8-ed2a2567cf4b","textAlign":"inherit","indent":0,"level":2,"isHoverDragHandle":false},"content":[{"type":"text","text":"六、步骤日志:记录每一次工具调用"}]},{"type":"paragraph","attrs":{"id":"e60b1255-25b0-40cd-876a-9c692f0310d6","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"第五步是记录步骤日志。"}]},{"type":"paragraph","attrs":{"id":"1884c7b3-965a-4d3b-9313-7b40082d5cfd","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"每一个步骤都应该记录开始时间、结束时间、耗时、输入、输出、错误信息和重试次数。"}]},{"type":"codeBlock","attrs":{"id":"49debb65-a63d-42c2-aa2b-9d3276ba7f14","language":"javascript","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":"","languageByAi":"javascript"},"content":[{"type":"text","text":"def write_step_log(record):nSTEP_LOGS.append(record)nnndef execute_tool_with_retry(task_id, step):ntool_name = step["tool"]ntool_func = TOOL_REGISTRY[tool_name]nretry_limit = TOOL_CONFIG[tool_name]["retry"]nnattempt = 0nlast_error = Nonennwhile attempt <= retry_limit:nattempt = 1nstart_time = now_ms()nntry:nresult = tool_func(**step["input"])nend_time = now_ms()nnlog = {n"task_id": task_id,n"step_name": step["step_name"],n"tool": tool_name,n"status": "SUCCESS",n"attempt": attempt,n"input": step["input"],n"output_preview": str(result)[:200],n"duration_ms": end_time - start_time,n"error": None,n"time": datetime.now().isoformat()n}nnwrite_step_log(log)nnreturn {n"status": "SUCCESS",n"result": result,n"attempt": attemptn}nnexcept Exception as error:nend_time = now_ms()nlast_error = str(error)nnlog = {n"task_id": task_id,n"step_name": step["step_name"],n"tool": tool_name,n"status": "FAILED",n"attempt": attempt,n"input": step["input"],n"output_preview": None,n"duration_ms": end_time - start_time,n"error": last_error,n"time": datetime.now().isoformat()n}nnwrite_step_log(log)nnreturn {n"status": "FAILED",n"error": last_error,n"attempt": attemptn}n"}]},{"type":"paragraph","attrs":{"id":"273d73ae-923a-40f2-8d35-0a91b1efe2d7","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"这部分是 AgentOps 的关键代码。"}]},{"type":"paragraph","attrs":{"id":"33d26cb8-834e-413f-8609-6155a91a1702","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"它让工具调用不再是黑盒,而是每一步都有记录。"}]},{"type":"horizontalRule","attrs":{"id":"4756ad94-b918-41f3-a230-bac3bcf3f3d7","isHoverDragHandle":false}},{"type":"heading","attrs":{"id":"b5026c96-9e76-497e-a5a2-bb6f56157c36","textAlign":"inherit","indent":0,"level":2,"isHoverDragHandle":false},"content":[{"type":"text","text":"七、任务执行器:串联完整 Agent 流程"}]},{"type":"paragraph","attrs":{"id":"c577395a-d617-4912-8951-c3aab47c563e","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"第六步是执行完整任务。"}]},{"type":"paragraph","attrs":{"id":"1beb11f9-76df-4ed2-9f29-050347e70240","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"执行器会更新任务状态,依次执行步骤,并在失败时停止任务。"}]},{"type":"codeBlock","attrs":{"id":"c5104495-8222-483b-8043-c7e635452f0f","language":"javascript","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":"","languageByAi":"javascript"},"content":[{"type":"text","text":"def update_task_status(task_id, status):ntask = TASK_STORE[task_id]ntask["status"] = statusntask["updated_at"] = datetime.now().isoformat()nnndef run_agent_task(user_id, task_text):ntask = create_task(user_id, task_text)ntask_id = task["task_id"]nnupdate_task_status(task_id, "RUNNING")nnsteps = plan_task(task_text)ntask["steps"] = stepsnnfinal_outputs = []nnfor step in steps:nresult = execute_tool_with_retry(ntask_id=task_id,nstep=stepn)nnfinal_outputs.append({n"step_name": step["step_name"],n"tool": step["tool"],n"result": resultn})nnif result["status"] == "FAILED":nupdate_task_status(task_id, "FAILED")ntask["result"] = {n"message": "任务执行失败",n"failed_step": step["step_name"],n"error": result.get("error"),n"outputs": final_outputsn}nreturn tasknnupdate_task_status(task_id, "SUCCESS")nntask["result"] = {n"message": "任务执行成功",n"outputs": final_outputsn}nnreturn taskn"}]},{"type":"paragraph","attrs":{"id":"7308cbad-d9fd-4aa4-b7ab-3c9f825d67d0","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"任务执行器相当于 AgentOps 的调度中心。"}]},{"type":"paragraph","attrs":{"id":"9a7515f4-f8dc-43ed-86f5-e016d7be9b87","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"它不只负责运行任务,还负责更新状态和记录最终结果。"}]},{"type":"horizontalRule","attrs":{"id":"495c6d24-f73c-44a1-a165-aaf0b1e0d021","isHoverDragHandle":false}},{"type":"heading","attrs":{"id":"16c694d0-b24a-4f3d-92c3-4b6709b5c501","textAlign":"inherit","indent":0,"level":2,"isHoverDragHandle":false},"content":[{"type":"text","text":"八、查询任务:查看执行状态和日志"}]},{"type":"paragraph","attrs":{"id":"49b19947-11d9-4d2f-88f2-93e16c293772","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"第七步是任务查询。"}]},{"type":"paragraph","attrs":{"id":"a0e9bdcb-60bf-4717-8a15-92b540af9d17","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"企业系统中,用户或管理员需要随时查看某个任务的执行状态。"}]},{"type":"codeBlock","attrs":{"id":"1d042210-1b55-4f48-b5e0-6942553d6e3c","language":"javascript","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":"","languageByAi":"javascript"},"content":[{"type":"text","text":"def get_task_logs(task_id):nreturn [nlog for log in STEP_LOGSnif log["task_id"] == task_idn]nnndef get_task_detail(task_id):ntask = TASK_STORE.get(task_id)nnif not task:nreturn {n"error": "task not found"n}nnreturn {n"task": task,n"logs": get_task_logs(task_id)n}n"}]},{"type":"paragraph","attrs":{"id":"e634a6ca-d2a3-43cc-8183-f11659f58348","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"这一步让 Agent 任务具备可追踪能力。"}]},{"type":"paragraph","attrs":{"id":"5d142fe4-7ebb-485b-985a-f09a9b0b9458","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"当用户反馈“任务没有成功”时,系统可以直接查看步骤日志,而不是重新猜测原因。"}]},{"type":"horizontalRule","attrs":{"id":"eb4e2a02-52ec-47fa-8a68-e090f2b592b9","isHoverDragHandle":false}},{"type":"heading","attrs":{"id":"69ce3bb0-f233-4a12-b77c-ba2ecd5e0cec","textAlign":"inherit","indent":0,"level":2,"isHoverDragHandle":false},"content":[{"type":"text","text":"九、生成 AgentOps 运行报告"}]},{"type":"paragraph","attrs":{"id":"a8a69ef7-def4-4bb4-a8ca-6131bbe71d81","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"最后一步是生成整体运行报告。"}]},{"type":"paragraph","attrs":{"id":"36adf966-1d05-441c-a530-345861651cc6","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"报告可以统计任务总数、成功率、失败任务数量和平均步骤耗时。"}]},{"type":"codeBlock","attrs":{"id":"1207b4b9-1ed2-4d44-a125-48c33e6ed99e","language":"javascript","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":"","languageByAi":"javascript"},"content":[{"type":"text","text":"def generate_agentops_report():ntasks = list(TASK_STORE.values())ntotal_tasks = len(tasks)nnsuccess_tasks = len([ntask for task in tasksnif task["status"] == "SUCCESS"n])nnfailed_tasks = len([ntask for task in tasksnif task["status"] == "FAILED"n])nnavg_step_latency = 0nnif STEP_LOGS:navg_step_latency = round(31222.t.kuaisou.comnsum(log["duration_ms"] for log in STEP_LOGS) / len(STEP_LOGS),n2n)nnsuccess_rate = 0nnif total_tasks > 0:nsuccess_rate = round(nsuccess_tasks / total_tasks * 100,n2n)nnreturn {n"report_name": "AgentOps 智能体运行报告",n"total_tasks": total_tasks,n"success_tasks": success_tasks,n"failed_tasks": failed_tasks,n"success_rate": success_rate,n"total_steps": len(STEP_LOGS),n"avg_step_latency_ms": avg_step_latency,n"generate_time": datetime.now().isoformat()n}nnnif __name__ == "__main__":ntask_samples = [n"请生成今日 AI 技术日报",n"请生成 RAG 工程化趋势报告",n"请总结这段内容"n]nnfor text in task_samples:ntask = run_agent_task(nuser_id="user_001",ntask_text=textn)nnprint(json.dumps(ntask,nensure_ascii=False,nindent=2n))nnreport = generate_agentops_report()nnprint(json.dumps(nreport,nensure_ascii=False,nindent=2n))n"}]},{"type":"horizontalRule","attrs":{"id":"44584740-b1eb-48cd-8364-d2bcb7af0f3b","isHoverDragHandle":false}},{"type":"heading","attrs":{"id":"ae8cf6e2-9642-4883-ba03-db1391473a88","textAlign":"inherit","indent":0,"level":2,"isHoverDragHandle":false},"content":[{"type":"text","text":"十、趋势判断"}]},{"type":"paragraph","attrs":{"id":"72871771-1172-4cfb-9378-b00b20c1695e","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"从这套流程可以看到,AgentOps 的核心不是让智能体变得更“聪明”,而是让智能体变得更“可管理”。"}]},{"type":"paragraph","attrs":{"id":"c4381238-2aff-44e1-a95d-759b9dd8f93c","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"当 Agent 只是演示工具时,失败可以被忽略;当 Agent 进入企业流程后,失败就必须被记录、定位和恢复。"}]},{"type":"paragraph","attrs":{"id":"f19bff01-9fcf-48cd-b0a5-2b7ff5256ada","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"未来,企业级 Agent 系统不会只拼模型能力,还会拼任务管理能力。"}]},{"type":"paragraph","attrs":{"id":"b491f3a2-27f3-435f-af19-7082f8373874","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"任务状态、步骤日志、失败重试、工具审计和运行报告,将成为智能体系统的重要基础设施。"}]},{"type":"paragraph","attrs":{"id":"de4a342f-4b3f-44b8-aac4-6214959889c8","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"谁能更早建立 AgentOps 体系,谁就更容易把 AI Agent 从 Demo 推向生产环境。"}]}]}","createTime":1782898307,"ext":{"closeTextLink":0,"comment_ban":0,"description":"","focusRead":0},"favNum":0,"html":"","isOriginal":0,"likeNum":0,
点击查看更多
推荐专题
热门阅读