技能编写指南

本指南介绍如何编写 PostHog agent 技能 —— 即“待完成工作”模板,教导 agent 如何使用 MCP 工具实现产品目标。内容包括:

  • 工作流:通过 hogli 命令(init:skilllint:skillsbuild:skillssync:skill)搭建、编写、lint、构建和测试技能,合并后自动分发。
  • 何时编写:当产品新增功能且需要 agent 指导时创建技能;重点是经验丰富的人如何使用工具完成任务,而不仅仅是可用工具。
  • 保持技能聚焦:技能数量是预算有限的共享资源;偏好少量内容丰富的技能,将细节加入 references/,合并近似重复的兄弟技能。
  • 关键规则:使用小写 kebab-case 动名词命名(不加 posthog-* 前缀),用包含触发词的具体第三人称描述,SKILL.md 入口加 references/(保持 500 行以内),描述工作流而非僵硬脚本。
  • 模板函数.j2 文件在构建时使用 Jinja2;pydantic_schemarender_hogql_examplehogql_functions 等函数让领域知识保持以代码为准。

Writing skills for PostHog agents

Read the full guide at docs/published/handbook/engineering/ai/writing-skills.md.

Quick workflow

# 1. Scaffold
hogli init:skill

# 2. Write your skill in products/{product}/skills/{skill-name}/SKILL.md

# 3. Lint
hogli lint:skills

# 4. Build to verify
hogli build:skills

# 5. Test locally with PostHog Desktop or a coding agent
hogli sync:skill -- --name <skill-name>

# 6. Delete the test skill (optional)
hogli unsync:skill -- --name <skill-name>

Distribution is automatic after merge — CI publishes to PostHog/skills.

When to write a skill

When new functionality is added to a product and agents need to know how to work with it. A skill is not about what tools exist (that's the MCP server) — it's about how an experienced person would approach a job using those tools.

Ask: "If a customer asked an agent to do X with my feature, would the agent know the right approach?" If not, write a skill.

How many is too many?

Skill count is a budgeted, shared resource — agents pick from a list of all skill descriptions, and many harnesses truncate that list once it grows long, so every extra skill makes the others less likely to fire. Prefer a small set of focused skills, each with rich references/, over many thin ones:

  • New trigger → new skill. A skill earns its own entry point only when its "when to use it" is clearly distinct from every existing skill.
  • More detail → references/, not a new skill. Another failure mode, SDK variant, or query catalog is depth on an existing job — add it to that skill's references/ instead of spending a new slot.
  • Consolidate near-duplicate siblings. Skills sharing a diagnosis, bug class, or trigger should be one skill with references, not two.

Key rules

  • Name: lowercase kebab-case, prefer gerund form (analyzing-llm-traces, not llm-analytics). Never prefix with posthog-*.
  • Description: third person, specific, include trigger terms and when to use it. Max 1024 chars.
  • Structure: SKILL.md entry point + references/ for detailed content. Keep SKILL.md under 500 lines.
  • Frontmatter: name and description are required.
  • Tone: describe the workflow and reasoning, not a rigid script. Trust the agent to adapt.
  • Conciseness: the agent is smart — only include context it doesn't already have.

Skill structure

products/{product}/skills/{skill-name}/
    SKILL.md                         # entry point (required)
    references/                      # optional
        guidelines.md
        models-foo.md
        example-bar.md.j2            # Jinja2 template, rendered at build time
    scripts/                         # optional
        setup.sh

Only references/ and scripts/ subdirectories are collected. Others are ignored.

Template functions

Files ending in .j2 are rendered with Jinja2 at build time by products/posthog_ai/scripts/build_skills.py. Extend the build pipeline so the monorepo stays the source of truth — when domain knowledge lives in code (Pydantic models, query runners, function registries), add a template function rather than duplicating it as static markdown that drifts.

Available functions:

  • pydantic_schema("dotted.path.to.Model") — renders a Pydantic model's JSON Schema
  • render_hogql_example({"kind": "TrendsQuery", ...}) — renders a query spec to HogQL SQL
  • hogql_functions() — returns all available HogQL function names

Good example: querying-posthog-data

Bad example: llm-analytics

An umbrella skill covering traces, experiments, evaluations, cost tracking, prompt management. Too broad — agents can't determine when to activate it. Break into focused skills instead.

只读
技能数据
作者
posthog
仓库
posthog
GitHub 星标
37.5k
安装次数
99
数据来源
skills.sh
安装
$ npx skills add https://github.com/posthog/posthog --skill writing-skills

在项目目录下的终端中运行此命令。