Skip to content

Add parameter to track detected AI agent string#2423

Merged
bkonyi merged 7 commits into
dart-lang:mainfrom
jmagman:agent
Jun 17, 2026
Merged

Add parameter to track detected AI agent string#2423
bkonyi merged 7 commits into
dart-lang:mainfrom
jmagman:agent

Conversation

@jmagman

@jmagman jmagman commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Add an optional parameter to include a string describing a detected AI agent.

AiAgent.detectAgentName will take a platform environment and return a string, to be passed back into the usage event.

Environment logic gathered from:

Part of flutter/flutter#187623


  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:

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.

@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown

Package publishing

Package Version Status Publish tag (post-merge)
package:api_summary 0.1.0-wip WIP (no publish necessary)
package:bazel_worker 1.1.5 already published at pub.dev
package:benchmark_harness 2.4.0 already published at pub.dev
package:boolean_selector 2.1.2 already published at pub.dev
package:browser_launcher 1.2.0-wip WIP (no publish necessary)
package:cli_config 0.2.1-wip WIP (no publish necessary)
package:cli_util 0.5.1 already published at pub.dev
package:clock 1.1.3-wip WIP (no publish necessary)
package:code_builder 4.12.0-wip WIP (no publish necessary)
package:coverage 1.15.1 already published at pub.dev
package:csslib 1.0.2 already published at pub.dev
package:extension_discovery 2.1.0 already published at pub.dev
package:file 7.0.2-wip WIP (no publish necessary)
package:file_testing 3.1.0-wip WIP (no publish necessary)
package:glob 2.1.3 already published at pub.dev
package:graphs 2.4.0-wip WIP (no publish necessary)
package:html 0.15.7-wip WIP (no publish necessary)
package:io 1.1.0-wip WIP (no publish necessary)
package:json_rpc_2 4.1.0 already published at pub.dev
package:markdown 7.4.0 ready to publish markdown-v7.4.0
package:mime 2.1.0-wip WIP (no publish necessary)
package:oauth2 2.0.5 already published at pub.dev
package:package_config 3.0.0 already published at pub.dev
package:pool 1.5.3-wip WIP (no publish necessary)
package:process 5.0.5 (error) pubspec version (5.0.5) and changelog (5.0.6-wip) don't agree
package:pub_semver 2.2.0 already published at pub.dev
package:pubspec_parse 1.6.0-wip WIP (no publish necessary)
package:source_map_stack_trace 2.1.3-wip WIP (no publish necessary)
package:source_maps 0.10.14-wip WIP (no publish necessary)
package:source_span 1.10.2 already published at pub.dev
package:sse 4.2.0 already published at pub.dev
package:stack_trace 1.12.2-wip (error) pubspec version (1.12.2-wip) and changelog (1.12.2-dev) don't agree
package:stream_channel 2.1.4 already published at pub.dev
package:stream_transform 2.1.2-wip WIP (no publish necessary)
package:string_scanner 1.4.2-wip WIP (no publish necessary)
package:term_glyph 1.2.3-wip WIP (no publish necessary)
package:test_reflective_loader 0.6.0 ready to publish test_reflective_loader-v0.6.0
package:timing 1.0.2 already published at pub.dev
package:unified_analytics 8.0.15 ready to publish unified_analytics-v8.0.15
package:watcher 1.2.2-wip WIP (no publish necessary)
package:yaml 3.1.4-wip WIP (no publish necessary)
package:yaml_edit 2.2.4 already published at pub.dev

Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread pkgs/unified_analytics/lib/src/analytics.dart
Comment thread pkgs/unified_analytics/lib/src/analytics.dart Outdated
Comment thread pkgs/unified_analytics/test/unified_analytics_test.dart
@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown

PR Health

Unused Dependencies ✔️
Package Status
unified_analytics ✔️ All dependencies utilized correctly.

For details on how to fix these, see dependency_validator.

This check can be disabled by tagging the PR with skip-unused-dependencies-check.

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.

@jmagman
jmagman marked this pull request as draft June 5, 2026 21:28
@jmagman
jmagman marked this pull request as ready for review June 5, 2026 21:40
@jmagman

jmagman commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

@bkonyi any idea why the checker thinks this is a breaking change?

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.

@bwilkerson bwilkerson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

... 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.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added the enum AiAgent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks like it worked. Sorry I didn't think to try that earlier.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

@bwilkerson

Copy link
Copy Markdown
Member

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.

@jmagman

jmagman commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

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.

@jmagman

jmagman commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

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.

@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.

@bwilkerson

Copy link
Copy Markdown
Member

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,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@bkonyi
bkonyi merged commit 8a608b1 into dart-lang:main Jun 17, 2026
20 checks passed
@jmagman
jmagman deleted the agent branch July 6, 2026 19:45
pull Bot pushed a commit to NOUIY/flutter that referenced this pull request Jul 7, 2026
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
Rusino pushed a commit to Rusino/flutter that referenced this pull request Jul 7, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants