Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ select = [
"G", # logging format
"I", # isort
"LOG", # logging
"UP", # pyupgrade
]

[tool.ruff.lint.per-file-ignores]
Expand Down
9 changes: 4 additions & 5 deletions scripts/bump-version.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import time
from datetime import datetime
from pathlib import Path
from typing import Optional, Tuple

import requests

Expand All @@ -21,7 +20,7 @@ def get_current_version() -> str:
return match.group(1)


def get_sdk_dependency_version() -> Optional[str]:
def get_sdk_dependency_version() -> str | None:
"""Get current SDK dependency version."""
content = Path("pyproject.toml").read_text()
match = re.search(r'bedrock-agentcore>=([^"]+)', content)
Expand Down Expand Up @@ -60,7 +59,7 @@ def update_sdk_dependency(new_sdk_version: str):
print(f"✓ Updated SDK dependency to >={new_sdk_version}")


def parse_version(version: str) -> Tuple[int, int, int, Optional[str]]:
def parse_version(version: str) -> tuple[int, int, int, str | None]:
"""Parse semantic version string."""
match = re.match(r"(\d+)\.(\d+)\.(\d+)(?:-(.+))?", version)
if not match:
Expand Down Expand Up @@ -122,7 +121,7 @@ def update_all_versions(old_version: str, new_version: str):
print(f"✓ Updated {init_file}")


def get_git_log(since_tag: Optional[str] = None) -> str:
def get_git_log(since_tag: str | None = None) -> str:
"""Get git commit messages since last tag."""
cmd = ["git", "log", "--pretty=format:- %s (%h)"]
if since_tag:
Expand Down Expand Up @@ -220,7 +219,7 @@ def main():

print("\nNext steps:")
print("1. Review changes: git diff")
print("2. Commit: git add -A && git commit -m 'chore: bump version to {}'".format(new))
print(f"2. Commit: git add -A && git commit -m 'chore: bump version to {new}'")
print("3. Create PR or push to trigger release workflow")

except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion scripts/prepare-release.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

print("Preparing pyproject.toml for release...")

with open("pyproject.toml", "r") as f:
with open("pyproject.toml") as f:
content = f.read()

# Remove [tool.uv.sources] section
Expand Down
3 changes: 1 addition & 2 deletions scripts/validate-release.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import sys
import zipfile
from pathlib import Path
from typing import List, Tuple


class Colors:
Expand Down Expand Up @@ -37,7 +36,7 @@ def print_status(message: str, status: str = "info"):
print(f" {message}")


def run_command(cmd: List[str], capture=True) -> Tuple[int, str, str]:
def run_command(cmd: list[str], capture=True) -> tuple[int, str, str]:
"""Run a command and return exit code, stdout, and stderr."""
result = subprocess.run(cmd, capture_output=capture, text=True)
return result.returncode, result.stdout, result.stderr
Expand Down
3 changes: 1 addition & 2 deletions src/bedrock_agentcore_starter_toolkit/cli/cli_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import re
import time
from typing import Optional

from prompt_toolkit.application import Application
from prompt_toolkit.filters import Condition
Expand Down Expand Up @@ -433,7 +432,7 @@ def sandwich_text_ui(style: str, text: str) -> None:
_pause_and_new_line_on_finish()


def show_invalid_aws_creds(ok: bool, msg: Optional[str], optional_header: Optional[str] = None) -> bool:
def show_invalid_aws_creds(ok: bool, msg: str | None, optional_header: str | None = None) -> bool:
"""Standard UI messaging for AWS credential validation.

Returns True if creds are valid, False otherwise.
Expand Down
6 changes: 3 additions & 3 deletions src/bedrock_agentcore_starter_toolkit/cli/common.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Common utilities for BedrockAgentCore CLI."""

import functools
from typing import NoReturn, Optional
from typing import NoReturn

import typer
from prompt_toolkit import prompt
Expand Down Expand Up @@ -32,7 +32,7 @@ def assert_valid_aws_creds_or_exit(failure_message=None):
raise typer.Exit(code=1)


def _handle_error(message: str, exception: Optional[Exception] = None) -> NoReturn:
def _handle_error(message: str, exception: Exception | None = None) -> NoReturn:
"""Handle errors with consistent formatting and exit."""
console.print(f"[red]❌ {message}[/red]")
if exception:
Expand All @@ -51,7 +51,7 @@ def _print_success(message: str) -> None:
console.print(f"[green]✓[/green] {message}")


def _prompt_with_default(question: str, default_value: Optional[str] = "") -> str:
def _prompt_with_default(question: str, default_value: str | None = "") -> str:
"""Prompt user with AWS CLI style [default] format and empty input field."""
prompt_text = question
if default_value:
Expand Down
29 changes: 14 additions & 15 deletions src/bedrock_agentcore_starter_toolkit/cli/create/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import re
from contextlib import contextmanager
from pathlib import Path
from typing import Optional, Tuple

import typer

Expand Down Expand Up @@ -79,13 +78,13 @@
@create_app.callback(invoke_without_command=True)
def create(
ctx: typer.Context,
project_name: Optional[str] = project_name_option,
template: Optional[CreateTemplateDisplay] = template_option,
project_name: str | None = project_name_option,
template: CreateTemplateDisplay | None = template_option,
sdk: CreateSDKProvider = sdk_option,
model_provider: CreateModelProvider = model_provider_option,
provider_api_key: Optional[str] = model_provider_api_key_option,
iac: Optional[CreateIACProvider] = iac_option,
non_interactive_flag: Optional[bool] = non_interactive_flag_opt,
provider_api_key: str | None = model_provider_api_key_option,
iac: CreateIACProvider | None = iac_option,
non_interactive_flag: bool | None = non_interactive_flag_opt,
venv_option: bool = venv_option,
):
"""CLI Implementation for Create Command."""
Expand Down Expand Up @@ -170,11 +169,11 @@ def create(


def _apply_non_interactive_defaults(
template: Optional[CreateTemplateDisplay],
sdk: Optional[CreateSDKProvider],
model_provider: Optional[CreateModelProvider],
iac: Optional[CreateIACProvider],
) -> Tuple[CreateTemplateDisplay, CreateSDKProvider, CreateModelProvider, Optional[CreateIACProvider]]:
template: CreateTemplateDisplay | None,
sdk: CreateSDKProvider | None,
model_provider: CreateModelProvider | None,
iac: CreateIACProvider | None,
) -> tuple[CreateTemplateDisplay, CreateSDKProvider, CreateModelProvider, CreateIACProvider | None]:
"""Applies defaults for non-interactive mode.
Assumes non-interactive mode is already active.
Expand Down Expand Up @@ -214,9 +213,9 @@ def _apply_non_interactive_defaults(
def _handle_basic_runtime_flow(
sdk: CreateSDKProvider,
model_provider: CreateModelProvider,
provider_api_key: Optional[str],
provider_api_key: str | None,
non_interactive_flag: bool,
) -> Tuple[CreateSDKProvider, CreateModelProvider, Optional[str], bool]:
) -> tuple[CreateSDKProvider, CreateModelProvider, str | None, bool]:
"""Handles prompt logic for Runtime-only mode."""
if not sdk:
sdk = prompt_sdk_provider(is_direct_code_deploy=True)
Expand Down Expand Up @@ -259,9 +258,9 @@ def _handle_basic_runtime_flow(
def _handle_monorepo_flow(
sdk: CreateSDKProvider,
model_provider: CreateModelProvider,
iac: Optional[CreateIACProvider],
iac: CreateIACProvider | None,
non_interactive_flag: bool,
) -> Tuple[CreateSDKProvider, CreateModelProvider, Optional[CreateIACProvider], Optional[BedrockAgentCoreAgentSchema]]:
) -> tuple[CreateSDKProvider, CreateModelProvider, CreateIACProvider | None, BedrockAgentCoreAgentSchema | None]:
"""Handles prompt logic for Monorepo mode."""
agent_config = None
configure_yaml = Path.cwd() / ".bedrock_agentcore.yaml"
Expand Down
67 changes: 31 additions & 36 deletions src/bedrock_agentcore_starter_toolkit/cli/evaluation/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import json
import logging
from pathlib import Path
from typing import List, Optional

import typer
from botocore.exceptions import ClientError
Expand Down Expand Up @@ -38,7 +37,7 @@
evaluation_app.add_typer(online_app, name="online")


def _get_agent_config_from_file(agent_name: Optional[str] = None) -> Optional[dict]:
def _get_agent_config_from_file(agent_name: str | None = None) -> dict | None:
"""Get agent configuration from .bedrock_agentcore.yaml file.

