Skip to content

Honor AI_AGENT and pass raw values through#196

Merged
renaudhartert-db merged 1 commit into
mainfrom
honor-ai-agent-env-var
Jun 5, 2026
Merged

Honor AI_AGENT and pass raw values through#196
renaudhartert-db merged 1 commit into
mainfrom
honor-ai-agent-env-var

Conversation

@renaudhartert-db

Copy link
Copy Markdown
Contributor

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 to agent/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-agent library. Tools that integrate with the Vercel ecosystem set it for the same purpose as AGENT, under a different name, and the SDK ignores it.
  • Coercing unrecognized values to "unknown" buries useful signal. A tool reporting claude-code_2-1-141 shows up as agent/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_AGENT as a fallback after AGENT and 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. AGENT is checked first; AI_AGENT only when AGENT is unset or empty. Empty is treated as unset for both. Explicit product-specific matchers (e.g. CLAUDECODE) still win over both.
  • The fallback value is no longer coerced to "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: Add AI_AGENT_ENV_VAR and MAX_AGENT_FALLBACK_LEN constants; rewrite agentEnvFallback to consult AGENT then AI_AGENT, route the value through the existing sanitize() helper, and cap its length. Update doc comments.
  • packages/core/tests/clientinfo/agent.test.ts: Update the two AGENT-fallback cases for raw passthrough; add cases for sanitization, the length cap, AI_AGENT detection, and AGENT/AI_AGENT precedence.
  • packages/core/tests/clientinfo/default.test.ts: Update the integration case that previously expected agent/unknown.

How is this tested?

  • npx vitest run packages/core/tests/clientinfo/agent.test.ts passes (40 tests).
  • npm test --workspace=packages/core passes (367 tests); npm run test:browser --workspace=packages/core passes (266 tests).
  • npm run format:check, npm run lint, and npm run typecheck are clean.

NO_CHANGELOG=true

@renaudhartert-db renaudhartert-db requested review from parthban-db and simonfaltum and removed request for simonfaltum June 5, 2026 08:59
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.
@renaudhartert-db renaudhartert-db added this pull request to the merge queue Jun 5, 2026
Merged via the queue into main with commit bd20889 Jun 5, 2026
45 checks passed
@renaudhartert-db renaudhartert-db deleted the honor-ai-agent-env-var branch June 5, 2026 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants