Add AI agent detection to user-agent string#1537
Open
simonfaltum wants to merge 6 commits intomainfrom
Open
Conversation
Detect known AI coding agents (Claude Code, Cursor, Cline, Codex, Gemini CLI, OpenCode, Antigravity) via environment variables and append agent/<name> to the User-Agent header on HTTP requests. Returns empty when zero or multiple agents are detected (ambiguity guard). Part of a cross-SDK effort (Go, Python, Java). Co-authored-by: Isaac Signed-off-by: simon <simon.faltum@databricks.com>
The previous tests in config/visitors_test.go manually built the UA context instead of going through the HTTP client visitor chain. This meant they would pass even if the visitor wiring in api_client.go were removed. New tests in client/client_test.go follow the same pattern as TestUserAgentForCiCd: create a real HTTP client, make a request, and capture the actual User-Agent header to verify the agent/ entry appears end-to-end. Co-authored-by: Isaac Signed-off-by: simon <simon.faltum@databricks.com>
3 tasks
simonfaltum
commented
Mar 12, 2026
Member
Author
simonfaltum
left a comment
There was a problem hiding this comment.
Review (automated, 2 agents)
Verdict: Approved
0 Critical | 0 Major | 2 Gap | 1 Nit | 1 Suggestion
See inline comments for details.
Add early exit in lookupAgentProvider when count > 1 to communicate intent more clearly. Add TestUserAgentForMultipleAgents client-level integration test for the multi-agent ambiguity guard. Co-authored-by: Isaac
We have data from direct testing in Copilot CLI confirming it sets COPILOT_CLI=1 in its environment. Add it to the canonical agent list. Co-authored-by: Isaac
Signed-off-by: simon <simon.faltum@databricks.com>
|
If integration tests don't run automatically, an authorized user can run them manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
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.
Changes
The SDK now detects known AI coding agents via environment variables and appends
agent/<name>to the User-Agent header on every HTTP request. If zero or multiple agents are detected, no agent segment is added (ambiguity guard).ANTIGRAVITY_AGENTantigravityCLAUDECODEclaude-codeCLINE_ACTIVEclineCODEX_CIcodexCOPILOT_CLIcopilot-cliCURSOR_AGENTcursorGEMINI_CLIgemini-cliOPENCODEopencodeOPENCLAW_SHELLopenclawThe
COPILOT_CLIenv var was confirmed by direct testing in Copilot CLI.The
OPENCLAW_SHELLenv var uses context-qualified values (exec,acp,acp-client); any non-empty value triggers detection.This is part of a cross-SDK effort to add agent detection to Go, Python, and Java SDKs with identical agent lists.
Tests
useragent/agent_test.go: each of the 9 agents individually, no agent, multiple agents, empty value, caching behavior.config/visitors_test.go: agent detected in UA context, no agent in UA context.go vetclean.