关于 omnibus-instrument-llm-analytics
用于为 LLM 调用添加 PostHog 分析的编码技能。它识别项目使用的提供商或框架,并指导针对性埋点,记录令牌、模型、延迟和成本。
主要功能
- 01识别 LLM 提供商与框架
- 02指导设置 PostHog SDK
- 03记录令牌、模型、延迟和成本
- 04将生成记录关联到已识别用户
- 05提供针对技术栈的参考资料
适用场景
- 01为新加入的 LLM 功能添加埋点
- 02检查代码中未跟踪的生成调用
- 03为现有 LLM 项目设置 PostHog
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ posthog/ skills --skill omnibus-instrument-llm-analytics安装后在 Claude Code 中输入/omnibus-instrument-llm-analytics确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
references/anthropic.mdautogen.mdazure-openai.mdbasics.mdcalculating-costs.mdcerebras.mdcohere.mdcrewai.mddeepseek.mddspy.mdfireworks-ai.mdgoogle.mdgroq.mdhelicone.mdhugging-face.mdinstructor.mdlangchain.mdlanggraph.mdlitellm.mdllamaindex.mdmanual-capture.mdmastra.mdmirascope.mdmistral.mdollama.mdopenai-agents.mdopenai.mdopenrouter.mdperplexity.mdportkey.md详细介绍
添加 PostHog LLM 分析
使用此技能添加 PostHog LLM 分析,以跟踪新代码或更改后代码中的 AI 模型使用情况。在实现 LLM 功能或审查 PR 后使用此技能,确保记录所有生成操作的 Token 数量、延迟和成本。如果尚未安装 PostHog,此技能也涵盖初始 SDK 设置。支持任何提供商或框架。
支持的提供商:OpenAI、Azure OpenAI、Anthropic、Google、Cohere、Mistral、Perplexity、DeepSeek、Groq、Together AI、Fireworks AI、xAI、Cerebras、Hugging Face、Ollama、OpenRouter。
支持的框架:LangChain、LlamaIndex、CrewAI、AutoGen、DSPy、LangGraph、Pydantic AI、Vercel AI、LiteLLM、Instructor、Semantic Kernel、Mirascope、Mastra、SmolAgents、OpenAI Agents。
代理/网关:Portkey、Helicone。
说明
请按顺序执行以下步骤:
STEP 1:分析代码库并检测 LLM 技术栈。
- 在依赖文件和导入语句中查找 LLM 提供商 SDK(openai、anthropic、google-generativeai 等)和 AI 框架(langchain、llamaindex、crewai 等)。
- 查找锁文件以确定包管理器。
- 检查是否已配置 PostHog 或可观测性。如果已安装 PostHog 且已配置 LLM 跟踪,请跳至 STEP 4,为新增的 LLM 调用添加跟踪。
STEP 2:研究埋点方式。(如果已配置 PostHog LLM 跟踪,则跳过。) 2.1. 在下方查找与检测到的提供商或框架相匹配的参考文件——它是回调设置、中间件配置和事件采集的权威依据。现在阅读该文件。 2.2. 如果没有匹配的参考文件,请使用 manual-capture.md 作为后备方案——其中介绍了适用于任何提供商的通用事件采集方法。
STEP 3:安装 PostHog SDK。(如果已配置 PostHog,则跳过。)
- 添加 PostHog SDK 以及所需的回调/集成包。
- 不要手动编辑依赖文件——使用包管理器的安装命令。
- 始终将安装包作为后台任务运行。不要等待安装完成;立即继续其他工作。
STEP 4:添加 LLM 跟踪。
- 为 LLM 调用添加埋点,以记录每次生成的输入 Token 数、输出 Token 数、模型名称、延迟和成本。
- 按照提供商专属参考中的说明,准确配置回调/中间件。
- 不要改变现有文件的基本架构。只进行尽可能少且有针对性的更改。
- 尝试写入文件前,必须立即阅读该文件。
STEP 5:关联用户。
- 尽可能通过 distinct ID 将 LLM 生成操作与已识别的用户关联起来。
STEP 6:设置环境变量。
- 如果已连接 env-file-tools MCP 服务,请使用 check_env_keys,然后使用 set_env_values 配置 PostHog API key 和 host。
- 在代码中引用这些环境变量,而不是硬编码。
参考文件
references/openai.md- Openai 大模型分析安装文档references/azure-openai.md- Azure openai 大模型分析安装文档references/anthropic.md- Anthropic 大模型分析安装文档references/google.md- Google 大模型分析安装文档references/cohere.md- Cohere 大模型分析安装文档references/mistral.md- Mistral 大模型分析安装文档references/perplexity.md- Perplexity 大模型分析安装文档references/deepseek.md- Deepseek 大模型分析安装文档references/groq.md- Groq 大模型分析安装文档references/together-ai.md- Together ai 大模型分析安装文档references/fireworks-ai.md- Fireworks ai 大模型分析安装文档references/xai.md- Xai 大模型分析安装文档references/cerebras.md- Cerebras 大模型分析安装文档references/hugging-face.md- Hugging face 大模型分析安装文档references/ollama.md- Ollama 大模型分析安装文档references/openrouter.md- Openrouter 大模型分析安装文档references/langchain.md- Langchain 大模型分析安装文档references/llamaindex.md- Llamaindex 大模型分析安装文档references/crewai.md- Crewai 大模型分析安装文档references/autogen.md- Autogen 大模型分析安装文档references/dspy.md- Dspy 大模型分析安装文档references/langgraph.md- Langgraph 大模型分析安装文档references/pydantic-ai.md- Pydantic ai 大模型分析安装文档references/vercel-ai.md- Vercel ai SDK 大模型分析安装文档references/litellm.md- Litellm 大模型分析安装文档references/instructor.md- Instructor 大模型分析安装文档references/semantic-kernel.md- Semantic kernel 大模型分析安装文档references/mirascope.md- Mirascope 大模型分析安装文档references/mastra.md- Mastra 大模型分析安装文档references/smolagents.md- Smolagents 大模型分析安装文档references/openai-agents.md- Openai agents SDK 大模型分析安装文档references/portkey.md- Portkey 大模型分析安装文档references/helicone.md- Helicone 大模型分析安装文档references/manual-capture.md- 手动捕获大模型分析安装文档references/basics.md- 大模型分析基础知识references/traces.md- 追踪references/calculating-costs.md- 计算大模型成本
每个提供商参考文件都包含针对该提供商或框架的安装说明、SDK 设置和代码示例。请找到与用户技术栈相匹配的参考文件。
如果未列出用户使用的提供商,请使用 manual-capture.md 作为备用方案——其中介绍了适用于任何提供商的通用事件捕获方法。
核心原则
- 环境变量:始终使用环境变量存储 PostHog 和大模型提供商密钥。切勿将密钥硬编码。
- 最小改动:在现有大模型调用旁添加大模型分析。不要替换或重构现有代码。
- 追踪所有生成:记录每次大模型调用的输入令牌、输出令牌、模型名称、延迟和成本。
- 关联用户:尽可能通过 distinct ID 将大模型生成与已识别的用户关联起来。
- 一次使用一个提供商:仅为用户实际使用的提供商添加监控。不要为代码库中不存在的提供商添加监控。