tencent-cls-agent-obs-analyze

Tencent CLS Agent Observability Analysis: Performs intelligent analysis on observability data collected by Tencent Cloud CLS Agent using CLS SearchLog API and outputs structured reports. Supports multidimensional analysis including user profiling, error diagnosis, performance bottleneck localization, token cost optimization, session quality assessment, and trend comparisons. Use when analyzing Agent observability, LLM calls, session or call-chain analysis, generating observability daily reports or inspections, or when investigating with traceID/sessionId/userId.

Installation

Review the source and dependencies with a prompt. A package is available to download.

Install with an AI assistant

Copy the prompt so your assistant can review the pinned revision and dependencies first.

View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "tencent-cls-agent-obs-analyze" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-f9a77d4a9f6f711dd3981d7b75532843893e1206effb3a5a8d2504ee965e241e. Verify the upstream source and version against https://skillhub.cn/skills/user_5b951003/tencent-cls-agent-obs-analyze before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.

Source and setup

skillhub.cn

Setup guidance pending

See the original source for supported tools, dependencies, and permissions.

Installation test pending

Tencent CLS Agent Observability Analysis: Performs intelligent analysis on observability data collected by Tencent Cloud CLS Agent using CLS SearchLog API and outputs structured reports. Supports multidimensional analysis including user profiling, error diagnosis, performance bottleneck localization, token cost optimization, session quality assessment, and trend comparisons. Use when analyzing Agent observability, LLM calls, session or call-chain analysis, generating observability daily reports or inspections, or when investigating with traceID/sessionId/userId.

0 Downloads

Introduction source: third_party · user_5b951003 · 1.0.1 Reference

SkillPi interpretation

Tasks
Translation pending; see source documentation.
Software, accounts and paid services
Translation pending; see source documentation.
Limits and differences
Translation pending; see source documentation.
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: cls-agent-obs-analyze
description: |
  基于腾讯云 CLS Agent 可观测数据进行智能分析。支持用户画像、错误诊断、性能瓶颈定位、Token 成本优化、会话质量评估、趋势对比等多维度分析,通过 CLS SearchLog API 查询数据并输出结构化报告。

  Use when:
  - 用户说"分析 Agent 可观测"、"Agent 错误分析"、"分析 LLM 调用"
  - 用户说"用户画像分析"、"Token 成本分析"、"Agent 性能分析"
  - 用户说"会话分析"、"调用链分析"、"帮我看看 Agent 运行情况"
  - 用户说"生成可观测日报"、"Agent 巡检"、"模型调用统计"
  - 用户给出 traceID/sessionId/userId 想做深度排查
  - 用户想知道 AI 应用的错误率、延迟、成本趋势

CLS Agent 可观测分析

前置条件

  • 用户已完成 CLS Agent 可观测接入(有数据上报)
  • Python 3.8+ 已安装
  • 已安装依赖:pip install tencentcloud-sdk-python python-dotenv
  • 环境变量已配置:TENCENTCLOUD_SECRET_ID、TENCENTCLOUD_SECRET_KEY、CLS_DEFAULT_REGION
  • 可选环境变量:CLS_TOPIC_ID(作为默认 TopicID)
  • 如果不方便执行脚本,可将查询语句复制到 CLS 控制台 > 检索分析 手动执行

查询工具

本 Skill 使用 references/cls_search.py 脚本直接调用 CLS SearchLog API 进行数据查询,无需安装额外 CLI 工具。

安装依赖

pip install tencentcloud-sdk-python python-dotenv

使用方式

python cls_search.py --topic <TopicID> --query '<CQL>' --from "1h ago" --to "now"

参数说明: | 参数 | 说明 | 默认值 | |------|------|--------| | --topic | 日志主题 TopicID | 读环境变量 CLS_TOPIC_ID | | --query | CQL 查询语句(支持检索 + SQL 分析) | 必填 | | --from | 起始时间 | 1h ago | | --to | 结束时间 | now | | --limit | 最大返回条数 | 1000 | | --format | 输出格式:json / pretty | pretty |

时间参数支持:1h ago、30m ago、7d ago、15 minutes ago、now、2026-07-07 00:00:00

如用户未指定 TopicID,按以下顺序自动获取:

  1. --topic 参数
  2. 环境变量 CLS_TOPIC_ID
  3. 用户 .env 文件中的 CLS_TOPIC_ID

