---
title: "How we built cross-harness skill tracing without pushing complexity to the user"
date: 2026/12/01
description: "Understanding the influence a skill had on an agent run should be straightforward, but it proved surprisingly hard to implement across a skill's lifecycle stages and across different harnesses."
tag: engineering
author: Tobias
---

We've done our fair share of skill engineering ourselves at Langfuse, through our open-source [Langfuse skill](/docs/api-and-data-platform/features/agent-skill) (hosted on [GitHub](https://github.com/langfuse/skills)) and Halo, our in-app agent (read more in [How we built Langfuse Halo](/blog/2026-10-21-building-the-langfuse-assistant)). Whenever we changed instructions or added references, we wanted to answer the same two things:

1. which skills did an agent actually use, and
2. when it used one, did version 2 perform better than version 1?

So we started on a journey to get these questions easily answered in Langfuse. But every harness and SDK, including Halo, loaded and reported skills differently. So how do you trace skill usage in a unified way?

## What "using a skill" actually means at runtime [#lifecycle-states]

Under the [Agent Skills specification](https://agentskills.io/specification), a skill is a directory with a `SKILL.md` file (YAML frontmatter with a `name` and `description`, plus Markdown instructions) and optional files in `references/` or `scripts/`.

Agent Skill directory layout (`my-skill/`):

- `SKILL.md` (required): YAML frontmatter (`name`, `description`) exposed at startup for discovery, plus Markdown body loaded when the model invokes the skill.
- `references/` (optional): Supporting docs opened on demand.
- `scripts/` (optional): Helper scripts executed for specific steps.

To avoid overloading the model's context window with instructions it may not need, skills use **progressive disclosure**. At startup, the agent only exposes each skill's `name` and `description` in the system prompt or tool list. When the model decides a skill applies, it reads `SKILL.md`. If the task needs more detail, it opens reference files or runs scripts.

Because of this behavior, you can divide the skill lifecycle into five stages:

Skill lifecycle states and Langfuse tracking:

End-to-end coverage by Langfuse Skill Management (stages 1 to 4):

1. Installed or fetched: Skill files sit on disk or are fetched from the registry (Install via [CLI](/docs/skill-management/get-started#cli-install) / [API](https://api.reference.langfuse.com/#tag/skills)).
2. Available: Skill name and description appear in the system prompt or tool list (Recorded on `GENERATION`).
3. Requested (intent): Model calls a skill-loading tool in its output (Computed in trace UI).
4. Loaded: Tool call succeeds and returns non-null output (Recorded on `TOOL`).

Outside coverage:

5. Evicted or compacted: Session compacts context; skill may be dropped or re-attached (Not covered today).

Collapsing those stages into one flag hides why a skill failed to help:

- **Installed, never discovered:** the folder sits on disk, or the agent's context budget dropped its description before the model saw it.
- **Available, never requested:** the model saw the description and ignored it, usually because the description was too vague to match the user's phrasing (something we hit when [evaluating our own Langfuse skill](/blog/2026-02-26-evaluate-ai-agent-skills)).
- **Requested, never loaded:** the model called the skill tool, but the file never reached context.

### Separating model intent from actual loads [#intent-vs-load]

Counting a model's tool call as a skill load skews your analytics. Between the model asking for a skill and the instructions entering context, plenty can fail: the path may not exist, a sandbox rule can block the read, the loader can return an error, or (in harnesses like Gemini CLI) the user can deny the activation consent prompt.

In Langfuse, we split this into three signals:

| Signal               | Recorded on  | Capturing mechanism                                                                                                                                                    |
| -------------------- | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Available skills** | `GENERATION` | Reported on the model span as the agent's available skill catalog.                                                                                                     |
| **Requested skills** | `GENERATION` | Parsed in the trace UI from the generation's tool-call output, splitting available skills into **Requested** and **Not requested** (with requested file paths).        |
| **Loaded skills**    | `TOOL`       | Recorded at ingestion when a subsequent tool span matches a recognized skill loader, has no `ERROR` level, and returns non-null output (name, version, and file path). |

<figure className="my-6">
  
    ![A generation observation reporting three available skills and a request for langfuse v2 in the Preview view.](/images/blog/2026-11-23-building-skill-management-and-tracing/skill-management-generation.png)
  
  <figcaption className="mt-2 text-sm text-text-tertiary">
    A generation observation showing three available skills, with `langfuse` v2 split under Requested from the model's `loadSkill` tool call.
  </figcaption>
</figure>

<figure className="my-6">
  
    ![A loadSkill tool observation showing langfuse v2 and the loaded SKILL.md file in the trace's Preview view.](/images/blog/2026-11-23-building-skill-management-and-tracing/skill-management-tool-load.png)
  
  <figcaption className="mt-2 text-sm text-text-tertiary">
    The subsequent `loadSkill` tool observation recording `langfuse` v2 and `SKILL.md` as loaded once the call succeeds.
  </figcaption>
</figure>

  A non-error, non-null tool result is still a proxy, not a guarantee. Early on, we scanned plain-text tool outputs for strings like `"not found"` to catch soft failures, then removed that check because free-text matching was too brittle. If a custom tool swallows an exception and returns an error string with a normal status, it still counts as loaded.

### Compaction and eviction [#compaction]

Even with availability, intent, and loads separated, long sessions still introduce the open challenges of compaction and eviction. Once a conversation hits context limits and compacts history, whether a skill loaded earlier is still in context depends on the harness:

Session timeline across context compaction (turns 1 to 7):

- Turn 1: Session starts.
- Turn 2: Skill loaded (`TOOL` span recorded); skill stays in context across turns 2 to 5.
- Between turn 5 and turn 6: Context compaction occurs.
- Turns 6 and 7: Still in context? Depends on whether the harness drops or re-attaches the skill.

- **Claude Code** re-attaches the most recent invocation of each skill after auto-compaction, keeping up to 5,000 tokens per skill inside a 25,000-token combined budget (most recent first), so older skills can be dropped. If the model calls a skill again and its rendered content hasn't changed, Claude Code inserts a short "already loaded" note instead of repeating the body.
- **Mastra** treats skill loading as stateless: instructions sit in conversation history as a tool result, and if compaction trims them out, the agent has to call the `skill` tool again.

**Langfuse doesn't model compaction or eviction today.** Answering whether skill X was still in context on generation 14 would require harness-specific compaction hooks or scanning every generation's full message history for earlier skill payloads, and neither has a standard format yet.

## Every harness loads skills differently [#harness-fragmentation]

Tracking availability, intent, and loads is already tricky for one agent. Supporting the mix of coding agents and frameworks teams run makes it much harder.

The Agent Skills spec standardizes the folder layout on disk, not how an agent reads it at runtime. Every harness invents its own discovery budget, tool name, argument schema, and message format:

| Harness                     | Load mechanism                                     | Context delivery                        |
| --------------------------- | -------------------------------------------------- | --------------------------------------- |
| **Claude Code / Agent SDK** | `Skill` (`{skill}`), `Read`, or `/name`            | `isMeta: true` user row; short tool ack |
| **Anthropic API**           | `bash: cat .../SKILL.md` in container              | Server-side container tool result       |
| **OpenAI Codex**            | Shell `exec_command` (`cat`), or `$skill`          | Tool result, or `<skill>` prompt block  |
| **Cursor**                  | File read or shell tool                            | Tool result                             |
| **Gemini CLI**              | `activate_skill` (`{name}`) + consent prompt       | `<activated_skill>` XML tool result     |
| **OpenCode**                | `skill` (`{id}` from path) or `@skill-id`          | Tool result                             |
| **LangChain Deep Agents**   | `read_file` (`{file_path}`) via `SkillsMiddleware` | Tool result                             |
| **Mastra**                  | `skill`, `skill_read`, or `load_skill`             | Tool result                             |
| **Vercel AI SDK**           | `HarnessAgent` inline `skills`, or `uploadSkill`   | Depends on harness adapter              |

Those differences make it challenging to get to a unified skill logging design:

1. **Tool names and argument keys don't match across frameworks.**
2. **Some agents never call a skill tool.** Codex shells out to `cat`, and Anthropic's API loads skills inside a server-side container with no client tool span.
3. **The tool result isn't always the skill.** Claude Code's `Skill` tool returns a short ack while the rendered body lands in a separate `isMeta: true` message.
4. **Some loads produce no tool span at all.** Slash commands (`/skill-name`), subagent preloads, and Codex `$skill` blocks inject skills directly into messages.

## Hooks everywhere vs. ingestion-side parsing [#decision-gate]

Once you see that fragmentation, you run into the main design question for skill tracing: **who should report a skill load?**

- **Active reporting via hooks everywhere.** Every SDK, framework, and coding-agent plugin emits structured events when skills are offered and whenever a file loads. In theory, that's the cleanest signal: exact, version-aware, and able to catch non-tool loads like slash commands or prompt injections. In practice, almost nobody would wire it up. Every harness needs custom load hooks, every custom agent loop has to instrument its own file readers, existing OpenTelemetry pipelines emit nothing until rewritten, and you duplicate data that's already sitting in your tool spans.
- **Pure ingestion-side parsing.** Ask nothing from the client and infer everything on the server from prompts and tool spans. Zero client work sounds appealing, but it breaks in two places. First, the server can't reliably extract which skills were offered from arbitrary system prompts. Second, when an agent calls `Read(".agents/skills/my-skill/SKILL.md")`, the span gives you a path on disk, not whether that folder holds version 1 or version 2 in Langfuse. Guessing skill loads from generic `Read` calls without knowing which skills exist also flags ordinary source files as skill loads.

### Active catalog in, passive loads out [#hybrid-approach]

Neither extreme works on its own, so we split the job in two: **active reporting for the available catalog, passive ingestion-side parsing for loads.**

How Langfuse splits active catalog reporting from passive load parsing:

1. Active input: The application reports `skills_available` (names and versions) on model and tool spans.
2. Passive input: Existing tool spans (`Skill`, `loadSkill`, `skill_read`, `Read`, Codex `cat`) carry tool name, arguments, output, and error status.
3. Langfuse ingestion checks for non-error, non-null output, allow-lists generic file paths against the catalog, and resolves loaded names to skill versions.
4. `GENERATION` observations store the available skills; the trace UI splits them into Requested and Not requested from tool calls.
5. `TOOL` observations store the loaded skill version and file path (discarding the catalog after linking), feeding filters and per-version Usage analytics.

Harnesses don't natively emit a standardized list of available skills on their spans. To enable full skill tracing in Langfuse, your application attaches one OpenTelemetry attribute, `langfuse.observation.skills_available`, listing the skill names (and optional versions) available to the agent, either through the Langfuse SDK helpers or directly on your spans. That is the only client-side step: clients and hooks never emit a separate load event.

Instead, Langfuse's ingestion pipeline parses incoming tool observations automatically. It recognizes dedicated skill tools (such as `Skill`, `loadSkill`, and `skill_read`), generic file readers like `Read`, and literal `cat` commands inside Codex shell observations without executing any shell code.

One detail makes this split work: clients attach `skills_available` to **both** model spans and skill-loading tool spans, even though Langfuse only persists the catalog on `GENERATION` observations. On a `TOOL` span, the catalog does two things before ingestion discards it:

1. **It allow-lists generic file and shell reads.** For `Read`, `readFile`, and Codex `cat` commands, ingestion inspects the path segments, checks for a `skills/<name>/...` layout, and requires an unambiguous match against the catalog. Ordinary `Read` calls on application code never turn into phantom skill loads.
2. **It resolves a tool call to a specific skill version.** Named tools like `Skill` or `loadSkill` still record name-only loads without a catalog, which show up on traces and name filters. When the catalog is present on the tool span, ingestion matches the loaded name to its exact skill version, which powers per-version **Usage** analytics.

### Tradeoffs we accepted [#tradeoffs]

Centralizing load detection in ingestion gives us skill tracing across custom agents and all of the prominent harnesses without asking teams to rewrite their tools. It also comes with three tradeoffs:

- **Loader drift needs new parser rules.** Harnesses whose tool names or argument shapes aren't in our rule table yet, such as `activate_skill`, `read_file`, OpenCode's `{id}`, or Mastra's `load_skill`, are missed until we add them.
- **Shell scanning is heuristic.** Scanning literal `cat` arguments never executes shell code, which keeps ingestion safe, but it matches command text rather than proving the file was read.
- **Non-tool loads stay invisible to ingestion.** Slash commands (`/skill-name`), prompt-injected `$skill` blocks, and server-side Anthropic container executions never emit a client-side `TOOL` span.

Putting load detection in client SDKs or harness plugins would let each integration report exact loads locally (including custom or non-tool loaders), but every new harness shape would require SDK updates and client upgrades across teams. Keeping the parser inside Langfuse flips that equation: adding a new harness rule once fixes tracing for everyone without waiting on client upgrades.

## Carrying skill versions into traces [#distribution-and-versioning]

Knowing that a specific skill loaded only gets you halfway if you can't tell whether the agent ran **version 2** or **version 1**.

In Langfuse, each skill version is an immutable snapshot of `SKILL.md` and its supporting files, promoted or rolled back with movable labels like `staging` and `production` through the UI, API, CLI, or MCP. Because Langfuse is the registry and observability backend rather than the runtime skill loader, carrying those version numbers into traces works in one of two setups depending on how your agent loads skills: **filesystem harnesses** that read folders from disk, or **API-driven agents** that fetch skills in memory.

**1. Filesystem harnesses (Claude Code, Codex, Cursor, Claude Agent SDK).** Coding agents read plain folders on disk (`.agents/skills/<name>/`), and `SKILL.md` itself has no Langfuse version field. To resolve versions on disk, installing skills with `@langfuse/cli` (`langfuse skills install`) writes local version metadata next to those folders recording which Langfuse version landed in each directory. At runtime, the Langfuse SDK's `discoverSkills` (or `discover_skills` in Python) reads that directory and its recorded versions into a `{ name, version }` catalog. Passing that catalog to `LangfuseSpanProcessor` and wrapping the agent run in `propagateAttributes` automatically attaches those versions to every model and tool span:

```typescript
import { NodeSDK } from "@opentelemetry/sdk-node";
import { LangfuseSpanProcessor } from "@langfuse/otel";
import { discoverSkills } from "@langfuse/otel/node";
import { propagateAttributes } from "@langfuse/tracing";
import { runAgent } from "./agent";

const skills = await discoverSkills({ dir: ".agents/skills" });

const sdk = new NodeSDK({
  spanProcessors: [
    new LangfuseSpanProcessor({ skills: { available: skills } }),
  ],
});
sdk.start();

try {
  await propagateAttributes({ attachSkills: true }, () => runAgent());
} finally {
  await sdk.shutdown();
}
```

**2. API-driven agents.** Agents that load skills directly in memory, including Halo, our Mastra-based in-app assistant, don't read from disk at all. Instead, they call `langfuse.api.skills.get(...)` at run start, which returns the resolved version number alongside the skill's files. The agent pins that version for the full run so `SKILL.md` and its reference files always come from the same revision, and passes `{ name, version }` directly into `propagateAttributes`.

In both setups, `propagateAttributes` attaches skills in-process only. They aren't sent over OpenTelemetry baggage across service boundaries, and an explicit span attribute always overrides propagated or processor-level defaults.

## Usage analytics out of the box [#usage-analytics]

With the available catalog reported on generations, successful loads parsed from tool spans, and version numbers carried into both, the two questions we started with now answer themselves directly in each skill version's **Usage** tab:

1. **Which skills did an agent actually use?** Comparing available vs. loaded observation counts shows whether a skill is being offered and ignored, or actually loaded. Per-file load counts break that down further so you can see which reference docs and scripts agents open and which ones never get touched.
2. **Did version 2 perform better than version 1?** Because every loaded tool observation resolves to a specific skill version, you can switch between versions in the sidebar, filter linked generations and tool spans by version, compare outcomes across production traffic in custom dashboards, or trigger evaluations through skill-version webhooks whenever a new version ships.

<figure className="my-6">
  
    ![The Usage tab for langfuse v2 showing version history, available versus loaded observation counts, per-file load breakdown, and linked observations.](/images/blog/2026-11-23-building-skill-management-and-tracing/skill-management-usage.png)
  
  <figcaption className="mt-2 text-sm text-text-tertiary">
    The Usage tab for `langfuse` v2 alongside its version history, showing available vs. loaded observation counts, per-file load breakdown across `SKILL.md`, references, and scripts, and linked observations.
  </figcaption>
</figure>

## Try it out [#try-it-out]

Follow the [get-started guide](/docs/skill-management/get-started) to create your first versioned skill, or read the [Skill Management overview](/docs/skill-management/overview) and [skill tracing docs](/docs/skill-management/tracing) to connect it to your agent traces.

If your harness loads skills in a format we don't recognize yet, [open a GitHub issue](https://github.com/langfuse/langfuse/issues) with the tool name and a sample input and output. If you like working on this kind of problem, [we are hiring](/careers).

<!-- agent-instructions -->

---

## Agent Instructions

This page is part of the [Langfuse](https://langfuse.com) documentation, published as plain Markdown for AI agents. Every page is available as Markdown by appending `.md` to its URL, or by sending an `Accept: text/markdown` header. This page: `https://langfuse.com/blog/2026-12-01-building-skill-management-and-tracing.md`.

### Querying these docs

If the answer is not on this page, query the documentation instead of guessing:

- **Semantic search** across all Langfuse docs, returning an answer with the relevant pages and excerpts. Ask a specific, self-contained question:

  ```bash
  curl -sG "https://langfuse.com/api/search-docs" --data-urlencode "query=How do I trace a LangGraph agent?"
  ```

- **Index of every page**: <https://langfuse.com/llms.txt>, with per-section indexes [llms-docs.txt](https://langfuse.com/llms-docs.txt), [llms-integrations.txt](https://langfuse.com/llms-integrations.txt), and [llms-self-hosting.txt](https://langfuse.com/llms-self-hosting.txt).

### Before writing Langfuse code

- **Install the [Langfuse Agent Skill](https://langfuse.com/docs/api-and-data-platform/features/agent-skill).** It encodes Langfuse's own best practices for instrumentation, prompt management, and evaluation, and materially improves results.
- **Read [What does a good trace look like?](https://langfuse.com/docs/observability/best-practices.md)** before instrumenting an application.
- **Verify endpoints, parameters, and response fields** against the [OpenAPI spec](https://cloud.langfuse.com/generated/api/openapi.yml), or read the [API reference as Markdown](https://api.reference.langfuse.com/index.md), instead of inferring them from code examples.
- **Use the [Langfuse CLI](https://langfuse.com/docs/api-and-data-platform/features/cli)** (`npx @langfuse/cli api <resource> <action>`) to read or write traces, prompts, datasets, and scores from the terminal.

Found an error in these docs? Please open an issue at <https://github.com/langfuse/langfuse-docs/issues>.
