Not loaded · from launchdarkly
Instruments existing code to send AI config metrics (duration, tokens, success/error, tool calls) to LaunchDarkly. Walks a four-tier ladder from convenience functions to manual track(), picking the lowest-ceremony option that captures what the Monitoring tab needs.
Claude Code won't load this skill
It ships in launchdarkly at skills/, but Claude Code only loads skills/<name>/SKILL.md and folders listed under skills in plugin.json. Installing the plugin doesn't add it.
You're using a skill that gets LaunchDarkly agent metrics flowing from an existing provider call. Your job is to audit what's already there, pick the right tier from the ladder below, and implement it with the least ceremony that still captures the metrics the Monitoring tab needs.
The single most important thing to get right: in the current SDKs, metrics are a side effect of routing the call through the SDK. There is no tracker to create and no wrapper to call. If the provider call runs inside config().invoke() (or a convenience function), the SDK records the metrics. If it runs outside, nothing is recorded.
Every invoke() and stream() call records these events against the served variation:
| Event | Metric |
|---|---|
$ld:ai:duration:total | Duration, in milliseconds |
$ld:ai:generation:success / $ld:ai:generation:error | Generation counts and error rate |
$ld:ai:tokens:input, :output, :total | Token usage, from the handler's normalized usage |
$ld:ai:tool_call | One event per tool call the SDK dispatches |
The current SDKs do not record time to first token or user feedback. For feedback, see Tier 4.
Walk from the top and stop at the first tier that fits:
| Tier | Pattern | Use when |
|---|---|---|
| 1 — Convenience function | openai_messages(key, input, context) / openaiMessages(key, input, context), one per handler package | One provider in one mode, no tools, no streaming. The shortest path. |
2 — config() + handler package | config(key=..., handler=[...]).invoke(input, context) / .stream(...) | A handler package covers your provider, and you need more than one provider or mode, tools, template variables, streaming, or background judges. |
| 3 — Custom handler | create_handler((provider, mode), fn) / createHandler([provider, mode], fn), passed to config() | No handler package fits (Gemini SDK, Bedrock via boto3, Strands, custom HTTP), or you want to keep an existing provider call as is. |
4 — Manual track() | get_client().track(event_key, context, result.track_data, value) | Events the SDK doesn't record: user feedback and business outcomes. Never for duration, tokens, or success, which the SDK already records. |
Before picking a tier, find the provider call and answer these questions:
messages) or an agent (agent)? The served variation's mode selects the handler.stream() instead of invoke(). Metrics are recorded the same way, but time to first token isn't.configs-create first.ldai / @launchdarkly/server-sdk-ai, or calls create_tracker(), track_metrics_of(), trackMetricsOf(), completion_config(), or create_model(), it's on the legacy surface. Replace it as part of this work (see Replacing legacy tracker code), or use legacy-sdk-migrate for a full codebase upgrade. For call sites with hardcoded models or prompts, hand off to migrate instead.Install the core package ("launchdarkly-ai-server[ld]" or @launchdarkly/ai-node) plus one handler package per provider and mode you serve:
| Provider / framework | Python handler package | Node.js handler package | Reference |
|---|---|---|---|
| OpenAI | launchdarkly-ai-openai-messages, -openai-agents | @launchdarkly/ai-openai-messages, -openai-agents | openai-tracking.md |
| Anthropic | launchdarkly-ai-claude-messages, -claude-agents | @launchdarkly/ai-claude-messages, -claude-agents | anthropic-tracking.md |
| LangChain / LangGraph (any provider) | launchdarkly-ai-langchain-messages, -langchain-agents | @launchdarkly/ai-langchain-messages, -langchain-agents | langchain-tracking.md |
| AWS Bedrock | LangChain handler + langchain-aws, or a custom handler | LangChain handler, or a custom handler | bedrock-tracking.md |
| Gemini / Google GenAI | LangChain handler with a model factory, or a custom handler | Same | gemini-tracking.md |
| Strands Agents | Custom handler | Custom handler | strands-tracking.md |
| Cohere, Mistral, custom HTTP | Custom handler | Custom handler | anthropic-tracking.md shows the shape |
| Any provider, streaming | stream() | stream() | streaming-tracking.md |
The LangChain handlers register for every provider ("*") and only apply when no exact-provider handler matches.
Open the reference file and follow the pattern. Stop at the first tier that matches the app's shape.
Guardrails that apply to every tier:
invoke() raises a RuntimeError when the served variation is disabled or the config can't be reached. If you fall back on RuntimeError, first check (await inspect_config(key, context))["enabled"] (or (await inspectConfig(key, context)).enabled in Node.js) and re-raise when it's True — the config was served, so the error came from the run.track("$ld:ai:tokens:total", ...) next to invoke() double counts.("OpenAI", "messages"), ("Anthropic", "messages"), ("Bedrock", "messages"), ("Gemini", "messages").await shutdown() before the process exits. It flushes pending events, then closes the client. Trailing events are at risk of being lost otherwise, in short-lived scripts and long-running services alike.Confirm the Monitoring tab fills in:
{"output": ..., "usage": {"input": n, "output": n}}.| Legacy | Current |
|---|---|
LDAIClient(ldclient.get()) / initAi(ldClient) | Lazy init from LD_SDK_KEY, or init_client() / initClient() |
completion_config() / agent_config() + provider call | config(key=..., handler=...).invoke(input, context) |
create_model() + model.run() | config().invoke() or a convenience function |
tracker.track_metrics_of(extractor, fn) / trackMetricsOf | Delete. Route the call through a handler package or a custom handler. |
get_ai_metrics_from_response / custom LDAIMetrics extractors | Delete. Handlers return normalized usage. |
track_duration, track_tokens, track_success, track_error | Delete. Recorded on every call. |
track_tool_call(s) | Delete. Recorded for each tool the SDK dispatches. |
track_time_to_first_token | Not recorded by the current SDKs. |
track_feedback({kind}) | get_client().track("$ld:ai:feedback:user:positive" or ":negative", context, result.track_data, 1) (Tier 4) |
track_judge_result | Attached judges record their own scores. See online-evals. |
ldclient.get().flush() + close() | await shutdown() |
The SDK doesn't record thumbs-up / thumbs-down, but the Monitoring tab still reads the feedback events. Keep the track_data from the invoke() result and send the event when the user responds:
from ldclient import Context
from launchdarkly_ai_server import get_client
result = await config(key="support-agent", handler=handler).invoke(user_input, context)
# Later, when the user clicks thumbs up or down:
event = "$ld:ai:feedback:user:positive" if thumbs_up else "$ld:ai:feedback:user:negative"
get_client().track(event, Context.from_dict(context), result.track_data, 1)
import { getClient } from '@launchdarkly/ai-node';
const result = await config({ key: 'support-agent', handler }).invoke(userInput, context);
const event = thumbsUp ? '$ld:ai:feedback:user:positive' : '$ld:ai:feedback:user:negative';
getClient().track(event, context, result.trackData, 1);
track_data identifies the config, variation, version, and model, so the feedback lands on the variation that produced the response. stream() doesn't return track_data in the current SDKs, so feedback on streamed responses can't be attributed to a variation yet. In Python, convert the context dict with Context.from_dict() before calling track().
For business outcomes such as conversions or resolutions, use the custom-metrics skill with the same track_data.
configs-create — prerequisite if the app doesn't have a config yetcustom-metrics — business metrics (conversion, resolution, retention) layered on top of the agent metrics this skill capturesonline-evals — automatic quality scoring (LLM-as-judge) on sampled live requests; complementary to the metrics heretools — tool implementations and custom handler detailsmigrate — Stage 4 of the hardcoded-to-AgentControl migration delegates to this skillreferences/anthropic-tracking.md (opens in a new tab)references/bedrock-tracking.md (opens in a new tab)references/gemini-tracking.md (opens in a new tab)references/langchain-tracking.md (opens in a new tab)references/metrics-api.md (opens in a new tab)references/openai-tracking.md (opens in a new tab)references/strands-tracking.md (opens in a new tab)references/streaming-tracking.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
launchdarkly, ai-metrics, observability, instrumentation, monitoring
56 skills in this plugin
/agent-graphsCreate and manage agent graphs — directed graphs of configs connected by edges with handoff logic. Use when building multi-agent workflows where configs route to each other./aiconfig-agent-graphsDEPRECATED redirect — this skill was renamed to agent-graphs. Do not use this skill; invoke agent-graphs instead. Kept only so old references to aiconfig-agent-graphs still point users to the new name./aiconfig-ai-metricsDEPRECATED redirect — this skill was renamed to built-in-metrics. Do not use this skill; invoke built-in-metrics instead. Kept only so old references to aiconfig-ai-metrics still point users to the new name.npx claudepluginhub launchdarkly/ai-tooling --plugin launchdarklyOther plugins' skills for the same job