数据字段

字段 说明
traceID 请求追踪 ID
spanID 当前 Span ID
parentSpanID 父 Span ID(根 Span 为空)
name 操作名称
duration 耗时(纳秒)
statusCode OK / ERROR
statusMessage 错误消息
attribute 完整属性 JSON
userId 用户标识
sessionId 会话标识
model 模型名称

分析能力

1. 用户画像

识别谁在用、怎么用、用多少。

-- 活跃用户 Top20
* | SELECT userId, COUNT(DISTINCT traceID) AS requests, COUNT(DISTINCT sessionId) AS sessions,
  SUM(CASE WHEN statusCode='ERROR' THEN 1 ELSE 0 END) AS errors,
  MIN(__TIMESTAMP__) AS first_seen, MAX(__TIMESTAMP__) AS last_seen
WHERE userId != '' GROUP BY userId ORDER BY requests DESC LIMIT 20

-- 用户活跃时段
* | SELECT userId, HOUR(__TIMESTAMP__) AS hour, COUNT(DISTINCT traceID) AS cnt
WHERE userId != '' GROUP BY userId, HOUR(__TIMESTAMP__) ORDER BY userId, hour

-- 单用户行为详情
userId:"u-123" | SELECT traceID, sessionId, name, model, duration/1000000 AS ms, statusCode, __TIMESTAMP__
ORDER BY __TIMESTAMP__ DESC LIMIT 50

执行示例:

python cls_search.py --topic <TopicID> --query '* | SELECT userId, COUNT(DISTINCT traceID) AS requests, COUNT(DISTINCT sessionId) AS sessions, SUM(CASE WHEN statusCode='\''ERROR'\'' THEN 1 ELSE 0 END) AS errors, MIN(__TIMESTAMP__) AS first_seen, MAX(__TIMESTAMP__) AS last_seen WHERE userId != '\'''\'' GROUP BY userId ORDER BY requests DESC LIMIT 20' --from "24h ago" --to "now"

输出要点:高频用户 / 使用模式 / 错误率 / 活跃时段

2. 错误诊断

快速定位问题根因。

-- 错误类型分布
statusCode:"ERROR" | SELECT name, statusMessage, COUNT(*) AS cnt, COUNT(DISTINCT userId) AS users
GROUP BY name, statusMessage ORDER BY cnt DESC LIMIT 20

-- 错误趋势
statusCode:"ERROR" | SELECT DATE_FORMAT(__TIMESTAMP__,'%Y-%m-%d %H:00') AS hour, COUNT(*) AS errors
GROUP BY hour ORDER BY hour

-- 特定 trace 调用链
traceID:"xxx" | SELECT spanID, parentSpanID, name, model, duration/1000000 AS ms, statusCode, statusMessage
ORDER BY start ASC

-- 按模型统计错误
statusCode:"ERROR" AND model:* | SELECT model, COUNT(*) AS errors GROUP BY model ORDER BY errors DESC

执行示例:

python cls_search.py --topic <TopicID> --query 'statusCode:"ERROR" | SELECT name, statusMessage, COUNT(*) AS cnt, COUNT(DISTINCT userId) AS users GROUP BY name, statusMessage ORDER BY cnt DESC LIMIT 20' --from "24h ago" --to "now"

分析 SOP:

  1. 查错误概览 → 确定最高频错误类型
  2. 查趋势 → 持续性 or 突发
  3. 抽样 error trace → 查完整调用链
  4. 定位首个报错 span → 根因分析
  5. 输出:错误分类 + 影响范围 + 根因 + 修复建议

3. 性能瓶颈

定位慢请求和延迟来源。

-- 耗时分位
* AND parentSpanID:"" | SELECT
  APPROX_PERCENTILE(duration/1000000,0.5) AS p50,
  APPROX_PERCENTILE(duration/1000000,0.9) AS p90,
  APPROX_PERCENTILE(duration/1000000,0.99) AS p99,
  COUNT(*) AS total

-- 慢请求 Top20
* AND parentSpanID:"" | SELECT traceID, name, model, userId, duration/1000000 AS ms
ORDER BY duration DESC LIMIT 20

