-
Notifications
You must be signed in to change notification settings - Fork 268
Detects popular AI agents and defaults to no-prompt mode #6633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces automatic detection of popular AI coding agents invoking azd, wiring that into both telemetry (execution environment) and CLI behavior (auto-enabling --no-prompt for seamless non-interactive runs).
Changes:
- Add a new
agentdetectpackage that detects AI agents via environment variables,AZURE_DEV_USER_AGENT, and parent-process inspection with cross-platform (Windows/Linux/macOS) implementations and caching. - Integrate agent detection into global flag parsing so that
GlobalCommandOptions.NoPromptdefaults totruewhen an agent is detected, while respecting explicit--no-promptvalues and expanding tests to cover this behavior. - Extend telemetry execution environment fields to include AI agent-specific environments and feed agent detection results into
getExecutionEnvironment.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
cli/azd/internal/tracing/resource/exec_environment.go |
Adds execEnvFromAgent using agentdetect.GetCallingAgent to set a specific telemetry execution environment when running under known AI agents. |
cli/azd/internal/tracing/fields/fields.go |
Introduces new execution-environment constant strings for each supported AI agent and a generic agent bucket. |
cli/azd/internal/runcontext/agentdetect/types.go |
Defines AgentType, DetectionSource, AgentInfo, and helper methods (DisplayName, NoAgent) to standardize agent metadata. |
cli/azd/internal/runcontext/agentdetect/detect.go |
Implements the top-level detection pipeline with caching and debug logging, plus IsRunningInAgent and ResetDetection for tests. |
cli/azd/internal/runcontext/agentdetect/detect_env.go |
Implements detection via well-known agent environment variables and AZURE_DEV_USER_AGENT substring matching to map back to AgentType. |
cli/azd/internal/runcontext/agentdetect/detect_process.go |
Adds OS-agnostic parent-process tree walking and process-name pattern matching to infer calling agents when env/user agent detection fails. |
cli/azd/internal/runcontext/agentdetect/detect_process_linux.go |
Linux-specific implementation reading /proc to obtain process name, executable, cmdline, and parent PID for detection. |
cli/azd/internal/runcontext/agentdetect/detect_process_darwin.go |
macOS-specific implementation using ps and optionally lsof to gather process info and parent PID. |
cli/azd/internal/runcontext/agentdetect/detect_process_windows.go |
Windows-specific implementation using Win32 APIs to query executable path and enumerate processes to find parent PID. |
cli/azd/internal/runcontext/agentdetect/detect_test.go |
Adds tests for DisplayName, NoAgent, env-var and user-agent detection, process matching, caching behavior, and IsRunningInAgent. |
cli/azd/internal/global_command_options.go |
Documents that NoPrompt is automatically set when an AI agent is detected, unless explicitly overridden with --no-prompt=false. |
cli/azd/cmd/auto_install.go |
Updates global --no-prompt flag help text and enhances ParseGlobalFlags to turn on NoPrompt when agentdetect.IsRunningInAgent() and the flag wasn’t explicitly set. |
cli/azd/cmd/auto_install_test.go |
Adds unit tests ensuring ParseGlobalFlags correctly combines explicit --no-prompt settings with automatic agent detection via env vars. |
cli/azd/cmd/auto_install_integration_test.go |
Adds integration-style tests that exercise the full agent detection + global flag parsing flow, including AZURE_DEV_USER_AGENT-based detection and override scenarios. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
cli/azd/internal/runcontext/agentdetect/detect_process_windows.go
Outdated
Show resolved
Hide resolved
Azure Dev CLI Install InstructionsInstall scriptsMacOS/Linux
bash: pwsh: WindowsPowerShell install MSI install Standalone Binary
MSI
Documentationlearn.microsoft.com documentationtitle: Azure Developer CLI reference
|
vhvb1989
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is cool
Agent Launch Detection for azd
Automatically detects when azd is invoked by AI coding agents and applies
--no-promptbehavior to enable seamless automation.What
AZURE_DEV_USER_AGENTparsing, and parent process tree walkingWhy
AI coding agents need azd to run non-interactively. Rather than requiring agents to always pass
--no-prompt, azd now auto-detects agent context and suppresses prompts automatically.Key Changes
ParseGlobalFlagsto setNoPrompt=truewhen agent detectedBehavior
--no-promptis implicitly enabled--no-prompt=falseexplicitly disables auto-detection