Add parameter to track detected AI agent string#2423
Conversation
Package publishing
Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation. |
There was a problem hiding this comment.
Code Review
This pull request adds an optional agent parameter to the Analytics class and its implementations to track AI coding assistants. Feedback suggests documenting this parameter in the Analytics.development constructor, truncating the agent value to 36 characters to comply with Google Analytics 4 limits, and adding a corresponding unit test to verify truncation.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
PR HealthUnused Dependencies ✔️
For details on how to fix these, see dependency_validator. This check can be disabled by tagging the PR with
Breaking changes
|
| Package | Change | Current Version | New Version | Needed Version | Looking good? |
|---|---|---|---|---|---|
| unified_analytics | Breaking | 8.0.14 | 8.0.15 | 9.0.0 Got "8.0.15" expected >= "9.0.0" (breaking changes) |
This check can be disabled by tagging the PR with skip-breaking-check.
API leaks ⚠️
The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.
| Package | Leaked API symbol | Leaking sources |
|---|---|---|
| unified_analytics | Condition | survey_handler.dart::Survey::conditionList survey_handler.dart::Survey::new::conditionList |
| unified_analytics | PersistedSurvey | survey_handler.dart::SurveyHandler::fetchPersistedSurveys |
| unified_analytics | GAClient | analytics.dart::Analytics::fake::gaClient analytics.dart::AnalyticsImpl::new::gaClient |
| unified_analytics | UserProperty | analytics.dart::FakeAnalytics::userProperty |
This check can be disabled by tagging the PR with skip-leaking-check.
Changelog Entry ✔️
| Package | Changed Files |
|---|
Changes to files need to be accounted for in their respective changelogs.
This check can be disabled by tagging the PR with skip-changelog-check.
Coverage ⚠️
| File | Coverage |
|---|---|
| pkgs/unified_analytics/lib/src/analytics.dart | 💚 73 % ⬆️ 0 % |
| pkgs/unified_analytics/lib/src/enums.dart | 💚 100 % |
| pkgs/unified_analytics/lib/src/user_property.dart | 💚 96 % ⬆️ 0 % |
| pkgs/unified_analytics/lib/unified_analytics.dart | 💔 Not covered |
This check for test coverage is informational (issues shown here will not fail the PR).
This check can be disabled by tagging the PR with skip-coverage-check.
License Headers ✔️
// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
| Files |
|---|
| no missing headers |
All source files should start with a license header.
Unrelated files missing license headers
| Files |
|---|
| pkgs/bazel_worker/benchmark/benchmark.dart |
| pkgs/coverage/lib/src/coverage_options.dart |
| pkgs/html/example/main.dart |
| pkgs/pubspec_parse/test/git_uri_test.dart |
| pkgs/watcher/test/custom_watcher_factory_test.dart |
This check can be disabled by tagging the PR with skip-license-check.
|
@bkonyi any idea why the checker thinks this is a breaking change?
|
bwilkerson
left a comment
There was a problem hiding this comment.
There's another piece that's missing here. We're moving toward putting sharable logic into this package, so it would be good to have a utility, possibly a factory constructor on the enum mentioned in my other comment, that would compute the agent information. I have seen at least one piece of code, though I don't remember where, that computes the agent based on environment variables, and those ought to be available in this package.
Doing so would mean that all of our tooling is using the same approach to computing the information, which will further the goal of making the events easier to collate accurately.
It also means that it will be easier to add this information to every tool for which it's appropriate.
| String? flutterVersion, | ||
| String? clientIde, | ||
| String? enabledFeatures, | ||
| String? agent, |
There was a problem hiding this comment.
It would be better if this took a value from an enum. That would ensure that all of our tools were using the same names for each agent and that data across events could be correlated accurately.
Doing so would have the disadvantage that we needed to update this package every time a new agent comes out, but new agents aren't coming out frequently anymore. I think the advantage is worth the cost.
There was a problem hiding this comment.
Additionally I expect that we will see clients with multiple enabled so this should probably be a set of 1 for now then we can add multi detection later.
There was a problem hiding this comment.
I don't think an enum is feasible, this space is moving far faster than I'm willing to update and publish the unified_analytics package. You can see in flutter/flutter#187630 how complicated this detection logic is, including some that are just parsing the env AGENT and AI_AGENT https://github.com/flutter/flutter/pull/187630/changes#diff-117ebbd481e53f7a37cf568b4969f535cedf79d067b2a70d0a4186a2d1837678R150-R160
Sources:
- https://code.claude.com/docs/en/env-vars
- https://www.npmjs.com/package/@vercel/detect-agent
@vercel/detect-agent: consider also checkingAGENTenv var vercel/vercel#15336- https://github.com/ergebnis/agent-detector
I think it would be better to collect whatever strings we can figure out, and then make our dashboards be flexible coalescing them.
There was a problem hiding this comment.
... update and publish ...
If the infrastructure / process is discouraging us from doing the right thing, then I think we need to fix the infrastructure / process. (I'm not suggesting that we postpone landing this until we've done the bigger task, just that we also do the bigger task.)
There was a problem hiding this comment.
I added the enum AiAgent.
There was a problem hiding this comment.
I moved the AI detection logic into this package and added an AiAgent enum. Could you take a look, is that the pattern you wanted?
There was a problem hiding this comment.
Thank you!
This covers the most important part, which was having the detection logic in a reusable form so that all of our tools will report the agent identity in the same way. I probably would have passed the enum around instead of a string, but as you noted that creates problems of its own and I'm not suggesting we do that now.
I don't know whether you want to address Reid's comment about making this a set or if you'd rather we waited to address it.
I'll mark this as approved, but I don't know whether my approval will allow the PR to land. I was previously assuming that it wouldn't, which I why I didn't approve it earlier, but after a meeting yesterday I'm not sure who needs to approve it.
There was a problem hiding this comment.
Looks like it worked. Sorry I didn't think to try that earlier.
There was a problem hiding this comment.
Additionally I expect that we will see clients with multiple enabled so this should probably be a set of 1 for now then we can add multi detection later.
PR to do multi-agent detection (non-breaking change) #2455
|
One other thought: can we, and if so do we want to, capture the version of the agent? For example, if we end up having to tailor our skills, tools, mcp server, etc. for various versions of the agents, then it would be good to know when we no longer need to support older versions. |
I did look into how to figure out the version since that would be interesting, but I couldn't find any environmental way to figure this out. Should be easy to add another parameter if we do figure out how to do that. |
@bwilkerson I didn't realize we were moving any logic into this package. I'm happy to move the logic of flutter/flutter#187630 into here. Can you point me to the right place to organize this code, or a PR that moved logic into this package? I don't see an obvious place for it. |
|
The only one I'm aware of at this point is here: #2344. It adds some utility methods to help all of our tools be more consistent in the way analytics are gathered. Happy to chat off-line if you want more details. |
| String? flutterVersion, | ||
| String? clientIde, | ||
| String? enabledFeatures, | ||
| String? agent, |
There was a problem hiding this comment.
Thank you!
This covers the most important part, which was having the detection logic in a reusable form so that all of our tools will report the agent identity in the same way. I probably would have passed the enum around instead of a string, but as you noted that creates problems of its own and I'm not suggesting we do that now.
I don't know whether you want to address Reid's comment about making this a set or if you'd rather we waited to address it.
I'll mark this as approved, but I don't know whether my approval will allow the PR to land. I was previously assuming that it wouldn't, which I why I didn't approve it earlier, but after a meeting yesterday I'm not sure who needs to approve it.
Collect telemetry on which AI agents are calling `flutter` commands, based on environment variables the agents add in their sessions. This uses the `unified_analytics` change dart-lang/tools#2423 There's a conversation in that PR about making `AiAgent.detectAgentName` return a `Set`. I am adding this now dart-lang/tools#2455 (GA needs the user_property list values to be a string delineated by commas anyway, so it's not a breaking change), and then migrate this code over to it. However, I'd like to land this as-is ASAP to make it before the next stable cutoff. Fixes flutter#187623. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Collect telemetry on which AI agents are calling `flutter` commands, based on environment variables the agents add in their sessions. This uses the `unified_analytics` change dart-lang/tools#2423 There's a conversation in that PR about making `AiAgent.detectAgentName` return a `Set`. I am adding this now dart-lang/tools#2455 (GA needs the user_property list values to be a string delineated by commas anyway, so it's not a breaking change), and then migrate this code over to it. However, I'd like to land this as-is ASAP to make it before the next stable cutoff. Fixes flutter#187623. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Add an optional parameter to include a string describing a detected AI agent.
AiAgent.detectAgentNamewill take a platform environment and return a string, to be passed back into the usage event.Environment logic gathered from:
@vercel/detect-agent: consider also checkingAGENTenv var vercel/vercel#15336Part of flutter/flutter#187623
Contribution guidelines:
dart format.Many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.
Note: The Dart team is trialing Gemini Code Assist. Don't take its comments as final Dart team feedback. Use the suggestions if they're helpful; otherwise, wait for a human reviewer.