-- 各模型耗时
model:* | SELECT model, COUNT(*) AS calls, AVG(duration/1000000) AS avg_ms,
  APPROX_PERCENTILE(duration/1000000,0.9) AS p90 GROUP BY model ORDER BY avg_ms DESC

-- 各操作耗时
* | SELECT name, COUNT(*) AS cnt, AVG(duration/1000000) AS avg_ms,
  APPROX_PERCENTILE(duration/1000000,0.9) AS p90 GROUP BY name ORDER BY avg_ms DESC LIMIT 20

执行示例:

python cls_search.py --topic <TopicID> --query '* AND parentSpanID:"" | SELECT APPROX_PERCENTILE(duration/1000000,0.5) AS p50, APPROX_PERCENTILE(duration/1000000,0.9) AS p90, APPROX_PERCENTILE(duration/1000000,0.99) AS p99, COUNT(*) AS total' --from "1h ago" --to "now"

输出要点:P50/P90/P99 / 慢请求采样 / 慢模型识别 / 优化建议

4. Token 成本

分析成本构成和优化空间。

-- 按日 + 模型统计 Token
* AND model:* | SELECT DATE_FORMAT(__TIMESTAMP__,'%Y-%m-%d') AS date, model, COUNT(*) AS calls,
  SUM(CAST(JSON_EXTRACT(attribute,'$.gen_ai.usage.input_tokens') AS BIGINT)) AS input_tokens,
  SUM(CAST(JSON_EXTRACT(attribute,'$.gen_ai.usage.output_tokens') AS BIGINT)) AS output_tokens
GROUP BY date, model ORDER BY date DESC, output_tokens DESC

-- 高消耗请求
* AND model:* | SELECT traceID, userId, model,
  CAST(JSON_EXTRACT(attribute,'$.gen_ai.usage.input_tokens') AS BIGINT) AS input,
  CAST(JSON_EXTRACT(attribute,'$.gen_ai.usage.output_tokens') AS BIGINT) AS output
ORDER BY input+output DESC LIMIT 20

-- 按 Agent 维度
* AND model:* | SELECT name, model, COUNT(*) AS calls,
  SUM(CAST(JSON_EXTRACT(attribute,'$.gen_ai.usage.input_tokens') AS BIGINT)) AS input,
  SUM(CAST(JSON_EXTRACT(attribute,'$.gen_ai.usage.output_tokens') AS BIGINT)) AS output
GROUP BY name, model ORDER BY input+output DESC LIMIT 20

执行示例:

python cls_search.py --topic <TopicID> --query '* AND model:* | SELECT DATE_FORMAT(__TIMESTAMP__,'\''%Y-%m-%d'\'') AS date, model, COUNT(*) AS calls, SUM(CAST(JSON_EXTRACT(attribute,'\''$.gen_ai.usage.input_tokens'\'') AS BIGINT)) AS input_tokens, SUM(CAST(JSON_EXTRACT(attribute,'\''$.gen_ai.usage.output_tokens'\'') AS BIGINT)) AS output_tokens GROUP BY date, model ORDER BY date DESC, output_tokens DESC' --from "7d ago" --to "now"

输出要点:日成本趋势 / 高消耗来源 / 输入输出比 / 优化建议(换模型、压缩 prompt、缓存)

5. 会话质量

评估用户对话体验。

-- 会话概览
* AND sessionId:* | SELECT sessionId, userId, COUNT(DISTINCT traceID) AS traces,
  SUM(CASE WHEN statusCode='ERROR' THEN 1 ELSE 0 END) AS errors
GROUP BY sessionId, userId ORDER BY traces DESC LIMIT 50

-- 异常会话
* AND sessionId:* | SELECT sessionId, userId, COUNT(DISTINCT traceID) AS traces,
  SUM(CASE WHEN statusCode='ERROR' THEN 1 ELSE 0 END) AS errors,
  ROUND(SUM(CASE WHEN statusCode='ERROR' THEN 1 ELSE 0 END)*100.0/COUNT(DISTINCT traceID),2) AS error_rate
GROUP BY sessionId, userId HAVING errors>0 ORDER BY error_rate DESC LIMIT 20

-- 单会话详情
sessionId:"xxx" | SELECT traceID, name, model, duration/1000000 AS ms, statusCode, __TIMESTAMP__
ORDER BY __TIMESTAMP__ ASC

执行示例:

