Honor AI_AGENT and pass raw values through#196
Merged
Conversation
Adds the Vercel @vercel/detect-agent AI_AGENT=<name> env var as a secondary fallback after the agents.md AGENT=<name> standard. AGENT wins when both are non-empty; empty is treated as unset for both. Also changes the fallback behavior to pass the raw value through (sanitized via sanitize() and capped at 64 chars) instead of coercing unrecognized names to the literal "unknown". Bucketing arbitrary tool names is an ETL concern, not the SDK's; the prior coercion buried useful signal such as versioned variants like "claude-code_2-1-141". Mirrors databricks-sdk-go#1683, databricks-sdk-py#1454, and databricks-sdk-java#815.
239e6f7 to
ceec205
Compare
parthban-db
approved these changes
Jun 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR mirrors parallel changes in databricks-sdk-go, databricks-sdk-py, and databricks-sdk-java, keeping agent detection in sync across SDKs.
Summary
Honors the Vercel
AI_AGENT=<name>convention as a secondary fallback for AI-agent detection in the user-agent header, and surfaces the raw fallback value instead of coercing unrecognized names toagent/unknown.Why
The SDK appends the detected AI coding agent to the user-agent header so Databricks can understand which agents invoke the SDK. Today, when no explicit product-specific env var fires, detection consults only the agents.md
AGENT=<name>standard, and any value it does not recognize is coerced to the literal"unknown".Two gaps follow from that:
AI_AGENT=<name>is the parallel convention pushed by Vercel's@vercel/detect-agentlibrary. Tools that integrate with the Vercel ecosystem set it for the same purpose asAGENT, under a different name, and the SDK ignores it."unknown"buries useful signal. A tool reportingclaude-code_2-1-141shows up asagent/unknown, so versioned variants and not-yet-listed tools are indistinguishable. Bucketing arbitrary tool names is an ETL concern, not the SDK's.This PR adds
AI_AGENTas a fallback afterAGENTand passes the raw value through instead of categorizing it.What changed
Interface changes
None. The exported functions (
lookupAgentProvider,agentProvider,clearAgentCache) keep their signatures.Behavioral changes
AI_AGENT=<name>is now honored as a fallback.AGENTis checked first;AI_AGENTonly whenAGENTis unset or empty. Empty is treated as unset for both. Explicit product-specific matchers (e.g.CLAUDECODE) still win over both."unknown". The raw value is passed through, sanitized to satisfy the user-agent allowlist ([-0-9A-Za-z_.+], other chars become-) and capped at 64 characters to keep the header bounded.Internal changes
packages/core/src/clientinfo/agent.ts: AddAI_AGENT_ENV_VARandMAX_AGENT_FALLBACK_LENconstants; rewriteagentEnvFallbackto consultAGENTthenAI_AGENT, route the value through the existingsanitize()helper, and cap its length. Update doc comments.packages/core/tests/clientinfo/agent.test.ts: Update the twoAGENT-fallback cases for raw passthrough; add cases for sanitization, the length cap,AI_AGENTdetection, andAGENT/AI_AGENTprecedence.packages/core/tests/clientinfo/default.test.ts: Update the integration case that previously expectedagent/unknown.How is this tested?
npx vitest run packages/core/tests/clientinfo/agent.test.tspasses (40 tests).npm test --workspace=packages/corepasses (367 tests);npm run test:browser --workspace=packages/corepasses (266 tests).npm run format:check,npm run lint, andnpm run typecheckare clean.NO_CHANGELOG=true