-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Agent Toolkit installation after setup moments #10505
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
Open
AndrewAsseily
wants to merge
8
commits into
v2
Choose a base branch
from
nyandrew/agent-toolkit-configure-hint
base: v2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
221ca2c
Suggest Agent Toolkit setup after configure/update and in install scr…
AndrewAsseily dd97515
Add Agent Toolkit hint to aws login and configure sso
AndrewAsseily 60f043e
Address review feedback
AndrewAsseily 6a1aa5a
strip interactive hint from update command
AndrewAsseily 05f3aa3
Address review feedback
AndrewAsseily 5965e72
Show hint instead of prompt outside us-east-1
AndrewAsseily 51e7a13
Dropped the interactive prompt entirely, so everyone gets the same st…
AndrewAsseily 9710bd2
Default agent-toolkit to us-east-1, prompt only in commercial partition
AndrewAsseily File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "type": "enhancement", | ||
| "category": "configure", | ||
| "description": "Suggest installing the Agent Toolkit for AWS when a supported AI coding agent is detected. In the commercial partition an interactive prompt is shown after ``aws configure``, ``aws configure sso``, and a first-time ``aws login`` that creates a new profile; in other partitions a non-interactive tip is shown instead. The prompt only appears on a terminal when no AWS skills are installed yet, and can be permanently suppressed by answering ``never`` or by setting the ``AWS_CLI_AGENT_TOOLKIT_HINT_DISABLED`` environment variable to ``true``. ``aws configure agent-toolkit`` now defaults to the ``us-east-1`` control-plane region unless ``--region`` is given, and a tip is also printed by the install scripts and after ``aws update``." | ||
| } |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"). You | ||
| # may not use this file except in compliance with the License. A copy of | ||
| # the License is located at | ||
| # | ||
| # http://aws.amazon.com/apache2.0/ | ||
| # | ||
| # or in the "license" file accompanying this file. This file is | ||
| # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF | ||
| # ANY KIND, either express or implied. See the License for the specific | ||
| # language governing permissions and limitations under the License. | ||
| """End-of-``aws configure`` hint suggesting the Agent Toolkit wizard. | ||
|
|
||
| After a successful ``aws configure`` that writes profile values, offer to run | ||
| ``aws configure agent-toolkit`` when a supported AI coding agent is present | ||
| and no AWS skills are installed yet. The wizard defaults to the Agent Toolkit | ||
| region (us-east-1), so in the commercial partition the offer is | ||
| an interactive prompt that can run the wizard directly. In other partitions | ||
| that region is unreachable, so we fall back to a non-interactive tip instead | ||
| of routing the user into a cross-partition call. Either way the hint only | ||
| shows on a TTY and can be suppressed. | ||
| """ | ||
|
|
||
| import json | ||
| import logging | ||
| import os | ||
| import re | ||
|
|
||
| from botocore.loaders import Loader | ||
| from botocore.utils import ensure_boolean | ||
|
|
||
| from awscli.customizations.agenttoolkit.agents import ( | ||
| get_detected_real_agents, | ||
| ) | ||
| from awscli.customizations.agenttoolkit.configure import ( | ||
| ConfigureAgentToolkitCommand, | ||
| ) | ||
| from awscli.customizations.prompts import yes_no_never_choice | ||
| from awscli.customizations.utils import uni_print | ||
| from awscli.utils import is_stdin_a_tty | ||
|
|
||
| LOG = logging.getLogger(__name__) | ||
|
|
||
| STATE_PATH = '~/.aws/cli/agent-toolkit/state.json' | ||
|
|
||
| HINT_DISABLED_ENV_VAR = 'AWS_CLI_AGENT_TOOLKIT_HINT_DISABLED' | ||
|
|
||
| # The wizard runs against the Agent Toolkit region, which only | ||
| # exists in the commercial partition. Elsewhere we cannot run it inline, so we | ||
| # only offer the interactive prompt to callers in this partition. | ||
| COMMERCIAL_PARTITION = 'aws' | ||
|
|
||
| PROMPT_TEXT = ( | ||
| '\nConfigure AWS skills and the AWS MCP server for your AI coding ' | ||
| 'agent(s)? [y/n/never]: ' | ||
| ) | ||
|
|
||
| HINT_TEXT = ( | ||
| "\nTip: run 'aws configure agent-toolkit' to set up AWS skills and the " | ||
| 'AWS MCP server for your AI coding agent(s).\n' | ||
| ) | ||
|
|
||
|
|
||
| def _state_file(): | ||
| return os.path.expanduser(STATE_PATH) | ||
|
|
||
|
|
||
| def _load_state(): | ||
| try: | ||
| with open(_state_file()) as f: | ||
| return json.load(f) | ||
| except FileNotFoundError: | ||
| return {} | ||
| except (OSError, json.JSONDecodeError) as e: | ||
| LOG.debug('Could not read agent toolkit hint state: %s', e) | ||
| return {} | ||
|
|
||
|
|
||
| def _save_state(state): | ||
| path = _state_file() | ||
| try: | ||
| os.makedirs(os.path.dirname(path), exist_ok=True) | ||
| tmp_path = f'{path}.tmp' | ||
| with open(tmp_path, 'w') as f: | ||
| json.dump(state, f) | ||
| f.write('\n') | ||
| os.replace(tmp_path, path) | ||
| except OSError as e: | ||
| LOG.debug('Could not write agent toolkit hint state: %s', e) | ||
|
|
||
|
|
||
| def _dismiss_forever(): | ||
| state = _load_state() | ||
| state['hint_dismissed'] = True | ||
| _save_state(state) | ||
|
|
||
|
|
||
| def _has_installed_skills(detected_agents): | ||
| return any(agent.get_installed_skills() for agent in detected_agents) | ||
|
|
||
|
|
||
| def hint_disabled(): | ||
| return ensure_boolean(os.environ.get(HINT_DISABLED_ENV_VAR, '')) | ||
|
|
||
|
|
||
| def _is_eligible(): | ||
| if not is_stdin_a_tty(): | ||
| return False | ||
| if hint_disabled(): | ||
| return False | ||
| if _load_state().get('hint_dismissed'): | ||
| return False | ||
| detected_agents = get_detected_real_agents() | ||
| if not detected_agents: | ||
| return False | ||
| if _has_installed_skills(detected_agents): | ||
| return False | ||
| return True | ||
|
|
||
|
|
||
| def _resolve_region(session, parsed_globals): | ||
| region = getattr(parsed_globals, 'region', None) | ||
| if region: | ||
| return region | ||
| try: | ||
| return session.get_config_variable('region') | ||
| except Exception: | ||
| return None | ||
|
|
||
|
|
||
| def _region_partition(region): | ||
| for partition in Loader().load_data('partitions')['partitions']: | ||
| if region in partition.get('regions', {}): | ||
| return partition['id'] | ||
| regex = partition.get('regionRegex') | ||
| if regex and re.match(regex, region): | ||
| return partition['id'] | ||
| return None | ||
|
|
||
|
|
||
| def _can_run_wizard(session, parsed_globals): | ||
| region = _resolve_region(session, parsed_globals) | ||
| if not region: | ||
| return True | ||
| return _region_partition(region) == COMMERCIAL_PARTITION | ||
|
|
||
|
|
||
| def maybe_prompt_agent_toolkit(session, parsed_globals): | ||
| try: | ||
| if not _is_eligible(): | ||
| return | ||
| # Outside the commercial partition the wizard's region is unreachable, | ||
| # so print a tip instead of prompting and routing the user into a | ||
| # cross-partition call that would fail. | ||
| if not _can_run_wizard(session, parsed_globals): | ||
| uni_print(HINT_TEXT) | ||
| return | ||
| choice = yes_no_never_choice(PROMPT_TEXT) | ||
| if choice == 'never': | ||
| _dismiss_forever() | ||
| run_wizard = choice == 'yes' | ||
| except Exception as e: | ||
| LOG.debug('Agent toolkit hint failed: %s', e, exc_info=True) | ||
| return | ||
|
|
||
| if run_wizard: | ||
| command = ConfigureAgentToolkitCommand(session) | ||
| command([], parsed_globals) | ||
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
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
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
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.