agentcore-cli 0.31.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agentcore/__init__.py +1 -0
- agentcore/agent_inspector/NOTICE +9 -0
- agentcore/agent_inspector/favicon.svg +60 -0
- agentcore/agent_inspector/index.css +1 -0
- agentcore/agent_inspector/index.html +14 -0
- agentcore/agent_inspector/index.js +289 -0
- agentcore/assets/AGENTS.md +60 -0
- agentcore/assets/README.md +108 -0
- agentcore/assets/agents/AGENTS.md +218 -0
- agentcore/assets/cdk/.prettierrc +8 -0
- agentcore/assets/cdk/README.md +26 -0
- agentcore/assets/cdk/bin/cdk.ts +216 -0
- agentcore/assets/cdk/cdk.json +88 -0
- agentcore/assets/cdk/gitignore.template +9 -0
- agentcore/assets/cdk/jest.config.js +9 -0
- agentcore/assets/cdk/lib/cdk-stack.ts +291 -0
- agentcore/assets/cdk/npmignore.template +6 -0
- agentcore/assets/cdk/package.json +30 -0
- agentcore/assets/cdk/test/cdk.test.ts +31 -0
- agentcore/assets/cdk/tsconfig.json +28 -0
- agentcore/assets/container/python/Dockerfile +47 -0
- agentcore/assets/container/python/dockerignore.template +27 -0
- agentcore/assets/container/typescript/Dockerfile +25 -0
- agentcore/assets/container/typescript/dockerignore.template +24 -0
- agentcore/assets/datasets/predefined-v1.jsonl +3 -0
- agentcore/assets/datasets/simulated-v1.jsonl +3 -0
- agentcore/assets/evaluators/autoevals-lambda/execution-role-policy.json +15 -0
- agentcore/assets/evaluators/autoevals-lambda/lambda_function.py +37 -0
- agentcore/assets/evaluators/autoevals-lambda/pyproject.toml +22 -0
- agentcore/assets/evaluators/deepeval-lambda/execution-role-policy.json +15 -0
- agentcore/assets/evaluators/deepeval-lambda/lambda_function.py +29 -0
- agentcore/assets/evaluators/deepeval-lambda/pyproject.toml +19 -0
- agentcore/assets/evaluators/python-lambda/execution-role-policy.json +10 -0
- agentcore/assets/evaluators/python-lambda/lambda_function.py +19 -0
- agentcore/assets/evaluators/python-lambda/pyproject.toml +15 -0
- agentcore/assets/harness/invoke.py.template +74 -0
- agentcore/assets/mcp/python/README.md +27 -0
- agentcore/assets/mcp/python/pyproject.toml +22 -0
- agentcore/assets/mcp/python/server.py +117 -0
- agentcore/assets/mcp/python-lambda/README.md +22 -0
- agentcore/assets/mcp/python-lambda/handler.py +144 -0
- agentcore/assets/mcp/python-lambda/pyproject.toml +15 -0
- agentcore/assets/python/a2a/googleadk/base/README.md +22 -0
- agentcore/assets/python/a2a/googleadk/base/gitignore.template +41 -0
- agentcore/assets/python/a2a/googleadk/base/main.py +124 -0
- agentcore/assets/python/a2a/googleadk/base/model/__init__.py +1 -0
- agentcore/assets/python/a2a/googleadk/base/model/load.py +41 -0
- agentcore/assets/python/a2a/googleadk/base/pyproject.toml +22 -0
- agentcore/assets/python/a2a/langchain_langgraph/base/README.md +22 -0
- agentcore/assets/python/a2a/langchain_langgraph/base/gitignore.template +41 -0
- agentcore/assets/python/a2a/langchain_langgraph/base/main.py +144 -0
- agentcore/assets/python/a2a/langchain_langgraph/base/model/__init__.py +1 -0
- agentcore/assets/python/a2a/langchain_langgraph/base/model/load.py +123 -0
- agentcore/assets/python/a2a/langchain_langgraph/base/pyproject.toml +26 -0
- agentcore/assets/python/a2a/strands/base/README.md +22 -0
- agentcore/assets/python/a2a/strands/base/gitignore.template +41 -0
- agentcore/assets/python/a2a/strands/base/main.py +113 -0
- agentcore/assets/python/a2a/strands/base/model/__init__.py +1 -0
- agentcore/assets/python/a2a/strands/base/model/load.py +123 -0
- agentcore/assets/python/a2a/strands/base/pyproject.toml +23 -0
- agentcore/assets/python/a2a/strands/capabilities/memory/__init__.py +1 -0
- agentcore/assets/python/a2a/strands/capabilities/memory/session.py +46 -0
- agentcore/assets/python/agui/googleadk/base/README.md +30 -0
- agentcore/assets/python/agui/googleadk/base/gitignore.template +41 -0
- agentcore/assets/python/agui/googleadk/base/main.py +91 -0
- agentcore/assets/python/agui/googleadk/base/model/__init__.py +1 -0
- agentcore/assets/python/agui/googleadk/base/model/load.py +41 -0
- agentcore/assets/python/agui/googleadk/base/pyproject.toml +25 -0
- agentcore/assets/python/agui/langchain_langgraph/base/README.md +22 -0
- agentcore/assets/python/agui/langchain_langgraph/base/gitignore.template +41 -0
- agentcore/assets/python/agui/langchain_langgraph/base/main.py +130 -0
- agentcore/assets/python/agui/langchain_langgraph/base/model/__init__.py +1 -0
- agentcore/assets/python/agui/langchain_langgraph/base/model/load.py +123 -0
- agentcore/assets/python/agui/langchain_langgraph/base/pyproject.toml +31 -0
- agentcore/assets/python/agui/strands/base/README.md +22 -0
- agentcore/assets/python/agui/strands/base/gitignore.template +41 -0
- agentcore/assets/python/agui/strands/base/main.py +105 -0
- agentcore/assets/python/agui/strands/base/model/__init__.py +1 -0
- agentcore/assets/python/agui/strands/base/model/load.py +123 -0
- agentcore/assets/python/agui/strands/base/pyproject.toml +27 -0
- agentcore/assets/python/agui/strands/capabilities/memory/__init__.py +1 -0
- agentcore/assets/python/agui/strands/capabilities/memory/session.py +46 -0
- agentcore/assets/python/http/autogen/base/README.md +45 -0
- agentcore/assets/python/http/autogen/base/gitignore.template +41 -0
- agentcore/assets/python/http/autogen/base/main.py +145 -0
- agentcore/assets/python/http/autogen/base/mcp_client/__init__.py +1 -0
- agentcore/assets/python/http/autogen/base/mcp_client/client.py +28 -0
- agentcore/assets/python/http/autogen/base/model/__init__.py +1 -0
- agentcore/assets/python/http/autogen/base/model/load.py +136 -0
- agentcore/assets/python/http/autogen/base/pyproject.toml +34 -0
- agentcore/assets/python/http/bma/base/Dockerfile +41 -0
- agentcore/assets/python/http/bma/base/README.md +178 -0
- agentcore/assets/python/http/bma/base/client.py +200 -0
- agentcore/assets/python/http/bma/base/lifecycle/server.py +641 -0
- agentcore/assets/python/http/bma/base/otel/collector.yaml +69 -0
- agentcore/assets/python/http/bma/base/plugins/acr-report/.codex-plugin/plugin.json +6 -0
- agentcore/assets/python/http/bma/base/plugins/acr-report/skills/acr-report/SKILL.md +16 -0
- agentcore/assets/python/http/bma/base/policies/bma-acr-policy.json +11 -0
- agentcore/assets/python/http/bma/base/policies/bma-session-policy.json +35 -0
- agentcore/assets/python/http/bma/base/policies/bma-session-trust.json +20 -0
- agentcore/assets/python/http/bma/base/pyproject.toml +21 -0
- agentcore/assets/python/http/googleadk/base/README.md +45 -0
- agentcore/assets/python/http/googleadk/base/gitignore.template +41 -0
- agentcore/assets/python/http/googleadk/base/main.py +207 -0
- agentcore/assets/python/http/googleadk/base/mcp_client/__init__.py +1 -0
- agentcore/assets/python/http/googleadk/base/mcp_client/client.py +75 -0
- agentcore/assets/python/http/googleadk/base/model/__init__.py +1 -0
- agentcore/assets/python/http/googleadk/base/model/load.py +41 -0
- agentcore/assets/python/http/googleadk/base/pyproject.toml +24 -0
- agentcore/assets/python/http/langchain_langgraph/base/README.md +45 -0
- agentcore/assets/python/http/langchain_langgraph/base/gitignore.template +41 -0
- agentcore/assets/python/http/langchain_langgraph/base/main.py +227 -0
- agentcore/assets/python/http/langchain_langgraph/base/mcp_client/__init__.py +1 -0
- agentcore/assets/python/http/langchain_langgraph/base/mcp_client/client.py +79 -0
- agentcore/assets/python/http/langchain_langgraph/base/model/__init__.py +1 -0
- agentcore/assets/python/http/langchain_langgraph/base/model/load.py +123 -0
- agentcore/assets/python/http/langchain_langgraph/base/pyproject.toml +38 -0
- agentcore/assets/python/http/openaiagents/base/README.md +45 -0
- agentcore/assets/python/http/openaiagents/base/gitignore.template +41 -0
- agentcore/assets/python/http/openaiagents/base/main.py +200 -0
- agentcore/assets/python/http/openaiagents/base/mcp_client/__init__.py +1 -0
- agentcore/assets/python/http/openaiagents/base/mcp_client/client.py +74 -0
- agentcore/assets/python/http/openaiagents/base/model/__init__.py +1 -0
- agentcore/assets/python/http/openaiagents/base/model/load.py +37 -0
- agentcore/assets/python/http/openaiagents/base/pyproject.toml +21 -0
- agentcore/assets/python/http/strands/base/README.md +46 -0
- agentcore/assets/python/http/strands/base/gitignore.template +41 -0
- agentcore/assets/python/http/strands/base/main.py +714 -0
- agentcore/assets/python/http/strands/base/mcp_client/__init__.py +1 -0
- agentcore/assets/python/http/strands/base/mcp_client/client.py +116 -0
- agentcore/assets/python/http/strands/base/model/__init__.py +1 -0
- agentcore/assets/python/http/strands/base/model/load.py +239 -0
- agentcore/assets/python/http/strands/base/model/mantle_compat.py +21 -0
- agentcore/assets/python/http/strands/base/pyproject.toml +31 -0
- agentcore/assets/python/http/strands/base/skills/fetcher.py +279 -0
- agentcore/assets/python/http/strands/capabilities/execution-limits/hooks/execution_limits.py +54 -0
- agentcore/assets/python/http/strands/capabilities/memory/__init__.py +1 -0
- agentcore/assets/python/http/strands/capabilities/memory/session.py +47 -0
- agentcore/assets/python/http/strands/capabilities/payments/__init__.py +4 -0
- agentcore/assets/python/http/strands/capabilities/payments/payments.py +142 -0
- agentcore/assets/python/mcp/standalone/base/README.md +36 -0
- agentcore/assets/python/mcp/standalone/base/gitignore.template +41 -0
- agentcore/assets/python/mcp/standalone/base/main.py +83 -0
- agentcore/assets/python/mcp/standalone/base/pyproject.toml +16 -0
- agentcore/assets/typescript/.gitkeep +0 -0
- agentcore/assets/typescript/http/strands/base/README.md +42 -0
- agentcore/assets/typescript/http/strands/base/gitignore.template +22 -0
- agentcore/assets/typescript/http/strands/base/main.ts +149 -0
- agentcore/assets/typescript/http/strands/base/mcp_client/client.ts +11 -0
- agentcore/assets/typescript/http/strands/base/model/load.ts +102 -0
- agentcore/assets/typescript/http/strands/base/package.json +38 -0
- agentcore/assets/typescript/http/strands/base/tsconfig.json +19 -0
- agentcore/assets/typescript/http/strands/capabilities/memory/memory.ts +52 -0
- agentcore/assets/typescript/http/vercelai/base/README.md +42 -0
- agentcore/assets/typescript/http/vercelai/base/gitignore.template +22 -0
- agentcore/assets/typescript/http/vercelai/base/main.ts +70 -0
- agentcore/assets/typescript/http/vercelai/base/model/load.ts +121 -0
- agentcore/assets/typescript/http/vercelai/base/package.json +35 -0
- agentcore/assets/typescript/http/vercelai/base/tsconfig.json +19 -0
- agentcore/aws/__init__.py +263 -0
- agentcore/aws/_aws_errors.py +72 -0
- agentcore/aws/_http.py +176 -0
- agentcore/aws/_util.py +37 -0
- agentcore/aws/account.py +165 -0
- agentcore/aws/agentcore.py +971 -0
- agentcore/aws/agentcore_ab_tests.py +230 -0
- agentcore/aws/agentcore_batch_evaluation.py +227 -0
- agentcore/aws/agentcore_config_bundles.py +220 -0
- agentcore/aws/agentcore_control.py +994 -0
- agentcore/aws/agentcore_datasets.py +222 -0
- agentcore/aws/agentcore_harness.py +330 -0
- agentcore/aws/agentcore_payments.py +430 -0
- agentcore/aws/agentcore_recommendation.py +140 -0
- agentcore/aws/agui_parser.py +131 -0
- agentcore/aws/agui_types.py +342 -0
- agentcore/aws/api_client.py +87 -0
- agentcore/aws/arn.py +18 -0
- agentcore/aws/aws_context.py +23 -0
- agentcore/aws/bedrock.py +44 -0
- agentcore/aws/bedrock_agent.py +129 -0
- agentcore/aws/bedrock_import.py +252 -0
- agentcore/aws/bedrock_import_types.py +111 -0
- agentcore/aws/cloudwatch.py +136 -0
- agentcore/aws/connect_shell.py +266 -0
- agentcore/aws/iam.py +41 -0
- agentcore/aws/partition.py +58 -0
- agentcore/aws/policy_generation.py +116 -0
- agentcore/aws/region.py +54 -0
- agentcore/aws/retry.py +27 -0
- agentcore/aws/shell_framer.py +136 -0
- agentcore/aws/stage_endpoint.py +39 -0
- agentcore/aws/target_region.py +54 -0
- agentcore/aws/transaction_search.py +97 -0
- agentcore/cdk/__init__.py +10 -0
- agentcore/cdk/constants.py +13 -0
- agentcore/cdk/local_cdk_project.py +48 -0
- agentcore/cdk/toolkit.py +706 -0
- agentcore/cli/__init__.py +0 -0
- agentcore/cli/commands/__init__.py +0 -0
- agentcore/cli/commands/_jobs_common.py +39 -0
- agentcore/cli/commands/_run_wizards.py +639 -0
- agentcore/cli/commands/add/__init__.py +37 -0
- agentcore/cli/commands/add/_commander.py +52 -0
- agentcore/cli/commands/add/_common.py +47 -0
- agentcore/cli/commands/add/agent_wizard.py +528 -0
- agentcore/cli/commands/add/auth_options.py +154 -0
- agentcore/cli/commands/add/skill_action.py +105 -0
- agentcore/cli/commands/add/skill_command.py +87 -0
- agentcore/cli/commands/add/tool_action.py +160 -0
- agentcore/cli/commands/add/tool_command.py +117 -0
- agentcore/cli/commands/add/validate.py +333 -0
- agentcore/cli/commands/capacity_provider/__init__.py +86 -0
- agentcore/cli/commands/capacity_provider/action.py +114 -0
- agentcore/cli/commands/capacity_provider/constants.py +22 -0
- agentcore/cli/commands/config.py +91 -0
- agentcore/cli/commands/config_bundle.py +251 -0
- agentcore/cli/commands/create/__init__.py +643 -0
- agentcore/cli/commands/create/action.py +406 -0
- agentcore/cli/commands/create/dependencies.py +91 -0
- agentcore/cli/commands/create/harness_validate.py +82 -0
- agentcore/cli/commands/create/validate.py +195 -0
- agentcore/cli/commands/create/wizard.py +127 -0
- agentcore/cli/commands/dataset.py +119 -0
- agentcore/cli/commands/deploy/__init__.py +31 -0
- agentcore/cli/commands/deploy/_guards.py +25 -0
- agentcore/cli/commands/deploy/actions.py +840 -0
- agentcore/cli/commands/deploy/command.py +349 -0
- agentcore/cli/commands/deploy/progress.py +115 -0
- agentcore/cli/commands/deploy/types.py +68 -0
- agentcore/cli/commands/deploy/utils.py +43 -0
- agentcore/cli/commands/deploy/validate.py +21 -0
- agentcore/cli/commands/dev/__init__.py +5 -0
- agentcore/cli/commands/dev/_deps.py +50 -0
- agentcore/cli/commands/dev/browser_mode.py +270 -0
- agentcore/cli/commands/dev/command.py +450 -0
- agentcore/cli/commands/dev/terminal_mode.py +379 -0
- agentcore/cli/commands/exec/__init__.py +29 -0
- agentcore/cli/commands/exec/action.py +442 -0
- agentcore/cli/commands/exec/command.py +206 -0
- agentcore/cli/commands/exec/types.py +35 -0
- agentcore/cli/commands/export/__init__.py +114 -0
- agentcore/cli/commands/export/constants.py +21 -0
- agentcore/cli/commands/export/fetch_harness_spec.py +234 -0
- agentcore/cli/commands/export/harness_action.py +385 -0
- agentcore/cli/commands/export/harness_mapper.py +868 -0
- agentcore/cli/commands/export/harness_resolver.py +95 -0
- agentcore/cli/commands/export/types.py +90 -0
- agentcore/cli/commands/export/wizard.py +97 -0
- agentcore/cli/commands/feedback/__init__.py +69 -0
- agentcore/cli/commands/feedback/action.py +30 -0
- agentcore/cli/commands/feedback/consent_prompt.py +35 -0
- agentcore/cli/commands/feedback/wizard.py +49 -0
- agentcore/cli/commands/fetch/__init__.py +69 -0
- agentcore/cli/commands/fetch/action.py +62 -0
- agentcore/cli/commands/help.py +65 -0
- agentcore/cli/commands/import_/__init__.py +167 -0
- agentcore/cli/commands/import_/_js.py +72 -0
- agentcore/cli/commands/import_/actions.py +457 -0
- agentcore/cli/commands/import_/constants.py +45 -0
- agentcore/cli/commands/import_/import_evaluator.py +140 -0
- agentcore/cli/commands/import_/import_gateway.py +520 -0
- agentcore/cli/commands/import_/import_memory.py +128 -0
- agentcore/cli/commands/import_/import_online_eval.py +165 -0
- agentcore/cli/commands/import_/import_pipeline.py +145 -0
- agentcore/cli/commands/import_/import_runtime.py +214 -0
- agentcore/cli/commands/import_/import_utils.py +410 -0
- agentcore/cli/commands/import_/phase1_update.py +110 -0
- agentcore/cli/commands/import_/phase2_import.py +206 -0
- agentcore/cli/commands/import_/resource_import.py +228 -0
- agentcore/cli/commands/import_/template_utils.py +148 -0
- agentcore/cli/commands/import_/types.py +150 -0
- agentcore/cli/commands/import_/yaml_parser.py +265 -0
- agentcore/cli/commands/init.py +196 -0
- agentcore/cli/commands/invoke/__init__.py +32 -0
- agentcore/cli/commands/invoke/_deps.py +73 -0
- agentcore/cli/commands/invoke/action.py +840 -0
- agentcore/cli/commands/invoke/command.py +490 -0
- agentcore/cli/commands/invoke/constants.py +40 -0
- agentcore/cli/commands/invoke/guards.py +23 -0
- agentcore/cli/commands/invoke/interactive.py +604 -0
- agentcore/cli/commands/invoke/resolve.py +149 -0
- agentcore/cli/commands/invoke/resolve_prompt.py +60 -0
- agentcore/cli/commands/invoke/types.py +61 -0
- agentcore/cli/commands/invoke/validate.py +33 -0
- agentcore/cli/commands/job_actions.py +239 -0
- agentcore/cli/commands/job_history.py +380 -0
- agentcore/cli/commands/logs/__init__.py +53 -0
- agentcore/cli/commands/logs/action.py +159 -0
- agentcore/cli/commands/logs/filter_pattern.py +17 -0
- agentcore/cli/commands/logs/guards.py +51 -0
- agentcore/cli/commands/logs_evals.py +42 -0
- agentcore/cli/commands/package.py +118 -0
- agentcore/cli/commands/remove/__init__.py +172 -0
- agentcore/cli/commands/remove/skill_command.py +131 -0
- agentcore/cli/commands/remove/tool_command.py +59 -0
- agentcore/cli/commands/run.py +808 -0
- agentcore/cli/commands/run_ingest.py +97 -0
- agentcore/cli/commands/shared/__init__.py +0 -0
- agentcore/cli/commands/shared/arn_utils.py +9 -0
- agentcore/cli/commands/shared/filesystem_utils.py +421 -0
- agentcore/cli/commands/shared/header_utils.py +87 -0
- agentcore/cli/commands/shared/indexed_key_parser.py +76 -0
- agentcore/cli/commands/shared/lifecycle_utils.py +72 -0
- agentcore/cli/commands/shared/region_utils.py +20 -0
- agentcore/cli/commands/shared/vpc_utils.py +99 -0
- agentcore/cli/commands/status/__init__.py +30 -0
- agentcore/cli/commands/status/_guards.py +25 -0
- agentcore/cli/commands/status/action.py +741 -0
- agentcore/cli/commands/status/command.py +321 -0
- agentcore/cli/commands/status/constants.py +36 -0
- agentcore/cli/commands/status/format_knowledge_base.py +111 -0
- agentcore/cli/commands/telemetry.py +79 -0
- agentcore/cli/commands/traces/__init__.py +155 -0
- agentcore/cli/commands/traces/action.py +123 -0
- agentcore/cli/commands/update/__init__.py +63 -0
- agentcore/cli/commands/update/action.py +164 -0
- agentcore/cli/commands/validate.py +165 -0
- agentcore/cli/constants.py +96 -0
- agentcore/cli/errors.py +118 -0
- agentcore/cli/external_requirements/__init__.py +67 -0
- agentcore/cli/external_requirements/checks.py +280 -0
- agentcore/cli/external_requirements/detect.py +55 -0
- agentcore/cli/external_requirements/versions.py +57 -0
- agentcore/cli/groups.py +23 -0
- agentcore/cli/interactive.py +85 -0
- agentcore/cli/main.py +137 -0
- agentcore/cli/naming.py +11 -0
- agentcore/cli/notices.py +42 -0
- agentcore/cli/project.py +34 -0
- agentcore/cli/run_command.py +27 -0
- agentcore/cli/tree.py +135 -0
- agentcore/cli/update_notifier.py +123 -0
- agentcore/cli/variadic.py +50 -0
- agentcore/cloudformation/__init__.py +84 -0
- agentcore/cloudformation/bootstrap.py +64 -0
- agentcore/cloudformation/logical_ids.py +37 -0
- agentcore/cloudformation/outputs.py +566 -0
- agentcore/cloudformation/stack_discovery.py +75 -0
- agentcore/cloudformation/stack_events.py +107 -0
- agentcore/cloudformation/stack_status.py +98 -0
- agentcore/cloudformation/types.py +44 -0
- agentcore/lib/__init__.py +68 -0
- agentcore/lib/constants.py +77 -0
- agentcore/lib/dependency_management/__init__.py +23 -0
- agentcore/lib/dependency_management/messages.py +92 -0
- agentcore/lib/dependency_management/plan.py +98 -0
- agentcore/lib/dependency_management/semver.py +137 -0
- agentcore/lib/dependency_management/sync.py +139 -0
- agentcore/lib/dependency_management/types.py +56 -0
- agentcore/lib/errors/__init__.py +5 -0
- agentcore/lib/errors/types.py +352 -0
- agentcore/lib/errors/validation.py +121 -0
- agentcore/lib/packaging/__init__.py +81 -0
- agentcore/lib/packaging/build_args.py +23 -0
- agentcore/lib/packaging/build_context.py +26 -0
- agentcore/lib/packaging/build_context_dockerignore.py +45 -0
- agentcore/lib/packaging/container.py +95 -0
- agentcore/lib/packaging/helpers.py +289 -0
- agentcore/lib/packaging/node.py +153 -0
- agentcore/lib/packaging/python.py +135 -0
- agentcore/lib/packaging/types.py +69 -0
- agentcore/lib/packaging/uv.py +45 -0
- agentcore/lib/result.py +104 -0
- agentcore/lib/schemas/__init__.py +1 -0
- agentcore/lib/schemas/io/__init__.py +27 -0
- agentcore/lib/schemas/io/config_io.py +458 -0
- agentcore/lib/schemas/io/global_config.py +239 -0
- agentcore/lib/schemas/io/path_resolver.py +132 -0
- agentcore/lib/secrets/__init__.py +18 -0
- agentcore/lib/secrets/cipher.py +70 -0
- agentcore/lib/secrets/key_provider.py +163 -0
- agentcore/lib/secrets/sensitive_keys.py +55 -0
- agentcore/lib/time_constants.py +4 -0
- agentcore/lib/utils/__init__.py +47 -0
- agentcore/lib/utils/aws_account.py +15 -0
- agentcore/lib/utils/credentials.py +68 -0
- agentcore/lib/utils/dotenv.py +32 -0
- agentcore/lib/utils/env.py +105 -0
- agentcore/lib/utils/json_format.py +29 -0
- agentcore/lib/utils/json_rpc.py +22 -0
- agentcore/lib/utils/platform.py +33 -0
- agentcore/lib/utils/polling.py +86 -0
- agentcore/lib/utils/subprocess.py +135 -0
- agentcore/lib/utils/time_parser.py +48 -0
- agentcore/lib/utils/validation.py +106 -0
- agentcore/logging/__init__.py +10 -0
- agentcore/logging/_common.py +77 -0
- agentcore/logging/cdk_io_host.py +36 -0
- agentcore/logging/create_logger.py +107 -0
- agentcore/logging/dev_logger.py +63 -0
- agentcore/logging/exec_logger.py +159 -0
- agentcore/logging/invoke_logger.py +154 -0
- agentcore/logging/remove_logger.py +95 -0
- agentcore/operations/__init__.py +0 -0
- agentcore/operations/agent/__init__.py +0 -0
- agentcore/operations/agent/config_bundle_defaults.py +31 -0
- agentcore/operations/agent/generate/__init__.py +28 -0
- agentcore/operations/agent/generate/schema_mapper.py +319 -0
- agentcore/operations/agent/generate/types.py +172 -0
- agentcore/operations/agent/generate/write_agent_to_project.py +67 -0
- agentcore/operations/agent/import_/__init__.py +31 -0
- agentcore/operations/agent/import_/base_translator.py +449 -0
- agentcore/operations/agent/import_/constants.py +23 -0
- agentcore/operations/agent/import_/execute.py +127 -0
- agentcore/operations/agent/import_/langgraph_translator.py +294 -0
- agentcore/operations/agent/import_/pyproject_generator.py +73 -0
- agentcore/operations/agent/import_/strands_translator.py +289 -0
- agentcore/operations/config_bundle/__init__.py +1 -0
- agentcore/operations/config_bundle/bundle_name_variants.py +9 -0
- agentcore/operations/config_bundle/diff_versions.py +52 -0
- agentcore/operations/config_bundle/resolve_bundle.py +65 -0
- agentcore/operations/connectors/__init__.py +3 -0
- agentcore/operations/connectors/translators.py +63 -0
- agentcore/operations/dataset/__init__.py +21 -0
- agentcore/operations/dataset/delete.py +7 -0
- agentcore/operations/dataset/publish.py +16 -0
- agentcore/operations/dataset/pull.py +21 -0
- agentcore/operations/dataset/push.py +201 -0
- agentcore/operations/dataset/resolve_dataset.py +65 -0
- agentcore/operations/dataset/status.py +18 -0
- agentcore/operations/dataset/wait.py +25 -0
- agentcore/operations/deploy/__init__.py +152 -0
- agentcore/operations/deploy/backfill_vpc_id.py +90 -0
- agentcore/operations/deploy/change_detection.py +84 -0
- agentcore/operations/deploy/constants.py +58 -0
- agentcore/operations/deploy/dependency_sync.py +105 -0
- agentcore/operations/deploy/ensure_target.py +30 -0
- agentcore/operations/deploy/gateway_status.py +44 -0
- agentcore/operations/deploy/managed_memory_notice.py +36 -0
- agentcore/operations/deploy/payment_connector_authorization.py +106 -0
- agentcore/operations/deploy/post_deploy_datasets.py +96 -0
- agentcore/operations/deploy/post_deploy_knowledge_bases.py +104 -0
- agentcore/operations/deploy/post_deploy_observability.py +28 -0
- agentcore/operations/deploy/post_deploy_online_evals.py +60 -0
- agentcore/operations/deploy/pre_deploy_identity.py +505 -0
- agentcore/operations/deploy/preflight.py +385 -0
- agentcore/operations/deploy/region_override.py +45 -0
- agentcore/operations/deploy/teardown.py +153 -0
- agentcore/operations/dev/__init__.py +61 -0
- agentcore/operations/dev/_http.py +79 -0
- agentcore/operations/dev/_server.py +165 -0
- agentcore/operations/dev/codezip_dev_server.py +151 -0
- agentcore/operations/dev/config.py +128 -0
- agentcore/operations/dev/constants.py +9 -0
- agentcore/operations/dev/container_dev_server.py +237 -0
- agentcore/operations/dev/container_runtime.py +37 -0
- agentcore/operations/dev/dev_server.py +244 -0
- agentcore/operations/dev/gateway_env.py +25 -0
- agentcore/operations/dev/invoke.py +214 -0
- agentcore/operations/dev/invoke_a2a.py +204 -0
- agentcore/operations/dev/invoke_agui.py +88 -0
- agentcore/operations/dev/invoke_mcp.py +145 -0
- agentcore/operations/dev/invoke_types.py +30 -0
- agentcore/operations/dev/load_dev_env.py +26 -0
- agentcore/operations/dev/memory_env.py +19 -0
- agentcore/operations/dev/otel/__init__.py +5 -0
- agentcore/operations/dev/otel/collector.py +234 -0
- agentcore/operations/dev/otel/transforms.py +331 -0
- agentcore/operations/dev/payment_env.py +50 -0
- agentcore/operations/dev/server.py +28 -0
- agentcore/operations/dev/sse_transform.py +30 -0
- agentcore/operations/dev/utils.py +152 -0
- agentcore/operations/dev/web_ui/__init__.py +31 -0
- agentcore/operations/dev/web_ui/constants.py +25 -0
- agentcore/operations/dev/web_ui/handlers/__init__.py +36 -0
- agentcore/operations/dev/web_ui/handlers/_common.py +36 -0
- agentcore/operations/dev/web_ui/handlers/_deployed.py +37 -0
- agentcore/operations/dev/web_ui/handlers/a2a_proxy.py +37 -0
- agentcore/operations/dev/web_ui/handlers/cloudwatch_traces.py +71 -0
- agentcore/operations/dev/web_ui/handlers/harness_invocation.py +89 -0
- agentcore/operations/dev/web_ui/handlers/harness_utils.py +95 -0
- agentcore/operations/dev/web_ui/handlers/invocations.py +327 -0
- agentcore/operations/dev/web_ui/handlers/mcp_proxy.py +119 -0
- agentcore/operations/dev/web_ui/handlers/memory.py +84 -0
- agentcore/operations/dev/web_ui/handlers/resources.py +351 -0
- agentcore/operations/dev/web_ui/handlers/start.py +182 -0
- agentcore/operations/dev/web_ui/handlers/status.py +25 -0
- agentcore/operations/dev/web_ui/handlers/traces.py +50 -0
- agentcore/operations/dev/web_ui/run_web_ui.py +60 -0
- agentcore/operations/dev/web_ui/web_server.py +297 -0
- agentcore/operations/eval/__init__.py +8 -0
- agentcore/operations/eval/list_eval_runs.py +18 -0
- agentcore/operations/eval/logs_eval.py +119 -0
- agentcore/operations/eval/pause_resume.py +90 -0
- agentcore/operations/eval/run_eval.py +354 -0
- agentcore/operations/eval/shared/__init__.py +0 -0
- agentcore/operations/eval/shared/dataset_loader.py +68 -0
- agentcore/operations/eval/shared/dataset_session_provider.py +122 -0
- agentcore/operations/eval/shared/evaluator_runner.py +89 -0
- agentcore/operations/eval/shared/scenario_executor.py +71 -0
- agentcore/operations/eval/shared/span_collector.py +255 -0
- agentcore/operations/eval/storage.py +67 -0
- agentcore/operations/feedback/__init__.py +21 -0
- agentcore/operations/feedback/aperture_client.py +98 -0
- agentcore/operations/feedback/build_payload.py +97 -0
- agentcore/operations/feedback/constants.py +26 -0
- agentcore/operations/feedback/submit_feedback.py +150 -0
- agentcore/operations/fetch_access/__init__.py +36 -0
- agentcore/operations/fetch_access/_target.py +17 -0
- agentcore/operations/fetch_access/fetch_gateway_token.py +75 -0
- agentcore/operations/fetch_access/fetch_harness_token.py +72 -0
- agentcore/operations/fetch_access/fetch_runtime_token.py +76 -0
- agentcore/operations/fetch_access/list_agents.py +18 -0
- agentcore/operations/fetch_access/list_gateways.py +26 -0
- agentcore/operations/fetch_access/list_harnesses.py +23 -0
- agentcore/operations/fetch_access/oauth_token.py +162 -0
- agentcore/operations/fetch_access/types.py +34 -0
- agentcore/operations/harness/__init__.py +1 -0
- agentcore/operations/harness/orphan.py +84 -0
- agentcore/operations/harness/skill_utils.py +56 -0
- agentcore/operations/identity/__init__.py +33 -0
- agentcore/operations/identity/api_key_credential_provider.py +68 -0
- agentcore/operations/identity/oauth2_credential_provider.py +95 -0
- agentcore/operations/ingest/__init__.py +184 -0
- agentcore/operations/init/__init__.py +3 -0
- agentcore/operations/init/files.py +59 -0
- agentcore/operations/insights/__init__.py +21 -0
- agentcore/operations/insights/insights_storage.py +67 -0
- agentcore/operations/insights/run_insights.py +148 -0
- agentcore/operations/invoke/__init__.py +5 -0
- agentcore/operations/invoke/resolve_agent_context.py +85 -0
- agentcore/operations/jobs/__init__.py +38 -0
- agentcore/operations/jobs/ab_test/__init__.py +0 -0
- agentcore/operations/jobs/ab_test/build_options.py +126 -0
- agentcore/operations/jobs/ab_test/format.py +121 -0
- agentcore/operations/jobs/ab_test/handler.py +412 -0
- agentcore/operations/jobs/ab_test/promote.py +142 -0
- agentcore/operations/jobs/ab_test/resolve.py +221 -0
- agentcore/operations/jobs/batch_evaluation/__init__.py +0 -0
- agentcore/operations/jobs/batch_evaluation/build_source.py +68 -0
- agentcore/operations/jobs/batch_evaluation/dataset_phase1.py +95 -0
- agentcore/operations/jobs/batch_evaluation/format.py +58 -0
- agentcore/operations/jobs/batch_evaluation/handler.py +203 -0
- agentcore/operations/jobs/insights/__init__.py +0 -0
- agentcore/operations/jobs/insights/format.py +65 -0
- agentcore/operations/jobs/insights/handler.py +178 -0
- agentcore/operations/jobs/recommendation/__init__.py +0 -0
- agentcore/operations/jobs/recommendation/apply_to_bundle.py +76 -0
- agentcore/operations/jobs/recommendation/build_config.py +271 -0
- agentcore/operations/jobs/recommendation/fetch_session_spans.py +93 -0
- agentcore/operations/jobs/recommendation/format.py +77 -0
- agentcore/operations/jobs/recommendation/handler.py +331 -0
- agentcore/operations/jobs/shared/__init__.py +0 -0
- agentcore/operations/jobs/shared/constants.py +85 -0
- agentcore/operations/jobs/shared/engine.py +187 -0
- agentcore/operations/jobs/shared/format.py +104 -0
- agentcore/operations/jobs/shared/region.py +34 -0
- agentcore/operations/jobs/shared/resolve_agent_state.py +30 -0
- agentcore/operations/jobs/shared/storage.py +117 -0
- agentcore/operations/jobs/shared/wait.py +30 -0
- agentcore/operations/knowledge_base/__init__.py +33 -0
- agentcore/operations/knowledge_base/connector_config.py +105 -0
- agentcore/operations/knowledge_base/hydrate_data_sources.py +59 -0
- agentcore/operations/mcp/__init__.py +4 -0
- agentcore/operations/memory/__init__.py +13 -0
- agentcore/operations/memory/_records.py +72 -0
- agentcore/operations/memory/list_memory_records.py +45 -0
- agentcore/operations/memory/retrieve_memory_records.py +52 -0
- agentcore/operations/node/__init__.py +15 -0
- agentcore/operations/node/setup.py +36 -0
- agentcore/operations/python/__init__.py +17 -0
- agentcore/operations/python/setup.py +47 -0
- agentcore/operations/resolve_agent.py +159 -0
- agentcore/operations/session/__init__.py +86 -0
- agentcore/operations/traces/__init__.py +29 -0
- agentcore/operations/traces/get_trace.py +202 -0
- agentcore/operations/traces/insights_query.py +74 -0
- agentcore/operations/traces/list_traces.py +46 -0
- agentcore/operations/traces/trace_url.py +25 -0
- agentcore/operations/traces/types.py +55 -0
- agentcore/primitives/__init__.py +0 -0
- agentcore/primitives/_gateway_target_wizard.py +293 -0
- agentcore/primitives/_gateway_validation.py +442 -0
- agentcore/primitives/_harness_cli.py +557 -0
- agentcore/primitives/_harness_validation.py +163 -0
- agentcore/primitives/_harness_wizard.py +726 -0
- agentcore/primitives/_knowledge_base_wizard.py +259 -0
- agentcore/primitives/_payment_wizard.py +331 -0
- agentcore/primitives/_policy_form.py +160 -0
- agentcore/primitives/agent.py +817 -0
- agentcore/primitives/auth_utils.py +77 -0
- agentcore/primitives/base.py +178 -0
- agentcore/primitives/capacity_provider.py +501 -0
- agentcore/primitives/config_bundle.py +329 -0
- agentcore/primitives/credential.py +387 -0
- agentcore/primitives/credential_utils.py +45 -0
- agentcore/primitives/dataset.py +211 -0
- agentcore/primitives/deployed_gateways.py +34 -0
- agentcore/primitives/evaluator.py +909 -0
- agentcore/primitives/gateway.py +496 -0
- agentcore/primitives/gateway_target.py +988 -0
- agentcore/primitives/harness.py +706 -0
- agentcore/primitives/knowledge_base.py +477 -0
- agentcore/primitives/memory.py +387 -0
- agentcore/primitives/online_eval_config.py +365 -0
- agentcore/primitives/online_insights.py +275 -0
- agentcore/primitives/payment_connector.py +427 -0
- agentcore/primitives/payment_eligible.py +20 -0
- agentcore/primitives/payment_manager.py +605 -0
- agentcore/primitives/payment_validation.py +68 -0
- agentcore/primitives/policy.py +622 -0
- agentcore/primitives/policy_engine.py +358 -0
- agentcore/primitives/registry.py +56 -0
- agentcore/primitives/runtime_endpoint.py +361 -0
- agentcore/primitives/secret_flag_warning.py +17 -0
- agentcore/schema/__init__.py +14 -0
- agentcore/schema/_zod.py +395 -0
- agentcore/schema/constants.py +306 -0
- agentcore/schema/schemas/__init__.py +40 -0
- agentcore/schema/schemas/agent_env.py +545 -0
- agentcore/schema/schemas/agentcore_project.py +530 -0
- agentcore/schema/schemas/auth.py +286 -0
- agentcore/schema/schemas/aws_targets.py +72 -0
- agentcore/schema/schemas/connections.py +187 -0
- agentcore/schema/schemas/deployed_state.py +322 -0
- agentcore/schema/schemas/mcp.py +650 -0
- agentcore/schema/schemas/mcp_defs.py +54 -0
- agentcore/schema/schemas/primitives/__init__.py +52 -0
- agentcore/schema/schemas/primitives/ab_test.py +162 -0
- agentcore/schema/schemas/primitives/capacity_provider.py +214 -0
- agentcore/schema/schemas/primitives/config_bundle.py +48 -0
- agentcore/schema/schemas/primitives/dataset.py +55 -0
- agentcore/schema/schemas/primitives/evaluator.py +171 -0
- agentcore/schema/schemas/primitives/harness.py +710 -0
- agentcore/schema/schemas/primitives/knowledge_base.py +90 -0
- agentcore/schema/schemas/primitives/memory.py +113 -0
- agentcore/schema/schemas/primitives/online_eval_config.py +77 -0
- agentcore/schema/schemas/primitives/payment.py +114 -0
- agentcore/schema/schemas/primitives/policy.py +83 -0
- agentcore/schema/schemas/primitives/tags.py +50 -0
- agentcore/schema/schemas/zod_util.py +5 -0
- agentcore/schema/types/__init__.py +3 -0
- agentcore/schema/types/path.py +16 -0
- agentcore/templates/__init__.py +115 -0
- agentcore/templates/_handlebars.py +782 -0
- agentcore/templates/_js.py +164 -0
- agentcore/templates/base_renderer.py +107 -0
- agentcore/templates/cdk_renderer.py +129 -0
- agentcore/templates/evaluator_renderer.py +39 -0
- agentcore/templates/gateway_target_renderer.py +69 -0
- agentcore/templates/llm_context/README.md +16 -0
- agentcore/templates/llm_context/agentcore.ts +685 -0
- agentcore/templates/llm_context/aws-targets.ts +51 -0
- agentcore/templates/profiles.py +151 -0
- agentcore/templates/render.py +92 -0
- agentcore/templates/renderers.py +83 -0
- agentcore/templates/schema_assets.py +23 -0
- agentcore/templates/template_root.py +28 -0
- agentcore/templates/types.py +192 -0
- agentcore_cli-0.31.1.dist-info/METADATA +84 -0
- agentcore_cli-0.31.1.dist-info/RECORD +655 -0
- agentcore_cli-0.31.1.dist-info/WHEEL +4 -0
- agentcore_cli-0.31.1.dist-info/entry_points.txt +2 -0
- agentcore_cli-0.31.1.dist-info/licenses/LICENSE +175 -0
- agentcore_cli-0.31.1.dist-info/licenses/NOTICE +88 -0
|
@@ -0,0 +1,840 @@
|
|
|
1
|
+
"""Port of commands/invoke/action.ts: invoke a deployed runtime, harness, or gateway."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import sys
|
|
5
|
+
import uuid
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from agentcore.aws import (
|
|
10
|
+
DEFAULT_RUNTIME_USER_ID,
|
|
11
|
+
AguiInvokeOptions,
|
|
12
|
+
ExecuteBashOptions,
|
|
13
|
+
InvokeAgentRuntimeOptions,
|
|
14
|
+
McpInvokeOptions,
|
|
15
|
+
build_agui_run_input,
|
|
16
|
+
execute_bash_command,
|
|
17
|
+
extract_result,
|
|
18
|
+
get_or_create_payment_session,
|
|
19
|
+
invoke_a2a_runtime,
|
|
20
|
+
invoke_agent_runtime,
|
|
21
|
+
invoke_agent_runtime_streaming,
|
|
22
|
+
invoke_agui_runtime,
|
|
23
|
+
mcp_call_tool,
|
|
24
|
+
mcp_init_session,
|
|
25
|
+
mcp_list_tools,
|
|
26
|
+
parse_sse,
|
|
27
|
+
)
|
|
28
|
+
from agentcore.aws._http import http_request, sign_headers
|
|
29
|
+
from agentcore.aws.agentcore import A2AInvokeOptions
|
|
30
|
+
from agentcore.aws.agentcore_harness import invoke_harness
|
|
31
|
+
from agentcore.aws.partition import dns_suffix
|
|
32
|
+
from agentcore.cli.commands.invoke import _deps
|
|
33
|
+
from agentcore.cli.commands.invoke.constants import ANSI
|
|
34
|
+
from agentcore.cli.commands.invoke.resolve import resolve_invoke_target
|
|
35
|
+
from agentcore.cli.commands.invoke.types import InvokeOptions, InvokeResult, result
|
|
36
|
+
from agentcore.lib.errors.types import ResourceNotFoundError, ValidationError
|
|
37
|
+
from agentcore.lib.schemas.io.config_io import ConfigIO
|
|
38
|
+
from agentcore.logging import InvokeLogger
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@dataclass
|
|
42
|
+
class InvokeContext:
|
|
43
|
+
project: Any
|
|
44
|
+
deployed_state: Any
|
|
45
|
+
aws_targets: list[Any]
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def load_invoke_config(config_io: ConfigIO | None = None) -> InvokeContext:
|
|
49
|
+
config_io = config_io or ConfigIO()
|
|
50
|
+
return InvokeContext(
|
|
51
|
+
project=config_io.read_project_spec(),
|
|
52
|
+
deployed_state=config_io.read_deployed_state(),
|
|
53
|
+
aws_targets=config_io.read_aws_deployment_targets(),
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _write(text: str, stream: Any = None) -> None:
|
|
58
|
+
out = stream or sys.stdout
|
|
59
|
+
out.write(text)
|
|
60
|
+
out.flush()
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _err_text(err: BaseException) -> str:
|
|
64
|
+
return str(err)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _drop_none(value: Any) -> Any:
|
|
68
|
+
if isinstance(value, dict):
|
|
69
|
+
return {k: _drop_none(v) for k, v in value.items() if v is not None}
|
|
70
|
+
if isinstance(value, list):
|
|
71
|
+
return [_drop_none(v) for v in value]
|
|
72
|
+
return value
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _compact(value: Any) -> str:
|
|
76
|
+
return json.dumps(_drop_none(value), separators=(",", ":"), ensure_ascii=False)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def _is_json(text: str) -> bool:
|
|
80
|
+
try:
|
|
81
|
+
json.loads(text)
|
|
82
|
+
return True
|
|
83
|
+
except ValueError:
|
|
84
|
+
return False
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
# ============================================================================
|
|
88
|
+
# Gateway invoke
|
|
89
|
+
# ============================================================================
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _handle_gateway_invoke(context: InvokeContext, options: InvokeOptions) -> InvokeResult:
|
|
93
|
+
project, deployed_state, aws_targets = context.project, context.deployed_state, context.aws_targets
|
|
94
|
+
targets = deployed_state.targets or {}
|
|
95
|
+
target_names = list(targets)
|
|
96
|
+
if not target_names:
|
|
97
|
+
return result(False, error=ResourceNotFoundError("No deployed targets found. Run `agentcore deploy` first."))
|
|
98
|
+
selected = options.target_name if options.target_name is not None else target_names[0]
|
|
99
|
+
target_state = targets.get(selected)
|
|
100
|
+
target_config = next((t for t in aws_targets if t.name == selected), None)
|
|
101
|
+
if target_config is None:
|
|
102
|
+
return result(False, error=ResourceNotFoundError(f"Target config '{selected}' not found in aws-targets"))
|
|
103
|
+
|
|
104
|
+
resources = target_state.resources if target_state else None
|
|
105
|
+
gw_state = ((resources.gateways if resources else None) or {}).get(options.gateway) or (
|
|
106
|
+
((resources.mcp.gateways if resources and resources.mcp else None) or {}).get(options.gateway)
|
|
107
|
+
)
|
|
108
|
+
if not gw_state:
|
|
109
|
+
return result(
|
|
110
|
+
False,
|
|
111
|
+
error=ResourceNotFoundError(f"Gateway '{options.gateway}' is not deployed. Run `agentcore deploy` first."),
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
gw_spec = next((g for g in (project.agent_core_gateways or []) if g.name == options.gateway), None)
|
|
115
|
+
is_mcp = gw_spec is not None and gw_spec.protocol_type == "MCP"
|
|
116
|
+
authorizer = gw_spec.authorizer_type if gw_spec is not None else None
|
|
117
|
+
|
|
118
|
+
if authorizer == "CUSTOM_JWT" and not options.bearer_token:
|
|
119
|
+
return result(False, error=ValidationError("Gateway requires --bearer-token (CUSTOM_JWT authorizer)."))
|
|
120
|
+
|
|
121
|
+
region = target_config.region
|
|
122
|
+
gateway_url = gw_state.gateway_url
|
|
123
|
+
if not gateway_url:
|
|
124
|
+
parts = (gw_state.gateway_arn or "").split(":")
|
|
125
|
+
r = parts[3] if len(parts) > 3 else ""
|
|
126
|
+
gateway_url = f"https://{gw_state.gateway_id}.gateway.bedrock-agentcore.{r}.{dns_suffix(r)}" if r else None
|
|
127
|
+
if not gateway_url:
|
|
128
|
+
return result(False, error=ValidationError("Could not determine gateway URL."))
|
|
129
|
+
|
|
130
|
+
gw_targets = list(gw_spec.targets or []) if gw_spec is not None else []
|
|
131
|
+
if not is_mcp:
|
|
132
|
+
if not options.gateway_target:
|
|
133
|
+
http_targets = [t.name for t in gw_targets if t.target_type == "httpRuntime"]
|
|
134
|
+
return result(
|
|
135
|
+
False,
|
|
136
|
+
error=ValidationError(
|
|
137
|
+
f"--target-name is required for HTTP gateways. Available targets: {', '.join(http_targets)}"
|
|
138
|
+
),
|
|
139
|
+
)
|
|
140
|
+
target_spec = next((t for t in gw_targets if t.name == options.gateway_target), None)
|
|
141
|
+
if target_spec is None:
|
|
142
|
+
return result(
|
|
143
|
+
False,
|
|
144
|
+
error=ResourceNotFoundError(
|
|
145
|
+
f"Target '{options.gateway_target}' not found on gateway '{options.gateway}'."
|
|
146
|
+
),
|
|
147
|
+
)
|
|
148
|
+
if target_spec.target_type != "httpRuntime":
|
|
149
|
+
return result(
|
|
150
|
+
False, error=ValidationError(f"Target '{options.gateway_target}' is not an httpRuntime target.")
|
|
151
|
+
)
|
|
152
|
+
invocation_url = f"{gateway_url}/{options.gateway_target}/invocations"
|
|
153
|
+
if not options.prompt:
|
|
154
|
+
return result(False, error=ValidationError("--prompt is required for HTTP gateway invoke."))
|
|
155
|
+
# Plain strings become {"prompt": "..."}; JSON prompts pass through unchanged.
|
|
156
|
+
body = options.prompt if _is_json(options.prompt) else json.dumps({"prompt": options.prompt})
|
|
157
|
+
else:
|
|
158
|
+
if not options.tool:
|
|
159
|
+
return result(False, error=ValidationError("--tool is required for MCP gateway invoke."))
|
|
160
|
+
invocation_url = gateway_url if gateway_url.endswith("/mcp") else f"{gateway_url}/mcp"
|
|
161
|
+
body = json.dumps(
|
|
162
|
+
{
|
|
163
|
+
"jsonrpc": "2.0",
|
|
164
|
+
"id": 1,
|
|
165
|
+
"method": "tools/call",
|
|
166
|
+
"params": {"name": options.tool, "arguments": json.loads(options.input) if options.input else {}},
|
|
167
|
+
},
|
|
168
|
+
separators=(",", ":"),
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
headers: dict[str, str] = {"content-type": "application/json"}
|
|
172
|
+
if options.session_id:
|
|
173
|
+
headers["x-amz-bedrock-agentcore-session-id"] = options.session_id
|
|
174
|
+
if is_mcp:
|
|
175
|
+
headers["Accept"] = "application/json, text/event-stream"
|
|
176
|
+
headers["Mcp-Protocol-Version"] = "2025-03-26"
|
|
177
|
+
|
|
178
|
+
fetch_headers = headers
|
|
179
|
+
if authorizer == "CUSTOM_JWT":
|
|
180
|
+
fetch_headers = {**headers, "authorization": f"Bearer {options.bearer_token}"}
|
|
181
|
+
elif authorizer == "AWS_IAM":
|
|
182
|
+
fetch_headers = sign_headers("POST", invocation_url, region=region, headers=headers, body=body)
|
|
183
|
+
|
|
184
|
+
response = http_request("POST", invocation_url, headers=fetch_headers, body=body)
|
|
185
|
+
if not response.ok:
|
|
186
|
+
return result(False, error=RuntimeError(f"Gateway invoke failed ({response.status}): {response.text()}"))
|
|
187
|
+
|
|
188
|
+
response_text = response.text()
|
|
189
|
+
if is_mcp:
|
|
190
|
+
response_body = response_text
|
|
191
|
+
elif "data: " in response_text:
|
|
192
|
+
response_body = parse_sse(response_text)
|
|
193
|
+
else:
|
|
194
|
+
response_body = extract_result(response_text)
|
|
195
|
+
|
|
196
|
+
return result(
|
|
197
|
+
True,
|
|
198
|
+
response=response_body,
|
|
199
|
+
agentName=options.gateway_target or options.gateway,
|
|
200
|
+
targetName=selected,
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
# ============================================================================
|
|
205
|
+
# Main invoke handler
|
|
206
|
+
# ============================================================================
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def handle_invoke(context: InvokeContext, options: InvokeOptions | None = None) -> InvokeResult:
|
|
210
|
+
options = options or InvokeOptions()
|
|
211
|
+
project, deployed_state, aws_targets = context.project, context.deployed_state, context.aws_targets
|
|
212
|
+
|
|
213
|
+
if options.gateway:
|
|
214
|
+
return _handle_gateway_invoke(context, options)
|
|
215
|
+
|
|
216
|
+
harness_entries = project.harnesses or []
|
|
217
|
+
runtimes = project.runtimes or []
|
|
218
|
+
is_harness_invoke = options.harness_name is not None or (len(harness_entries) > 0 and len(runtimes) == 0)
|
|
219
|
+
|
|
220
|
+
if is_harness_invoke:
|
|
221
|
+
targets = deployed_state.targets or {}
|
|
222
|
+
target_names = list(targets)
|
|
223
|
+
if not target_names:
|
|
224
|
+
return result(
|
|
225
|
+
False, error=ResourceNotFoundError("No deployed targets found. Run `agentcore deploy` first.")
|
|
226
|
+
)
|
|
227
|
+
selected = options.target_name if options.target_name is not None else target_names[0]
|
|
228
|
+
if options.target_name and options.target_name not in target_names:
|
|
229
|
+
return result(
|
|
230
|
+
False,
|
|
231
|
+
error=ResourceNotFoundError(
|
|
232
|
+
f"Target '{options.target_name}' not found. Available: {', '.join(target_names)}"
|
|
233
|
+
),
|
|
234
|
+
)
|
|
235
|
+
target_config = next((t for t in aws_targets if t.name == selected), None)
|
|
236
|
+
if target_config is None:
|
|
237
|
+
return result(False, error=ResourceNotFoundError(f"Target config '{selected}' not found in aws-targets"))
|
|
238
|
+
return _handle_harness_invoke(project, targets.get(selected), target_config, selected, options)
|
|
239
|
+
|
|
240
|
+
if harness_entries and runtimes and not options.agent_name:
|
|
241
|
+
runtime_names = ", ".join(a.name for a in runtimes)
|
|
242
|
+
harness_names = ", ".join(h.name for h in harness_entries)
|
|
243
|
+
return result(
|
|
244
|
+
False,
|
|
245
|
+
error=ValidationError(
|
|
246
|
+
"Project has both runtimes and harnesses. Specify one:\n"
|
|
247
|
+
f" --runtime: {runtime_names}\n"
|
|
248
|
+
f" --harness: {harness_names}"
|
|
249
|
+
),
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
resolved = resolve_invoke_target(
|
|
253
|
+
project=project,
|
|
254
|
+
deployed_state=deployed_state,
|
|
255
|
+
aws_targets=aws_targets,
|
|
256
|
+
agent_name=options.agent_name,
|
|
257
|
+
target_name=options.target_name,
|
|
258
|
+
bearer_token=options.bearer_token,
|
|
259
|
+
session_id=options.session_id,
|
|
260
|
+
)
|
|
261
|
+
if not resolved.success:
|
|
262
|
+
return result(False, error=resolved.error)
|
|
263
|
+
|
|
264
|
+
agent_spec = resolved.agent_spec
|
|
265
|
+
selected = resolved.target_name
|
|
266
|
+
region = resolved.target_config.region
|
|
267
|
+
runtime_arn = resolved.runtime_arn
|
|
268
|
+
baggage = resolved.baggage
|
|
269
|
+
options = options.with_(
|
|
270
|
+
bearer_token=resolved.bearer_token or options.bearer_token,
|
|
271
|
+
session_id=resolved.session_id or options.session_id,
|
|
272
|
+
)
|
|
273
|
+
|
|
274
|
+
if agent_spec.network_mode == "VPC" and not options.json:
|
|
275
|
+
print(
|
|
276
|
+
f"{ANSI.yellow}Warning: This agent uses VPC network mode. Ensure your VPC endpoints are configured for "
|
|
277
|
+
f"invocation.{ANSI.reset}",
|
|
278
|
+
flush=True,
|
|
279
|
+
)
|
|
280
|
+
|
|
281
|
+
protocol = agent_spec.protocol
|
|
282
|
+
if (
|
|
283
|
+
(options.payment_instrument_id or options.payment_session_id or options.auto_session)
|
|
284
|
+
and protocol
|
|
285
|
+
and protocol != "HTTP"
|
|
286
|
+
):
|
|
287
|
+
return result(
|
|
288
|
+
False,
|
|
289
|
+
error=RuntimeError(
|
|
290
|
+
f"Payment flags are only supported for HTTP protocol agents. Agent '{agent_spec.name}' uses "
|
|
291
|
+
f"'{protocol}'."
|
|
292
|
+
),
|
|
293
|
+
)
|
|
294
|
+
|
|
295
|
+
if options.auto_session and options.payment_session_id:
|
|
296
|
+
return result(
|
|
297
|
+
False,
|
|
298
|
+
error=RuntimeError("--auto-session and --payment-session-id are mutually exclusive. Use one or the other."),
|
|
299
|
+
)
|
|
300
|
+
|
|
301
|
+
# Payments end-user identity: --payment-user-id, falling back to --user-id.
|
|
302
|
+
resolved_payment_user_id = options.payment_user_id if options.payment_user_id is not None else options.user_id
|
|
303
|
+
options = options.with_(payment_user_id=resolved_payment_user_id)
|
|
304
|
+
|
|
305
|
+
using_payment_context = bool(options.payment_instrument_id or options.payment_session_id or options.auto_session)
|
|
306
|
+
project_has_payments = len(project.payments or []) > 0
|
|
307
|
+
if (using_payment_context or project_has_payments) and not resolved_payment_user_id:
|
|
308
|
+
_write(
|
|
309
|
+
f"{ANSI.yellow}Warning: no --payment-user-id (or --user-id) provided. Payments will be scoped to "
|
|
310
|
+
f'"{DEFAULT_RUNTIME_USER_ID}" on the agent. This is intended for single-user testing only; '
|
|
311
|
+
"production should set --payment-user-id per end user so wallets and budgets are not shared."
|
|
312
|
+
f"{ANSI.reset}\n",
|
|
313
|
+
sys.stderr,
|
|
314
|
+
)
|
|
315
|
+
|
|
316
|
+
if options.auto_session and not options.payment_session_id:
|
|
317
|
+
target_state = (deployed_state.targets or {}).get(selected)
|
|
318
|
+
payments = target_state.resources.payments if target_state and target_state.resources else None
|
|
319
|
+
first_manager = next(iter(payments.values()), None) if payments else None
|
|
320
|
+
if not first_manager or not first_manager.manager_arn:
|
|
321
|
+
return result(
|
|
322
|
+
False,
|
|
323
|
+
error=RuntimeError("--auto-session requires a deployed payment manager. Run `agentcore deploy` first."),
|
|
324
|
+
)
|
|
325
|
+
try:
|
|
326
|
+
first_name = next(iter(payments))
|
|
327
|
+
payment_spec = next((p for p in (project.payments or []) if p.name == first_name), None)
|
|
328
|
+
kwargs: dict[str, Any] = {}
|
|
329
|
+
if payment_spec is not None and payment_spec.default_spend_limit is not None:
|
|
330
|
+
kwargs["default_spend_limit"] = payment_spec.default_spend_limit
|
|
331
|
+
session = get_or_create_payment_session(
|
|
332
|
+
region=region,
|
|
333
|
+
user_id=resolved_payment_user_id or DEFAULT_RUNTIME_USER_ID,
|
|
334
|
+
manager_arn=first_manager.manager_arn,
|
|
335
|
+
**kwargs,
|
|
336
|
+
)
|
|
337
|
+
options = options.with_(payment_session_id=session)
|
|
338
|
+
except Exception as exc: # noqa: BLE001
|
|
339
|
+
return result(False, error=RuntimeError(f"--auto-session failed to create payment session: {exc}"))
|
|
340
|
+
|
|
341
|
+
if options.exec:
|
|
342
|
+
return _handle_invoke_exec(region, runtime_arn, agent_spec.name, selected, options)
|
|
343
|
+
|
|
344
|
+
if protocol == "MCP":
|
|
345
|
+
mcp_opts = McpInvokeOptions(
|
|
346
|
+
region=region,
|
|
347
|
+
runtime_arn=runtime_arn,
|
|
348
|
+
user_id=options.user_id,
|
|
349
|
+
headers=options.headers,
|
|
350
|
+
bearer_token=options.bearer_token,
|
|
351
|
+
)
|
|
352
|
+
if options.prompt == "list-tools":
|
|
353
|
+
try:
|
|
354
|
+
listed = mcp_list_tools(mcp_opts)
|
|
355
|
+
return result(
|
|
356
|
+
True,
|
|
357
|
+
agentName=agent_spec.name,
|
|
358
|
+
targetName=selected,
|
|
359
|
+
response=_deps.format_mcp_tool_list(listed.tools),
|
|
360
|
+
)
|
|
361
|
+
except Exception as exc: # noqa: BLE001
|
|
362
|
+
return result(False, error=RuntimeError(f"Failed to list MCP tools: {exc}"))
|
|
363
|
+
if options.prompt == "call-tool":
|
|
364
|
+
if not options.tool:
|
|
365
|
+
return result(
|
|
366
|
+
False,
|
|
367
|
+
error=RuntimeError(
|
|
368
|
+
'MCP call-tool requires --tool <name>. Use "list-tools" to see available tools.'
|
|
369
|
+
),
|
|
370
|
+
)
|
|
371
|
+
args: dict[str, Any] = {}
|
|
372
|
+
if options.input:
|
|
373
|
+
try:
|
|
374
|
+
args = json.loads(options.input)
|
|
375
|
+
except ValueError:
|
|
376
|
+
return result(False, error=ValidationError(f"Invalid JSON for --input: {options.input}"))
|
|
377
|
+
try:
|
|
378
|
+
mcp_session_id = mcp_init_session(mcp_opts)
|
|
379
|
+
mcp_opts.mcp_session_id = mcp_session_id
|
|
380
|
+
response = mcp_call_tool(mcp_opts, options.tool, args)
|
|
381
|
+
return result(True, agentName=agent_spec.name, targetName=selected, response=response)
|
|
382
|
+
except Exception as exc: # noqa: BLE001
|
|
383
|
+
return result(False, error=RuntimeError(f"Failed to call MCP tool: {exc}"))
|
|
384
|
+
if not options.prompt:
|
|
385
|
+
return result(
|
|
386
|
+
False,
|
|
387
|
+
error=ValidationError(
|
|
388
|
+
"MCP agents require a command. Usage:\n agentcore invoke list-tools\n"
|
|
389
|
+
' agentcore invoke call-tool --tool <name> --input \'{"arg": "value"}\''
|
|
390
|
+
),
|
|
391
|
+
)
|
|
392
|
+
|
|
393
|
+
if not options.prompt:
|
|
394
|
+
return result(False, error=ValidationError('No prompt provided. Usage: agentcore invoke "your prompt"'))
|
|
395
|
+
|
|
396
|
+
if protocol == "A2A":
|
|
397
|
+
try:
|
|
398
|
+
a2a = invoke_a2a_runtime(
|
|
399
|
+
A2AInvokeOptions(
|
|
400
|
+
region=region,
|
|
401
|
+
runtime_arn=runtime_arn,
|
|
402
|
+
user_id=options.user_id,
|
|
403
|
+
session_id=options.session_id,
|
|
404
|
+
headers=options.headers,
|
|
405
|
+
bearer_token=options.bearer_token,
|
|
406
|
+
),
|
|
407
|
+
options.prompt,
|
|
408
|
+
)
|
|
409
|
+
response = ""
|
|
410
|
+
for chunk in a2a.stream:
|
|
411
|
+
response += chunk
|
|
412
|
+
if options.stream:
|
|
413
|
+
_write(chunk)
|
|
414
|
+
if options.stream:
|
|
415
|
+
_write("\n")
|
|
416
|
+
return result(True, agentName=agent_spec.name, targetName=selected, response=response)
|
|
417
|
+
except Exception as exc: # noqa: BLE001
|
|
418
|
+
return result(False, error=RuntimeError(f"A2A invoke failed: {exc}"))
|
|
419
|
+
|
|
420
|
+
if protocol == "AGUI":
|
|
421
|
+
logger = InvokeLogger(agent_name=agent_spec.name, runtime_arn=runtime_arn, region=region)
|
|
422
|
+
try:
|
|
423
|
+
agui_input = build_agui_run_input(options.prompt, options.session_id)
|
|
424
|
+
logger.log_prompt(options.prompt, None, options.user_id)
|
|
425
|
+
agui = invoke_agui_runtime(
|
|
426
|
+
AguiInvokeOptions(
|
|
427
|
+
region=region,
|
|
428
|
+
runtime_arn=runtime_arn,
|
|
429
|
+
session_id=options.session_id,
|
|
430
|
+
user_id=options.user_id,
|
|
431
|
+
logger=logger,
|
|
432
|
+
headers=options.headers,
|
|
433
|
+
bearer_token=options.bearer_token,
|
|
434
|
+
),
|
|
435
|
+
agui_input,
|
|
436
|
+
)
|
|
437
|
+
response = ""
|
|
438
|
+
has_error = False
|
|
439
|
+
for chunk in agui.text_stream:
|
|
440
|
+
response += chunk
|
|
441
|
+
if chunk.startswith("Error: "):
|
|
442
|
+
has_error = True
|
|
443
|
+
if options.stream:
|
|
444
|
+
_write(chunk)
|
|
445
|
+
if options.stream:
|
|
446
|
+
_write("\n")
|
|
447
|
+
logger.log_response(response)
|
|
448
|
+
if has_error:
|
|
449
|
+
return result(
|
|
450
|
+
False,
|
|
451
|
+
error=RuntimeError(response),
|
|
452
|
+
agentName=agent_spec.name,
|
|
453
|
+
targetName=selected,
|
|
454
|
+
response=response,
|
|
455
|
+
sessionId=agui.session_id,
|
|
456
|
+
logFilePath=logger.log_file_path,
|
|
457
|
+
)
|
|
458
|
+
return result(
|
|
459
|
+
True,
|
|
460
|
+
agentName=agent_spec.name,
|
|
461
|
+
targetName=selected,
|
|
462
|
+
response=response,
|
|
463
|
+
sessionId=agui.session_id,
|
|
464
|
+
logFilePath=logger.log_file_path,
|
|
465
|
+
)
|
|
466
|
+
except Exception as exc: # noqa: BLE001
|
|
467
|
+
logger.log_error(exc, "AGUI invoke failed")
|
|
468
|
+
return result(False, error=RuntimeError(f"AGUI invoke failed: {exc}"))
|
|
469
|
+
|
|
470
|
+
logger = InvokeLogger(
|
|
471
|
+
agent_name=agent_spec.name, runtime_arn=runtime_arn, region=region, session_id=options.session_id
|
|
472
|
+
)
|
|
473
|
+
logger.log_prompt(options.prompt, options.session_id, options.user_id)
|
|
474
|
+
|
|
475
|
+
invoke_options = InvokeAgentRuntimeOptions(
|
|
476
|
+
region=region,
|
|
477
|
+
runtime_arn=runtime_arn,
|
|
478
|
+
payload=options.prompt,
|
|
479
|
+
session_id=options.session_id,
|
|
480
|
+
user_id=options.user_id,
|
|
481
|
+
headers=options.headers,
|
|
482
|
+
bearer_token=options.bearer_token,
|
|
483
|
+
baggage=baggage,
|
|
484
|
+
payment_instrument_id=options.payment_instrument_id,
|
|
485
|
+
payment_session_id=options.payment_session_id,
|
|
486
|
+
payment_user_id=options.payment_user_id,
|
|
487
|
+
)
|
|
488
|
+
|
|
489
|
+
if options.stream:
|
|
490
|
+
full = ""
|
|
491
|
+
try:
|
|
492
|
+
invoke_options.logger = logger
|
|
493
|
+
streamed = invoke_agent_runtime_streaming(invoke_options)
|
|
494
|
+
for chunk in streamed.stream:
|
|
495
|
+
full += chunk
|
|
496
|
+
_write(chunk)
|
|
497
|
+
_write("\n")
|
|
498
|
+
logger.log_response(full)
|
|
499
|
+
return result(
|
|
500
|
+
True,
|
|
501
|
+
agentName=agent_spec.name,
|
|
502
|
+
targetName=selected,
|
|
503
|
+
response=full,
|
|
504
|
+
sessionId=streamed.session_id,
|
|
505
|
+
logFilePath=logger.log_file_path,
|
|
506
|
+
)
|
|
507
|
+
except Exception as exc:
|
|
508
|
+
logger.log_error(exc, "invoke streaming failed")
|
|
509
|
+
raise
|
|
510
|
+
|
|
511
|
+
response = invoke_agent_runtime(invoke_options)
|
|
512
|
+
logger.log_response(response.content)
|
|
513
|
+
return result(
|
|
514
|
+
True,
|
|
515
|
+
agentName=agent_spec.name,
|
|
516
|
+
targetName=selected,
|
|
517
|
+
response=response.content,
|
|
518
|
+
sessionId=response.session_id,
|
|
519
|
+
logFilePath=logger.log_file_path,
|
|
520
|
+
)
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
# ============================================================================
|
|
524
|
+
# Harness invoke
|
|
525
|
+
# ============================================================================
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
def _spec_get(spec: Any, attr: str) -> Any:
|
|
529
|
+
if spec is None:
|
|
530
|
+
return None
|
|
531
|
+
if isinstance(spec, dict):
|
|
532
|
+
camel = "".join(p if i == 0 else p.capitalize() for i, p in enumerate(attr.split("_")))
|
|
533
|
+
return spec.get(camel, spec.get(attr))
|
|
534
|
+
return getattr(spec, attr, None)
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
def build_harness_base_opts(options: InvokeOptions, harness_spec: Any = None) -> dict[str, Any]:
|
|
538
|
+
"""Per-invocation harness overrides, as keyword arguments for :func:`invoke_harness`."""
|
|
539
|
+
base: dict[str, Any] = {}
|
|
540
|
+
if (
|
|
541
|
+
options.model_id
|
|
542
|
+
or options.model_provider
|
|
543
|
+
or options.api_key_arn
|
|
544
|
+
or options.api_base
|
|
545
|
+
or options.additional_params
|
|
546
|
+
):
|
|
547
|
+
provider = options.model_provider or _spec_get(harness_spec, "provider")
|
|
548
|
+
model_id = options.model_id or _spec_get(harness_spec, "model_id") or ""
|
|
549
|
+
api_key_arn = options.api_key_arn or _spec_get(harness_spec, "api_key_arn")
|
|
550
|
+
api_base = options.api_base or _spec_get(harness_spec, "api_base")
|
|
551
|
+
additional_params = options.additional_params or _spec_get(harness_spec, "additional_params")
|
|
552
|
+
if provider == "open_ai":
|
|
553
|
+
base["model"] = {
|
|
554
|
+
"openAiModelConfig": {"modelId": model_id, **({"apiKeyArn": api_key_arn} if api_key_arn else {})}
|
|
555
|
+
}
|
|
556
|
+
elif provider == "gemini":
|
|
557
|
+
base["model"] = {
|
|
558
|
+
"geminiModelConfig": {"modelId": model_id, **({"apiKeyArn": api_key_arn} if api_key_arn else {})}
|
|
559
|
+
}
|
|
560
|
+
elif provider == "lite_llm":
|
|
561
|
+
config: dict[str, Any] = {"modelId": model_id}
|
|
562
|
+
if api_key_arn:
|
|
563
|
+
config["apiKeyArn"] = api_key_arn
|
|
564
|
+
if api_base:
|
|
565
|
+
config["apiBase"] = api_base
|
|
566
|
+
if additional_params:
|
|
567
|
+
config["additionalParams"] = additional_params
|
|
568
|
+
base["model"] = {"liteLlmModelConfig": config}
|
|
569
|
+
else:
|
|
570
|
+
base["model"] = {"bedrockModelConfig": {"modelId": model_id}}
|
|
571
|
+
if options.tools:
|
|
572
|
+
base["tools"] = [{"type": t.strip(), "name": t.strip()} for t in options.tools.split(",")]
|
|
573
|
+
if options.max_iterations is not None:
|
|
574
|
+
base["max_iterations"] = options.max_iterations
|
|
575
|
+
if options.max_tokens is not None:
|
|
576
|
+
base["max_tokens"] = options.max_tokens
|
|
577
|
+
if options.harness_timeout is not None:
|
|
578
|
+
base["timeout_seconds"] = options.harness_timeout
|
|
579
|
+
if options.skills:
|
|
580
|
+
skills = []
|
|
581
|
+
for s in options.skills.split(","):
|
|
582
|
+
trimmed = s.strip()
|
|
583
|
+
if trimmed.startswith("s3://"):
|
|
584
|
+
skills.append({"s3Uri": trimmed})
|
|
585
|
+
elif trimmed.startswith("https://"):
|
|
586
|
+
skills.append({"gitUrl": trimmed})
|
|
587
|
+
else:
|
|
588
|
+
skills.append({"path": trimmed})
|
|
589
|
+
base["skills"] = skills
|
|
590
|
+
if options.system_prompt:
|
|
591
|
+
base["system_prompt"] = [{"text": options.system_prompt}]
|
|
592
|
+
if options.allowed_tools:
|
|
593
|
+
base["allowed_tools"] = [t.strip() for t in options.allowed_tools.split(",")]
|
|
594
|
+
if options.actor_id:
|
|
595
|
+
base["actor_id"] = options.actor_id
|
|
596
|
+
return base
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
def _handle_invoke_exec(
|
|
600
|
+
region: str, runtime_arn: str, agent_name: str, target_name: str | None, options: InvokeOptions
|
|
601
|
+
) -> InvokeResult:
|
|
602
|
+
logger = InvokeLogger(agent_name=agent_name, runtime_arn=runtime_arn, region=region, session_id=options.session_id)
|
|
603
|
+
command = options.prompt
|
|
604
|
+
if not command:
|
|
605
|
+
return result(False, error=ValidationError("--exec requires a command (prompt)"))
|
|
606
|
+
logger.log_prompt(command, options.session_id, options.user_id)
|
|
607
|
+
|
|
608
|
+
try:
|
|
609
|
+
executed = execute_bash_command(
|
|
610
|
+
ExecuteBashOptions(
|
|
611
|
+
region=region,
|
|
612
|
+
runtime_arn=runtime_arn,
|
|
613
|
+
command=command,
|
|
614
|
+
session_id=options.session_id,
|
|
615
|
+
timeout=options.timeout,
|
|
616
|
+
headers=options.headers,
|
|
617
|
+
bearer_token=options.bearer_token,
|
|
618
|
+
)
|
|
619
|
+
)
|
|
620
|
+
stdout = ""
|
|
621
|
+
stderr = ""
|
|
622
|
+
exit_code: int | None = None
|
|
623
|
+
status: str | None = None
|
|
624
|
+
for event in executed.stream:
|
|
625
|
+
kind = event.get("type")
|
|
626
|
+
if kind == "stdout" and event.get("data"):
|
|
627
|
+
stdout += event["data"]
|
|
628
|
+
if not options.json:
|
|
629
|
+
_write(event["data"])
|
|
630
|
+
elif kind == "stderr" and event.get("data"):
|
|
631
|
+
stderr += event["data"]
|
|
632
|
+
if not options.json:
|
|
633
|
+
_write(event["data"], sys.stderr)
|
|
634
|
+
elif kind == "stop":
|
|
635
|
+
exit_code = event.get("exitCode")
|
|
636
|
+
status = event.get("status")
|
|
637
|
+
|
|
638
|
+
logger.log_response(stdout or stderr or f"exit code: {'undefined' if exit_code is None else exit_code}")
|
|
639
|
+
payload = _compact({"stdout": stdout, "stderr": stderr, "exitCode": exit_code, "status": status})
|
|
640
|
+
|
|
641
|
+
if options.json:
|
|
642
|
+
if exit_code == 0:
|
|
643
|
+
return result(
|
|
644
|
+
True,
|
|
645
|
+
exitCode=exit_code,
|
|
646
|
+
agentName=agent_name,
|
|
647
|
+
targetName=target_name,
|
|
648
|
+
response=payload,
|
|
649
|
+
logFilePath=logger.log_file_path,
|
|
650
|
+
)
|
|
651
|
+
return result(
|
|
652
|
+
False,
|
|
653
|
+
exitCode=exit_code,
|
|
654
|
+
error=RuntimeError(f"Command exited with code {'undefined' if exit_code is None else exit_code}"),
|
|
655
|
+
agentName=agent_name,
|
|
656
|
+
targetName=target_name,
|
|
657
|
+
response=payload,
|
|
658
|
+
logFilePath=logger.log_file_path,
|
|
659
|
+
)
|
|
660
|
+
|
|
661
|
+
if exit_code is None:
|
|
662
|
+
return result(
|
|
663
|
+
False,
|
|
664
|
+
error=RuntimeError("Command stream ended without exit code"),
|
|
665
|
+
agentName=agent_name,
|
|
666
|
+
targetName=target_name,
|
|
667
|
+
logFilePath=logger.log_file_path,
|
|
668
|
+
)
|
|
669
|
+
if exit_code != 0:
|
|
670
|
+
suffix = " (timed out)" if status == "TIMED_OUT" else ""
|
|
671
|
+
return result(
|
|
672
|
+
False,
|
|
673
|
+
exitCode=exit_code,
|
|
674
|
+
error=RuntimeError(f"Command exited with code {exit_code}{suffix}"),
|
|
675
|
+
agentName=agent_name,
|
|
676
|
+
targetName=target_name,
|
|
677
|
+
response=payload,
|
|
678
|
+
logFilePath=logger.log_file_path,
|
|
679
|
+
)
|
|
680
|
+
return result(
|
|
681
|
+
True, exitCode=exit_code, agentName=agent_name, targetName=target_name, logFilePath=logger.log_file_path
|
|
682
|
+
)
|
|
683
|
+
except Exception as exc:
|
|
684
|
+
logger.log_error(exc, "exec command failed")
|
|
685
|
+
raise
|
|
686
|
+
|
|
687
|
+
|
|
688
|
+
def handle_harness_invoke_by_arn(harness_arn: str, region: str, options: InvokeOptions) -> InvokeResult:
|
|
689
|
+
if not options.prompt:
|
|
690
|
+
return result(
|
|
691
|
+
False,
|
|
692
|
+
error=ValidationError(
|
|
693
|
+
'No prompt provided. Usage: agentcore invoke --harness-arn <arn> --region <region> "your prompt"'
|
|
694
|
+
),
|
|
695
|
+
)
|
|
696
|
+
session_id = options.session_id or str(uuid.uuid4())
|
|
697
|
+
if options.exec:
|
|
698
|
+
return _handle_invoke_exec(region, harness_arn, "external-harness", None, options.with_(session_id=session_id))
|
|
699
|
+
logger = InvokeLogger(agent_name="external-harness", runtime_arn=harness_arn, region=region, session_id=session_id)
|
|
700
|
+
logger.log_prompt(options.prompt, session_id, options.user_id)
|
|
701
|
+
return _stream_harness_invoke(
|
|
702
|
+
region, harness_arn, session_id, options.prompt, options, logger, build_harness_base_opts(options)
|
|
703
|
+
)
|
|
704
|
+
|
|
705
|
+
|
|
706
|
+
def _stream_harness_invoke(
|
|
707
|
+
region: str,
|
|
708
|
+
harness_arn: str,
|
|
709
|
+
session_id: str,
|
|
710
|
+
prompt: str,
|
|
711
|
+
options: InvokeOptions,
|
|
712
|
+
logger: InvokeLogger,
|
|
713
|
+
base_opts: dict[str, Any],
|
|
714
|
+
) -> InvokeResult:
|
|
715
|
+
full = ""
|
|
716
|
+
try:
|
|
717
|
+
stream = invoke_harness(
|
|
718
|
+
region=region,
|
|
719
|
+
harness_arn=harness_arn,
|
|
720
|
+
runtime_session_id=session_id,
|
|
721
|
+
messages=[{"role": "user", "content": [{"text": prompt}]}],
|
|
722
|
+
bearer_token=options.bearer_token,
|
|
723
|
+
**base_opts,
|
|
724
|
+
)
|
|
725
|
+
for event in stream:
|
|
726
|
+
if options.verbose:
|
|
727
|
+
print(_compact(event), flush=True)
|
|
728
|
+
continue
|
|
729
|
+
kind = event.get("type")
|
|
730
|
+
if kind == "contentBlockDelta":
|
|
731
|
+
delta = event.get("delta") or {}
|
|
732
|
+
if delta.get("type") == "text":
|
|
733
|
+
text = delta.get("text") or ""
|
|
734
|
+
full += text
|
|
735
|
+
if not options.json:
|
|
736
|
+
_write(text)
|
|
737
|
+
elif kind == "messageStop":
|
|
738
|
+
if not options.json and event.get("stopReason") not in ("tool_use", "tool_result"):
|
|
739
|
+
_write("\n")
|
|
740
|
+
elif kind == "error":
|
|
741
|
+
message = f"{event.get('errorType')}: {event.get('message')}"
|
|
742
|
+
logger.log_error(RuntimeError(message), "stream error")
|
|
743
|
+
if options.json:
|
|
744
|
+
return result(False, error=RuntimeError(message))
|
|
745
|
+
_write(f"\nError: {event.get('message')}\n", sys.stderr)
|
|
746
|
+
|
|
747
|
+
logger.log_response(full)
|
|
748
|
+
if options.json:
|
|
749
|
+
return result(
|
|
750
|
+
True,
|
|
751
|
+
response=_compact({"text": full, "sessionId": session_id}),
|
|
752
|
+
sessionId=session_id,
|
|
753
|
+
logFilePath=logger.log_file_path,
|
|
754
|
+
)
|
|
755
|
+
return result(True, sessionId=session_id, logFilePath=logger.log_file_path)
|
|
756
|
+
except Exception as exc: # noqa: BLE001
|
|
757
|
+
logger.log_error(exc, "harness invoke failed")
|
|
758
|
+
return result(False, error=RuntimeError(f"Harness invoke failed: {exc}"), logFilePath=logger.log_file_path)
|
|
759
|
+
|
|
760
|
+
|
|
761
|
+
def _handle_harness_invoke(
|
|
762
|
+
project: Any, target_state: Any, target_config: Any, selected: str, options: InvokeOptions
|
|
763
|
+
) -> InvokeResult:
|
|
764
|
+
entries = project.harnesses or []
|
|
765
|
+
if not entries:
|
|
766
|
+
return result(False, error=ValidationError("No harnesses defined in configuration"))
|
|
767
|
+
|
|
768
|
+
harness_name = options.harness_name
|
|
769
|
+
if not harness_name:
|
|
770
|
+
if len(entries) > 1:
|
|
771
|
+
names = ", ".join(h.name for h in entries)
|
|
772
|
+
return result(
|
|
773
|
+
False, error=ValidationError(f"Multiple harnesses found. Use --harness to specify one: {names}")
|
|
774
|
+
)
|
|
775
|
+
harness_name = entries[0].name
|
|
776
|
+
|
|
777
|
+
if not any(h.name == harness_name for h in entries):
|
|
778
|
+
names = ", ".join(h.name for h in entries)
|
|
779
|
+
return result(False, error=ResourceNotFoundError(f"Harness '{harness_name}' not found. Available: {names}"))
|
|
780
|
+
|
|
781
|
+
resources = target_state.resources if target_state else None
|
|
782
|
+
harness_state = ((resources.harnesses if resources else None) or {}).get(harness_name)
|
|
783
|
+
if not harness_state:
|
|
784
|
+
return result(
|
|
785
|
+
False,
|
|
786
|
+
error=ValidationError(
|
|
787
|
+
f"Harness '{harness_name}' is not deployed to target '{selected}'. Run `agentcore deploy` first."
|
|
788
|
+
),
|
|
789
|
+
)
|
|
790
|
+
|
|
791
|
+
session_id = options.session_id or str(uuid.uuid4())
|
|
792
|
+
region = target_config.region
|
|
793
|
+
options = options.with_(session_id=session_id)
|
|
794
|
+
|
|
795
|
+
harness_spec = None
|
|
796
|
+
try:
|
|
797
|
+
harness_spec = ConfigIO().read_harness_spec(harness_name)
|
|
798
|
+
except Exception: # noqa: BLE001, S110 - spec read is best-effort
|
|
799
|
+
pass
|
|
800
|
+
|
|
801
|
+
if harness_spec is not None and harness_spec.authorizer_type == "CUSTOM_JWT" and not options.bearer_token:
|
|
802
|
+
if _deps.can_fetch_harness_token(harness_name):
|
|
803
|
+
try:
|
|
804
|
+
token = _deps.token_of(_deps.fetch_harness_token(harness_name, deploy_target=selected))
|
|
805
|
+
options = options.with_(bearer_token=token)
|
|
806
|
+
except Exception as exc: # noqa: BLE001
|
|
807
|
+
return result(
|
|
808
|
+
False,
|
|
809
|
+
error=ValidationError(
|
|
810
|
+
f"CUSTOM_JWT harness requires a bearer token. Auto-fetch failed: {exc}\n"
|
|
811
|
+
"Provide one manually with --bearer-token."
|
|
812
|
+
),
|
|
813
|
+
)
|
|
814
|
+
else:
|
|
815
|
+
return result(
|
|
816
|
+
False,
|
|
817
|
+
error=ValidationError(
|
|
818
|
+
f"Harness '{harness_name}' is configured for CUSTOM_JWT but no bearer token is available.\n"
|
|
819
|
+
"Either provide --bearer-token or re-add the harness with --client-id and --client-secret to "
|
|
820
|
+
"enable auto-fetch."
|
|
821
|
+
),
|
|
822
|
+
)
|
|
823
|
+
|
|
824
|
+
if not options.prompt:
|
|
825
|
+
return result(
|
|
826
|
+
False, error=ValidationError('No prompt provided. Usage: agentcore invoke --harness <name> "your prompt"')
|
|
827
|
+
)
|
|
828
|
+
|
|
829
|
+
if options.exec:
|
|
830
|
+
return _handle_invoke_exec(region, harness_state.harness_arn, harness_name, selected, options)
|
|
831
|
+
|
|
832
|
+
logger = InvokeLogger(
|
|
833
|
+
agent_name=harness_name, runtime_arn=harness_state.harness_arn, region=region, session_id=session_id
|
|
834
|
+
)
|
|
835
|
+
logger.log_prompt(options.prompt, session_id, options.user_id)
|
|
836
|
+
base_opts = build_harness_base_opts(options, harness_spec.model if harness_spec is not None else None)
|
|
837
|
+
out = _stream_harness_invoke(
|
|
838
|
+
region, harness_state.harness_arn, session_id, options.prompt, options, logger, base_opts
|
|
839
|
+
)
|
|
840
|
+
return {**out, "targetName": selected}
|