python cls_search.py --topic <TopicID> --query '* AND sessionId:* | SELECT sessionId, userId, COUNT(DISTINCT traceID) AS traces, SUM(CASE WHEN statusCode='\''ERROR'\'' THEN 1 ELSE 0 END) AS errors GROUP BY sessionId, userId ORDER BY traces DESC LIMIT 50' --from "24h ago" --to "now"

输出要点:平均轮次 / 会话时长 / 错误率 / 中断模式

6. 趋势对比

日常巡检和异常检测。

-- 最近 7 天日维度对比
* AND parentSpanID:"" | SELECT DATE_FORMAT(__TIMESTAMP__,'%Y-%m-%d') AS date,
  COUNT(*) AS requests,
  SUM(CASE WHEN statusCode='ERROR' THEN 1 ELSE 0 END) AS errors,
  ROUND(SUM(CASE WHEN statusCode='ERROR' THEN 1 ELSE 0 END)*100.0/COUNT(*),2) AS error_rate,
  AVG(duration/1000000) AS avg_ms, COUNT(DISTINCT userId) AS users
GROUP BY date ORDER BY date DESC LIMIT 7

执行示例:

python cls_search.py --topic <TopicID> --query '* AND parentSpanID:"" | SELECT DATE_FORMAT(__TIMESTAMP__,'\''%Y-%m-%d'\'') AS date, COUNT(*) AS requests, SUM(CASE WHEN statusCode='\''ERROR'\'' THEN 1 ELSE 0 END) AS errors, ROUND(SUM(CASE WHEN statusCode='\''ERROR'\'' THEN 1 ELSE 0 END)*100.0/COUNT(*),2) AS error_rate, AVG(duration/1000000) AS avg_ms, COUNT(DISTINCT userId) AS users GROUP BY date ORDER BY date DESC LIMIT 7' --from "7d ago" --to "now"

报告模板

日报格式

# Agent 可观测日报 - {日期}

## 核心指标
| 指标 | 今日 | 昨日 | 环比 |
|------|------|------|------|
| 请求数 | - | - | -% |
| 错误率 | -% | -% | -pp |
| P99 耗时 | -ms | -ms | -% |
| 活跃用户 | - | - | -% |

## 异常摘要
- 🔴 {严重问题}
- 🟡 {注意事项}
- 🟢 {正常/改善}

## Top 错误
| 操作 | 错误 | 次数 | 影响用户 |
|------|------|------|---------|

## 建议
1. ...

注意事项

  • duration 是纳秒,展示时 /1000000 转毫秒
  • attribute 是 JSON 字符串,用 JSON_EXTRACT 取内部字段
  • 大时间范围查询可能慢,先用小窗口验证
  • 报告中避免暴露用户输入输出原文(隐私)
  • TopicID 自动获取顺序:--topic 参数 > 环境变量 CLS_TOPIC_ID > .env 文件
  • SQL 分析查询(含 | SELECT)一次返回全部结果;纯检索查询超过 limit 时会自动翻页

Current listing version

1.0.1

Verify the source revision ↗

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value95/100

Highlights

  • 高价值/高频刚需。直接解决用户明确的核心任务痛点,显著提升日常高频场景的效率,如自动化任务、信息聚合、内容生成等。
Trigger Precision90/100

Highlights

  • 触发词精准完整,覆盖多种变体,边界清晰。
Structure and Standards90/100

Highlights

  • Phase/步骤清晰,有出口条件,含端到端示例,frontmatter完整,单文件≤500行。
Execution Reliability90/100

Highlights

  • 工具来源明确,参数正确,覆盖主要异常,不可逆操作有确认机制。
Evidence Verifiability (mean of the first four)91/100

The arithmetic mean of the first four original scores, rounded to a whole number.

Static text checks

100 / 100 · skillpi-20261123-no-r3-v1

No current rules matched the text.

This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.

Permissions and checks before use

Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.

  • Install or fetch external dependencies

    Use official sources and pin versions. Check install scripts in an isolated environment. This document check does not cover code downloaded later.

    Mentioned in main document · lines 21, 33
Domains or addresses referenced in the document

These addresses may be documentation links or examples, not an approved network allowlist. Verify actual destinations and outgoing data before use.

  • console.cloud.tencent.com

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

Security rating and access scope

safe · Static evidence review; not a runtime safety guarantee.

Translation pending; see source documentation.

Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.