Skip to content

[sdk] tag API requests with the detected AI agent - #320

Draft
erulkey wants to merge 4 commits into
elisabeth/cli-telemetryfrom
elisabeth/sdk-agent-stamp
Draft

[sdk] tag API requests with the detected AI agent#320
erulkey wants to merge 4 commits into
elisabeth/cli-telemetryfrom
elisabeth/sdk-agent-stamp

Conversation

@erulkey

@erulkey erulkey commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #319, which added the agent/<name> user-agent phrase to the CLI. This extends the same stamp to the SDK, so programmatic callers get attributed too once the server side records the header (same ingestion ask, no new dependency on it).

This:

  • appends agent/<name> to the SDK's existing user-agent when detect-agent identifies an AI agent driving the process; no agent means the header is byte-identical to today
  • adds the dedupe guard in the CLI's fetch wrapper so CLI-over-SDK traffic carries exactly one agent phrase, with a unit test pinning that
  • adds detect-agent@1.2.0 as an SDK runtime dependency (zero transitive dependencies, node >=20 which the SDK already requires)

Deliberately not added: telemetry events. The SDK ships in customer production code; this is request metadata only, nothing is collected or sent anywhere new.

Verified:

  • probe with a logging fetch inside a Claude Code session:
UA: vercel/sandbox/3.2.0 agent/claude-code_2-1-247_agent (Node.js/v26.7.0; darwin/arm64)
  • same probe with env -u CLAUDECODE -u CLAUDE_CODE -u AI_AGENT (a deployed server's environment): vercel/sandbox/3.2.0 (Node.js/v26.7.0; darwin/arm64), unchanged
  • combined path unit test asserts exactly one agent/ occurrence in the final header
  • pnpm turbo typecheck --filter=@vercel/sandbox --filter=sandbox --force: 4/4; CLI suite 101 passed; SDK suite 291 passed, 80 skipped (pre-existing live-credential skips)

Detection only labels the process driving the SDK, so servers creating sandboxes to run agents inside them correctly carry no label; that population is the planned self-declared tag, not this PR.

@vercel

vercel Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
sandbox Ready Ready Preview, v0 Aug 31, 2026 3:38pm
sandbox-sdk-ai-example Ready Ready Preview, v0 Aug 31, 2026 3:38pm
workflow-code-runner Ready Ready Preview, v0 Aug 31, 2026 3:38pm

@alexfarnhambrown alexfarnhambrown left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked where this header could land: no sandbox table in PRODUCT has a user_agent column — not the usage facts, not any sandbox event-streaming topic. So both this and #319 depend on an ingestion change that doesn't have a ticket or owner yet. If the landing place is the sandbox usage-fact pipeline, that's the same pipeline we need a failure status from, so it's probably one ask rather than two.

The upside is real though: the composed header separates CLI-driven from programmatic from agent-driven with no join required, which is a split we can't currently make.

Comment thread packages/vercel-sandbox/package.json Outdated

// Attribute traffic to the AI agent driving this process, if any, so the
// server side can record it once ingestion support lands.
const aiAgent = await detectAgentName();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SDK has no telemetry setting, so once the server side records this header there's no way to opt out of agent attribution, and the CLI's VERCEL_TELEMETRY_DISABLED won't cover SDK traffic. That's request metadata now but collected data the moment ingestion lands, and cheaper to settle before a public SDK ships it. Recommend either honouring VERCEL_TELEMETRY_DISABLED here or documenting that this stamp isn't covered by it.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Half of this is closed — detectAgentName() now returns undefined when VERCEL_TELEMETRY_DISABLED or VERCEL_SANDBOX_TELEMETRY_DISABLED is set.

What's left is the config-file case: someone who ran vercel telemetry disable has enabled: false in config.json and no env var set, and the SDK can't see that, so they'd still get agent/<name> on the user-agent. The CLI path in #319 handles it through telemetry.enabled; the SDK has no equivalent. Looks like the automated review landed on the same point today.

Not urgent from our side — no sandbox table in PRODUCT has a user_agent column, so nothing reads this header yet. Leaving open in case you want to close the config-file case before something does.

@vercel

vercel Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

You must have Developer access to commit code to Vercel Labs on Vercel. If you contact an administrator and receive Developer access, commit again to see your changes.

Learn more: https://vercel.com/docs/accounts/team-members-and-roles/access-roles#team-level-roles

Comment thread packages/sandbox/src/client.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants