Agnost AI integration
Work from the target app root. This is the skill route: do not tell the user to
install an npm package, use a global binary, or run a package runner. Agents may
call bundled scripts/ helpers from this installed skill directory, but the
skill contract is the integration workflow.
Ask first
Before editing, ask only for missing facts:
- Agnost org id from the dashboard.
- Target app/package path if the repo is a monorepo.
- Whether verification should happen in a local app or deployed production app.
- Whether installing Agnost packages is allowed.
- The real AI entrypoint: chat route, agent call, MCP server startup, or tool call.
- How the app is restarted or deployed after env/code changes.
If the org id is absent, stop and ask for it. Do not invent one.
Choose the route
Inspect existing telemetry before choosing an integration:
- Find any OpenTelemetry provider, exporter, framework instrumentation, env
configuration, and representative spans from the real AI entrypoint.
- Check whether the emitted span family is supported by Agnost. Supported
signals include OTel
gen_ai.*, Vercel AI ai.*, OpenInference llm.*,
LiveKit lk.*, Mastra, LangSmith, MCP, and custom tool.* spans.
- When an existing OpenTelemetry path emits supported spans, preserve it and
route those spans to Agnost. Do not install a Conversation SDK merely because
the app is a general TypeScript or Python application.
- Retell does not expose a documented OTLP export. For Retell agents, configure
the
call_analyzed webhook route in references/frameworks.md; do not use
Live Monitoring, Analytics, or transcript_updated as a trace substitute.
- Treat automatic OTel detection as a candidate, not proof. Inspect or trigger
one real interaction and validate the resulting trace with the checklist
below before declaring that route usable.
- If OTel exists but the real AI path emits no supported spans, add the
framework's official instrumentation or the smallest missing attributes at
the real entrypoint. If that cannot produce a faithful conversation model,
use the matching Agnost SDK/MCP path instead.
- Respect an explicit
--strategy sdk or --strategy otel choice.
Use SDK/MCP integration when there is no usable existing OTel path:
- TypeScript conversation app: install
agnostai, initialize once, wrap the real
model/agent call with begin() and end().
- Python conversation app: install
agnost, initialize once, wrap the real
model/agent call with begin()/end() or track_ai().
- TypeScript MCP server: install
agnost, call configureFromEnv() and
trackMCP(server, orgId, config) after server construction and before
transport connection. For HTTP/OAuth MCP servers, preserve the official
transport request path (transport.handleRequest(req, res, req.body)) so
extra.requestInfo.headers reaches Agnost. If the target uses a custom
transport or manual handleMessage(...), pass
{ requestInfo: { headers: req.headers }, authInfo: req.auth }. If OAuth
middleware validates the bearer token, attach stable non-secret identity on
req.auth.extra such as { userId, tokenId }; Agnost uses tokenId as the
durable OAuth conversation/session key. If headers are unavailable, Agnost
can also read identity from authInfo.sub, authInfo.claims,
authInfo.tokenPayload, authInfo.extra, authInfo.token,
authInfo.accessToken, or authInfo.access_token; never use OAuth
clientId as the user id. Never log raw bearer tokens.
- Python MCP/FastMCP server: install
agnost-mcp, call track(server, org_id, config(...)) after tool registration and before run(). The SDK supports
stdio, SSE, and stateful/stateless Streamable HTTP. Multiple tracked server
instances in one process must use the same org ID and config. Without a
custom sync/async identify, built-in identity uses bearer or validated MCP
auth context without forwarding raw credentials, and identity is cached per
session key.
If no usable supported OTel route exists and a Node/TypeScript project contains
MCP code but is not solely an MCP server
(for example it also has app, agent, model, OpenAI, Vercel AI SDK, LangChain,
Mastra, Next/React, or API-server code), use its supported existing OTel path or
the TypeScript conversation SDK route (agnostai) and instrument the real AI
turn. Use the MCP wrapper route only when the package's main surface is a
dedicated MCP server.
Keep input and output capture enabled by default. For options named
disableInput/disableOutput (or Python disable_input/disable_output),
false means capture is on. Set them to true only when the user explicitly
asks to redact inputs/outputs or the target app's privacy requirements demand it.
Supported OTel recipe targets include LiveKit Agents, Vercel AI SDK, Mastra,
Spectrum TS, LangChain, OpenAI, and other already-instrumented OTel apps.
Do not make a synthetic fetcher or custom OTLP payload path when an official SDK,
MCP wrapper, or framework OTel option exists.
Validate an OTel route
For a representative real interaction, inspect the emitted trace and the
resulting Agnost user, conversation, turns, events, and tool details. Arrange
attributes at the framework instrumentation or real AI entrypoint when a gap is
found. The route is valid only when all of these checks pass:
- User mapping: use one stable
agnost.user_id, enduser.id, or user.id
for the same customer across all conversations. Verify that two separate
conversations for that customer map to the same Agnost user and that another
customer cannot inherit that identity.
- Conversation mapping: use one stable
agnost.session_id,
gen_ai.conversation.id, or session.id for all the events and turns in one
conversation, including spans exported in separate batches. A new
conversation must receive a different ID, and its user/assistant turns must
remain ordered and complete.
- Turn and tool hierarchy: each user-assistant turn must retain its input
and output. Internal
tool.*, framework-native tool, or MCP tool spans must
be child spans of the turn that invoked them, using the real OTel parent span
ID rather than a custom parent attribute.
- AI and SDK attributes: keep the framework's native attributes and confirm
model, provider, operation, success/error, and available token counts are on
the right span. Prefer current GenAI fields such as
gen_ai.usage.input_tokens and gen_ai.usage.output_tokens; retain useful
SDK-specific ai.*, llm.*, lk.*, Mastra, LangSmith, or MCP attributes.
- Custom metadata: use
user.* or enduser.* for custom user metadata,
conversation.* or session.* for custom conversation metadata, and
non-reserved span attributes for custom event metadata. Put stable values on
the resource or propagate them to every relevant span; put turn/tool-specific
values only on the event span they describe.
Fix the narrowest proven gap, restart or redeploy, repeat the same interaction,
and re-check the trace. Do not replace a working framework trace tree with
synthetic spans solely to rename attributes.
Read the right reference
Open only the matching section from references/frameworks.md:
#conversation-ts-agnostai
#conversation-py-agnost
#mcp-ts-agnost
#mcp-py-agnost-mcp
#vercel-ai-otlp
#openai-openinference-otlp
#mastra-otlp
#spectrum-ts-app-level-otel-spans
#langchain-langsmith-otel-mode
#custom-otel-spans
Voice-agent routes:
#livekit-agents-native-otlp
#retell-call-analyzed-webhook
For vercel-ai, read references/frameworks.md#vercel-ai-otlp before editing.
Use the official Agnost recipe only: OTel exporter setup plus
experimental_telemetry on modern generateText/streamText/generateObject
calls. If the app uses legacy OpenAIStream(...) without a modern call shape,
configure env/deps only if the user chose OTel, then report that app telemetry
requires migrating to a supported Vercel AI SDK call shape or using SDK
instrumentation. Do not generate custom OTLP fetches, synthetic spans, or
wrapper functions.
Voice agents
For livekit-ts or livekit-py, read
references/frameworks.md#livekit-agents-native-otlp before editing. Preserve
LiveKit's native spans: configure a standard OTel batch exporter and call the
framework tracer-provider hook before AgentSession.start(). Use session.id,
user.id, user.*, and conversation.* metadata. Do not add a
custom span wrapper, synthesize OTLP payloads, or use LiveKit room webhooks as a
substitute for agent traces.
For Retell, read references/frameworks.md#retell-call-analyzed-webhook.
Configure the direct Agnost webhook URL with the real organization UUID and
enable call_analyzed. Do not add an OTel exporter or ingest incremental
transcript_updated events.
Backfill existing data
If the user has historical conversations or agent activity, offer to backfill
it before or alongside live instrumentation. Preserve original timestamps and
stable conversation/event relationships, mapping source identifiers to the
required UUIDs. Create each conversation with the
Capture Session API, then send its
turn-pairs and tool calls with the
Capture Event API. Follow the API
reference for event hierarchy, input/output shape, and historical timestamps.
Script helpers
Scripts are helpers for agents and CLI tools, not the product surface.
Use them only after choosing the route above:
node "$SKILL_DIR/scripts/detect.mjs" --dir . --strategy <auto|sdk|otel> --json
node "$SKILL_DIR/scripts/instrument.mjs" --dir . --framework <framework> --org-id <org-id> --mode <local|prod> --env-mode <file|shell|manual> --json
node "$SKILL_DIR/scripts/send-demo.mjs" --org-id <org-id> --transport <ingest|otel> --mode <local|prod> --json
detect.mjs can suggest a route. In auto mode it keeps a supported framework's
existing OTel setup, but that suggestion still requires real trace validation.
instrument.mjs can apply the narrowest known edit. send-demo.mjs can check
whether Agnost accepts traffic, but it does not prove the customer app is
integrated.
Definition of done
Integration is done only when the user's own application runs locally with the
production Agnost endpoint and emits telemetry from its real code path.
- Set local app env to the real org id and prod endpoints:
AGNOST_ORG_ID=<org-id>, AGNOST_ENDPOINT=https://api.agnost.ai, and when
using OTel, AGNOST_OTEL_URL=https://otel.agnost.ai.
- Tell the agent harness/user to run the local application with its normal start
command after env and code changes are applied.
- Trigger one real chat, agent action, or MCP tool call through that running
local app.
- Confirm the user, conversation, turns/events, tool hierarchy, attributes, and
metadata in the Agnost dashboard before saying the integration is complete.
Do not call integration done from send-demo.mjs, a standalone SDK snippet, or
any event that bypasses the user's running application.
Verify
After dependencies, env vars, and code edits:
- Ask the user to restart the local app or deploy/restart the production app.
- Ask the user to perform one real chat, agent action, or MCP tool call.
- Ask the user to check Agnost dashboard raw logs, users, conversations, tools,
and traces for that real interaction. For OTel, apply the full validation
checklist above rather than checking only that one span arrived.
Report the route used, files changed, env vars required, restart/deploy step,
and the exact real interaction needed for verification. If no event appears,
inspect app logs and env propagation before adding more code.
Verification loop
Repeat until the real interaction appears in Agnost or a concrete blocker is
found:
- Ask for the smallest missing evidence: restart/deploy confirmation, env var
source, app logs, real interaction timestamp, dashboard screenshot/log, or
the exact AI entrypoint.
- Fix only the proven gap.
- Ask the user to restart/deploy again and repeat the same real interaction.
- Re-check the Agnost dashboard result before claiming success.
1---2name: agnost-ai3description: USE to guide an AI agent or CLI tool through adding Agnost AI analytics to a customer Python or TypeScript app from this installed skill directory. Inspect existing telemetry first, preserve a supported OTel path when it produces usable AI spans, otherwise use Agnost SDK/MCP packages, then verify the real conversation data model end to end.4---56# Agnost AI integration78Work from the target app root. This is the skill route: do not tell the user to9install an npm package, use a global binary, or run a package runner. Agents may10call bundled `scripts/` helpers from this installed skill directory, but the11skill contract is the integration workflow.1213## Ask first1415Before editing, ask only for missing facts:1617- Agnost org id from the dashboard.18- Target app/package path if the repo is a monorepo.19- Whether verification should happen in a local app or deployed production app.20- Whether installing Agnost packages is allowed.21- The real AI entrypoint: chat route, agent call, MCP server startup, or tool call.22- How the app is restarted or deployed after env/code changes.2324If the org id is absent, stop and ask for it. Do not invent one.2526## Choose the route2728Inspect existing telemetry before choosing an integration:2930- Find any OpenTelemetry provider, exporter, framework instrumentation, env31 configuration, and representative spans from the real AI entrypoint.32- Check whether the emitted span family is supported by Agnost. Supported33 signals include OTel `gen_ai.*`, Vercel AI `ai.*`, OpenInference `llm.*`,34 LiveKit `lk.*`, Mastra, LangSmith, MCP, and custom `tool.*` spans.35- When an existing OpenTelemetry path emits supported spans, preserve it and36 route those spans to Agnost. Do not install a Conversation SDK merely because37 the app is a general TypeScript or Python application.38- Retell does not expose a documented OTLP export. For Retell agents, configure39 the `call_analyzed` webhook route in `references/frameworks.md`; do not use40 Live Monitoring, Analytics, or `transcript_updated` as a trace substitute.41- Treat automatic OTel detection as a candidate, not proof. Inspect or trigger42 one real interaction and validate the resulting trace with the checklist43 below before declaring that route usable.44- If OTel exists but the real AI path emits no supported spans, add the45 framework's official instrumentation or the smallest missing attributes at46 the real entrypoint. If that cannot produce a faithful conversation model,47 use the matching Agnost SDK/MCP path instead.48- Respect an explicit `--strategy sdk` or `--strategy otel` choice.4950Use SDK/MCP integration when there is no usable existing OTel path:5152- TypeScript conversation app: install `agnostai`, initialize once, wrap the real53 model/agent call with `begin()` and `end()`.54- Python conversation app: install `agnost`, initialize once, wrap the real55 model/agent call with `begin()`/`end()` or `track_ai()`.56- TypeScript MCP server: install `agnost`, call `configureFromEnv()` and57 `trackMCP(server, orgId, config)` after server construction and before58 transport connection. For HTTP/OAuth MCP servers, preserve the official59 transport request path (`transport.handleRequest(req, res, req.body)`) so60 `extra.requestInfo.headers` reaches Agnost. If the target uses a custom61 transport or manual `handleMessage(...)`, pass62 `{ requestInfo: { headers: req.headers }, authInfo: req.auth }`. If OAuth63 middleware validates the bearer token, attach stable non-secret identity on64 `req.auth.extra` such as `{ userId, tokenId }`; Agnost uses `tokenId` as the65 durable OAuth conversation/session key. If headers are unavailable, Agnost66 can also read identity from `authInfo.sub`, `authInfo.claims`,67 `authInfo.tokenPayload`, `authInfo.extra`, `authInfo.token`,68 `authInfo.accessToken`, or `authInfo.access_token`; never use OAuth69 `clientId` as the user id. Never log raw bearer tokens.70- Python MCP/FastMCP server: install `agnost-mcp`, call `track(server, org_id,71 config(...))` after tool registration and before `run()`. The SDK supports72 stdio, SSE, and stateful/stateless Streamable HTTP. Multiple tracked server73 instances in one process must use the same org ID and config. Without a74 custom sync/async `identify`, built-in identity uses bearer or validated MCP75 auth context without forwarding raw credentials, and identity is cached per76 session key.7778If no usable supported OTel route exists and a Node/TypeScript project contains79MCP code but is not solely an MCP server80(for example it also has app, agent, model, OpenAI, Vercel AI SDK, LangChain,81Mastra, Next/React, or API-server code), use its supported existing OTel path or82the TypeScript conversation SDK route (`agnostai`) and instrument the real AI83turn. Use the MCP wrapper route only when the package's main surface is a84dedicated MCP server.8586Keep input and output capture enabled by default. For options named87`disableInput`/`disableOutput` (or Python `disable_input`/`disable_output`),88`false` means capture is on. Set them to `true` only when the user explicitly89asks to redact inputs/outputs or the target app's privacy requirements demand it.9091Supported OTel recipe targets include LiveKit Agents, Vercel AI SDK, Mastra,92Spectrum TS, LangChain, OpenAI, and other already-instrumented OTel apps.9394Do not make a synthetic fetcher or custom OTLP payload path when an official SDK,95MCP wrapper, or framework OTel option exists.9697## Validate an OTel route9899For a representative real interaction, inspect the emitted trace and the100resulting Agnost user, conversation, turns, events, and tool details. Arrange101attributes at the framework instrumentation or real AI entrypoint when a gap is102found. The route is valid only when all of these checks pass:1031041. **User mapping:** use one stable `agnost.user_id`, `enduser.id`, or `user.id`105 for the same customer across all conversations. Verify that two separate106 conversations for that customer map to the same Agnost user and that another107 customer cannot inherit that identity.1082. **Conversation mapping:** use one stable `agnost.session_id`,109 `gen_ai.conversation.id`, or `session.id` for all the events and turns in one110 conversation, including spans exported in separate batches. A new111 conversation must receive a different ID, and its user/assistant turns must112 remain ordered and complete.1133. **Turn and tool hierarchy:** each user-assistant turn must retain its input114 and output. Internal `tool.*`, framework-native tool, or MCP tool spans must115 be child spans of the turn that invoked them, using the real OTel parent span116 ID rather than a custom parent attribute.1174. **AI and SDK attributes:** keep the framework's native attributes and confirm118 model, provider, operation, success/error, and available token counts are on119 the right span. Prefer current GenAI fields such as120 `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens`; retain useful121 SDK-specific `ai.*`, `llm.*`, `lk.*`, Mastra, LangSmith, or MCP attributes.1225. **Custom metadata:** use `user.*` or `enduser.*` for custom user metadata,123 `conversation.*` or `session.*` for custom conversation metadata, and124 non-reserved span attributes for custom event metadata. Put stable values on125 the resource or propagate them to every relevant span; put turn/tool-specific126 values only on the event span they describe.127128Fix the narrowest proven gap, restart or redeploy, repeat the same interaction,129and re-check the trace. Do not replace a working framework trace tree with130synthetic spans solely to rename attributes.131132## Read the right reference133134Open only the matching section from `references/frameworks.md`:135136- `#conversation-ts-agnostai`137- `#conversation-py-agnost`138- `#mcp-ts-agnost`139- `#mcp-py-agnost-mcp`140- `#vercel-ai-otlp`141- `#openai-openinference-otlp`142- `#mastra-otlp`143- `#spectrum-ts-app-level-otel-spans`144- `#langchain-langsmith-otel-mode`145- `#custom-otel-spans`146147Voice-agent routes:148149- `#livekit-agents-native-otlp`150- `#retell-call-analyzed-webhook`151152For `vercel-ai`, read `references/frameworks.md#vercel-ai-otlp` before editing.153Use the official Agnost recipe only: OTel exporter setup plus154`experimental_telemetry` on modern `generateText`/`streamText`/`generateObject`155calls. If the app uses legacy `OpenAIStream(...)` without a modern call shape,156configure env/deps only if the user chose OTel, then report that app telemetry157requires migrating to a supported Vercel AI SDK call shape or using SDK158instrumentation. Do not generate custom OTLP fetches, synthetic spans, or159wrapper functions.160161### Voice agents162163For `livekit-ts` or `livekit-py`, read164`references/frameworks.md#livekit-agents-native-otlp` before editing. Preserve165LiveKit's native spans: configure a standard OTel batch exporter and call the166framework tracer-provider hook before `AgentSession.start()`. Use `session.id`,167`user.id`, `user.*`, and `conversation.*` metadata. Do not add a168custom span wrapper, synthesize OTLP payloads, or use LiveKit room webhooks as a169substitute for agent traces.170171For Retell, read `references/frameworks.md#retell-call-analyzed-webhook`.172Configure the direct Agnost webhook URL with the real organization UUID and173enable `call_analyzed`. Do not add an OTel exporter or ingest incremental174`transcript_updated` events.175176## Backfill existing data177178If the user has historical conversations or agent activity, offer to backfill179it before or alongside live instrumentation. Preserve original timestamps and180stable conversation/event relationships, mapping source identifiers to the181required UUIDs. Create each conversation with the182[Capture Session API](https://docs.agnost.ai/capture-session), then send its183turn-pairs and tool calls with the184[Capture Event API](https://docs.agnost.ai/capture-event). Follow the API185reference for event hierarchy, input/output shape, and historical timestamps.186187## Script helpers188189Scripts are helpers for agents and CLI tools, not the product surface.190191Use them only after choosing the route above:192193```bash194node "$SKILL_DIR/scripts/detect.mjs" --dir . --strategy <auto|sdk|otel> --json195node "$SKILL_DIR/scripts/instrument.mjs" --dir . --framework <framework> --org-id <org-id> --mode <local|prod> --env-mode <file|shell|manual> --json196node "$SKILL_DIR/scripts/send-demo.mjs" --org-id <org-id> --transport <ingest|otel> --mode <local|prod> --json197```198199`detect.mjs` can suggest a route. In `auto` mode it keeps a supported framework's200existing OTel setup, but that suggestion still requires real trace validation.201`instrument.mjs` can apply the narrowest known edit. `send-demo.mjs` can check202whether Agnost accepts traffic, but it does not prove the customer app is203integrated.204205## Definition of done206207Integration is done only when the user's own application runs locally with the208production Agnost endpoint and emits telemetry from its real code path.209210- Set local app env to the real org id and prod endpoints:211 `AGNOST_ORG_ID=<org-id>`, `AGNOST_ENDPOINT=https://api.agnost.ai`, and when212 using OTel, `AGNOST_OTEL_URL=https://otel.agnost.ai`.213- Tell the agent harness/user to run the local application with its normal start214 command after env and code changes are applied.215- Trigger one real chat, agent action, or MCP tool call through that running216 local app.217- Confirm the user, conversation, turns/events, tool hierarchy, attributes, and218 metadata in the Agnost dashboard before saying the integration is complete.219220Do not call integration done from `send-demo.mjs`, a standalone SDK snippet, or221any event that bypasses the user's running application.222223## Verify224225After dependencies, env vars, and code edits:2262271. Ask the user to restart the local app or deploy/restart the production app.2282. Ask the user to perform one real chat, agent action, or MCP tool call.2293. Ask the user to check Agnost dashboard raw logs, users, conversations, tools,230 and traces for that real interaction. For OTel, apply the full validation231 checklist above rather than checking only that one span arrived.232233Report the route used, files changed, env vars required, restart/deploy step,234and the exact real interaction needed for verification. If no event appears,235inspect app logs and env propagation before adding more code.236237## Verification loop238239Repeat until the real interaction appears in Agnost or a concrete blocker is240found:2412421. Ask for the smallest missing evidence: restart/deploy confirmation, env var243 source, app logs, real interaction timestamp, dashboard screenshot/log, or244 the exact AI entrypoint.2452. Fix only the proven gap.2463. Ask the user to restart/deploy again and repeat the same real interaction.2474. Re-check the Agnost dashboard result before claiming success.