Args:
Expand Down Expand Up @@ -76,25 +75,25 @@ def _get_agent_config_from_file(agent_name: Optional[str] = None) -> Optional[di

@evaluation_app.command("run")
def run_evaluation(
agent: Optional[str] = typer.Option(
agent: str | None = typer.Option(
None,
"--agent",
"-a",
help="Agent name (use 'agentcore configure list' to see available agents)",
),
session_id: Optional[str] = typer.Option(None, "--session-id", "-s", help="Override session ID from config"),
agent_id: Optional[str] = typer.Option(None, "--agent-id", help="Override agent ID from config"),
trace_id: Optional[str] = typer.Option(
session_id: str | None = typer.Option(None, "--session-id", "-s", help="Override session ID from config"),
agent_id: str | None = typer.Option(None, "--agent-id", help="Override agent ID from config"),
trace_id: str | None = typer.Option(
None,
"--trace-id",
"-t",
help="Evaluate only this trace (includes spans from all previous traces for context)",
),
evaluators: List[str] = typer.Option( # noqa: B008
evaluators: list[str] = typer.Option( # noqa: B008
[], "--evaluator", "-e", help="Evaluator(s) to use (can specify multiple times)"
),
days: int = typer.Option(7, "--days", "-d", help="Number of days to look back for session data (default: 7)"),
output: Optional[str] = typer.Option(None, "--output", "-o", help="Save results to JSON file"),
output: str | None = typer.Option(None, "--output", "-o", help="Save results to JSON file"),
):
"""Run evaluation on a session.

Expand Down Expand Up @@ -262,7 +261,7 @@ def get_evaluator(
evaluator_id: str = typer.Option(
..., "--evaluator-id", help="Evaluator ID (e.g., Builtin.Helpfulness or custom-id)"
),
output: Optional[str] = typer.Option(None, "--output", "-o", help="Save to JSON file"),
output: str | None = typer.Option(None, "--output", "-o", help="Save to JSON file"),
):
"""Get detailed information about an evaluator.

Expand Down Expand Up @@ -354,10 +353,10 @@ def _interactive_create_evaluator(client: EvaluationControlPlaneClient) -> tuple

@evaluator_app.command("create")
def create_evaluator(
name: Optional[str] = typer.Option(None, "--name", help="Evaluator name"),
config: Optional[str] = typer.Option(None, "--config", help="Path to evaluator config JSON file or inline JSON"),
level: Optional[str] = typer.Option(None, "--level", help="Evaluation level (SESSION, TRACE, TOOL_CALL)"),
description: Optional[str] = typer.Option(None, "--description", help="Evaluator description"),
name: str | None = typer.Option(None, "--name", help="Evaluator name"),
config: str | None = typer.Option(None, "--config", help="Path to evaluator config JSON file or inline JSON"),
level: str | None = typer.Option(None, "--level", help="Evaluation level (SESSION, TRACE, TOOL_CALL)"),
description: str | None = typer.Option(None, "--description", help="Evaluator description"),
):
r"""Create a custom evaluator.

Expand Down Expand Up @@ -435,8 +434,8 @@ def create_evaluator(
@evaluator_app.command("update")
def update_evaluator(
evaluator_id: str = typer.Option(..., "--evaluator-id", help="Evaluator ID to update"),
description: Optional[str] = typer.Option(None, "--description", help="New description"),
config: Optional[str] = typer.Option(None, "--config", help="Path to new config JSON file"),
description: str | None = typer.Option(None, "--description", help="New description"),
config: str | None = typer.Option(None, "--config", help="Path to new config JSON file"),
):
r"""Update a custom evaluator.

Expand Down Expand Up @@ -531,23 +530,21 @@ def delete_evaluator(

@online_app.command("create")
def create_online_config(
agent_id: Optional[str] = typer.Option(None, "--agent-id", help="Agent ID (uses config file if not provided)"),
config_name: Optional[str] = typer.Option(
None, "--name", "-n", help="Name for the online evaluation configuration"
),
agent: Optional[str] = typer.Option(None, "--agent", "-a", help="Agent name from config file"),
agent_id: str | None = typer.Option(None, "--agent-id", help="Agent ID (uses config file if not provided)"),
config_name: str | None = typer.Option(None, "--name", "-n", help="Name for the online evaluation configuration"),
agent: str | None = typer.Option(None, "--agent", "-a", help="Agent name from config file"),
endpoint: str = typer.Option("DEFAULT", "--endpoint", help="Agent endpoint (DEFAULT, DRAFT, or alias ARN)"),
sampling_rate: float = typer.Option(1.0, "--sampling-rate", "-s", help="Sampling rate percentage (0-100)"),
evaluators: List[str] = typer.Option( # noqa: B008
evaluators: list[str] = typer.Option( # noqa: B008
[], "--evaluator", "-e", help="Evaluator ID(s) to use (can specify multiple times)"
),
description: Optional[str] = typer.Option(None, "--description", "-d", help="Config description"),
execution_role: Optional[str] = typer.Option(
description: str | None = typer.Option(None, "--description", "-d", help="Config description"),
execution_role: str | None = typer.Option(
None, "--execution-role", help="IAM role ARN (auto-creates if not provided)"
),
no_auto_create_role: bool = typer.Option(False, "--no-auto-create-role", help="Disable automatic role creation"),
disabled: bool = typer.Option(False, "--disabled", help="Create config in disabled state"),
output: Optional[str] = typer.Option(None, "--output", "-o", help="Save config details to JSON file"),
output: str | None = typer.Option(None, "--output", "-o", help="Save config details to JSON file"),
):
r"""Create online evaluation configuration for continuous agent evaluation.

Expand Down Expand Up @@ -653,7 +650,7 @@ def create_online_config(
@online_app.command("get")
def get_online_config(
config_id: str = typer.Option(..., "--config-id", help="Online evaluation config ID"),
output: Optional[str] = typer.Option(None, "--output", "-o", help="Save config details to JSON file"),
output: str | None = typer.Option(None, "--output", "-o", help="Save config details to JSON file"),
):
"""Get online evaluation configuration details.

Expand Down Expand Up @@ -713,10 +710,10 @@ def get_online_config(

@online_app.command("list")
def list_online_configs(
agent_id: Optional[str] = typer.Option(None, "--agent-id", help="Filter by agent ID"),
agent: Optional[str] = typer.Option(None, "--agent", "-a", help="Filter by agent name from config file"),
agent_id: str | None = typer.Option(None, "--agent-id", help="Filter by agent ID"),
agent: str | None = typer.Option(None, "--agent", "-a", help="Filter by agent name from config file"),
max_results: int = typer.Option(50, "--max-results", help="Maximum number of configs to return"),
output: Optional[str] = typer.Option(None, "--output", "-o", help="Save configs list to JSON file"),
output: str | None = typer.Option(None, "--output", "-o", help="Save configs list to JSON file"),
):
"""List online evaluation configurations.

Expand Down Expand Up @@ -795,13 +792,13 @@ def list_online_configs(
@online_app.command("update")
def update_online_config(
config_id: str = typer.Option(..., "--config-id", help="Online evaluation config ID to update"),
status: Optional[str] = typer.Option(None, "--status", help="New status (ENABLED or DISABLED)"),
sampling_rate: Optional[float] = typer.Option(None, "--sampling-rate", "-s", help="New sampling rate (0-100)"),
evaluators: Optional[List[str]] = typer.Option( # noqa: B008
status: str | None = typer.Option(None, "--status", help="New status (ENABLED or DISABLED)"),
sampling_rate: float | None = typer.Option(None, "--sampling-rate", "-s", help="New sampling rate (0-100)"),
evaluators: list[str] | None = typer.Option( # noqa: B008
None, "--evaluator", "-e", help="New evaluator list (replaces existing, can specify multiple)"
),
description: Optional[str] = typer.Option(None, "--description", "-d", help="New description"),
output: Optional[str] = typer.Option(None, "--output", "-o", help="Save updated config to JSON file"),
description: str | None = typer.Option(None, "--description", "-d", help="New description"),
output: str | None = typer.Option(None, "--output", "-o", help="Save updated config to JSON file"),
):
r"""Update online evaluation configuration.

Expand Down Expand Up @@ -876,9 +873,7 @@ def update_online_config(
def delete_online_config(
config_id: str = typer.Option(..., "--config-id", help="Online evaluation config ID to delete"),
force: bool = typer.Option(False, "--force", "-f", help="Skip all confirmation prompts"),
delete_role: Optional[bool] = typer.Option(
None, "--delete-role/--no-delete-role", help="Delete IAM execution role"
),
delete_role: bool | None = typer.Option(None, "--delete-role/--no-delete-role", help="Delete IAM execution role"),
):
"""Delete online evaluation configuration.

Expand Down
Loading