Repository navigation
Add several composite CLI commands for common multi-step workflows - #10894
Draft
PCManticore wants to merge 7 commits into
Draft
PCManticore wants to merge 7 commits into
PCManticore wants to merge 7 commits into
Conversation
PCManticore
force-pushed
the
barisk/high-order-commands
branch
6 times, most recently
from
November 20, 2026 09:35
65f6dfa to
480c2d9
Compare
PCManticore
force-pushed
the
barisk/high-order-commands
branch
from
November 20, 2026 11:13
480c2d9 to
01bf0ae
Compare
Generated by AI tools, and reviewed by Claudiu Popa <clpo@amazon.com> Co-authored-by: Baris Kurt <barisk@amazon.com>
Generated by AI tools, and reviewed by Claudiu Popa <clpo@amazon.com> Co-authored-by: Baris Kurt <barisk@amazon.com>
Generated by AI tools, and reviewed by Claudiu Popa <clpo@amazon.com> Co-authored-by: Baris Kurt <barisk@amazon.com>
Generated by AI tools, and reviewed by Claudiu Popa <clpo@amazon.com> Co-authored-by: Baris Kurt <barisk@amazon.com>
… window anchoring 1. PromQL alarms now detected via EvaluationCriteria.PromQLCriteria and the broader no-MetricName/no-MetricStat fallback. Exit 255 with UNSUPPORTED_ALARM_TYPE instead of silent exit 0 with empty data. 2. Composite parsing handles AT_LEAST(n, STATE, (a, b, ...)) syntax, escaped quotes in child names, and notes ARN children limitation. 3. Window anchors on StateTransitionedTimestamp (falls back to StateUpdatedTimestamp, then now). Look-back widened to (EvaluationPeriods + ceil(240/Period) + 1) x Period. Still-ALARM extends the window end to now. Generated by AI tools, and reviewed by Claudiu Popa <clpo@amazon.com> Co-authored-by: Baris Kurt <barisk@amazon.com>
Clarify that alarm-metric-sweep replaces the first few CloudWatch API calls (DescribeAlarms, GetMetricData, DescribeAlarmHistory) in a single call. Add a note that --fan-out sibling context may reduce further investigation of infrastructure, logs and configuration. AWS-Bench testing showed that without --fan-out, agents use sweep as a starting point and continue investigating (ECS, SSM, logs), achieving the same pass rate as the control. With --fan-out, the comprehensive sibling comparison caused agents to stop investigating prematurely. Generated by AI tools, and reviewed by Claudiu Popa <clpo@amazon.com> Co-authored-by: Baris Kurt <barisk@amazon.com>
PCManticore
force-pushed
the
barisk/high-order-commands
branch
from
November 21, 2026 13:10
01bf0ae to
5ce7537
Compare
Reframe diagnose-service as gathering a diagnostic view that replaces the first several ECS API calls, rather than explaining why a service is unhealthy. Add a note that root causes outside ECS (VPC networking, ECR image availability, IAM policies, dependent services) require further investigation. AWS-Bench testing showed that with the updated framing, agents use diagnose-service as a starting point and continue investigating ECR, capacity providers, and networking, scoring 0.71 vs 0.14 with the original framing and 0.29 for the control. Generated by AI tools, and reviewed by Claudiu Popa <clpo@amazon.com> Co-authored-by: Baris Kurt <barisk@amazon.com>
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
The AWS CLI is the primary interface agents use to interact with AWS. Agents chain 5-12+ raw API calls to perform one logical operation (run a query, diagnose a service, investigate an alarm etc) and routinely drop steps, mishandle polling, produce unbounded output, or lose context between calls.
Four workflows stand out:
StartQueryExecution→ pollGetQueryExecution→ paginateGetQueryResults→ parse → type-castResultSetstructure unparsed, no timeout handlingDescribeLogGroups→StartQuery→ pollGetQueryResults→StopQueryon timeoutDescribeAlarms→ resolve composite children → extract metric config →GetMetricStatisticsper metricDescribeServices→DescribeTaskDefinition→ListTasks→DescribeTasks→ log retrieval → target healthThese commands address this by collapsing each workflow into a single CLI call.
What
Four new CLI customization commands, plus a shared
compositereadonly/support package:aws athena run-query— Submits a SQL query to Athena, polls for completion, paginates results, and returns structured JSON with type-cast values and execution metadata. Handles workgroup output location resolution, configurable polling with timeout and auto-cancellation, and row capping.aws logs run-insights-query— Runs a Logs Insights query across one or more log groups. Resolves log group names, prefixes, and ARNs; polls with auto-cancellation; splits large time windows when the result set exceeds the service limit; deduplicates across sub-windows; and caps output rows.aws cloudwatch alarm-metric-sweep— Resolves an alarm (including composite alarm children) to its underlying metrics, calculates the appropriate time window, and pulls bounded metric data for each. Returns a correlated view of alarm state and metric data in one call. Replaces the first few CloudWatch API calls in an alarm investigation (DescribeAlarms, GetMetricData, DescribeAlarmHistory). The optional--fan-outflag enumerates sibling dimension series for metric-level comparison; without it, agents use sweep as a starting point and continue investigating infrastructure, logs and configuration on their own.aws ecs diagnose-service— Gathers a full diagnostic view of an ECS service: configuration, task definitions, running and stopped tasks, recent service events, log evidence, and load balancer target health. Output is bounded and secrets in log evidence are redacted.All commands follow the same contract: errors are returned as data (never raised), every result is a structured JSON envelope, every bound and adjustment is reported in a
guidancearray, and exit codes are machine-parseable.Developer experience
aws athena run-queryBefore (5-7 steps)
After (1 call)
aws athena run-query \ --sql "SELECT * FROM my_table LIMIT 10" \ --catalog AwsDataCatalog \ --database default \ --output-location s3://my-bucket/results/aws logs run-insights-queryBefore (4-6 steps)
After (1 call)
aws cloudwatch alarm-metric-sweepBefore (4-10+ steps)
After (1 call)
aws cloudwatch alarm-metric-sweep --alarm-name 'MyAlarm'aws ecs diagnose-serviceBefore (6-12 steps)
After (1 call)
Summary
code,guidance, exit codesKey behaviors:
--max-rows; series and datapoint caps for CloudWatch). Truncation is always reported inguidance.error,code, andguidance— never an unhandled exception. Callers branch on exit code andcodefield.0= success,252= input validation error (fix the arguments),255= operational error (resource not found, service error, timeout).guidancearray in the output. The caller never has to guess what happened.*, and ARNs. Resolution results are included in the output so the caller can see what matched.--output tableand--output textDisclosure: This code was generated with AI assistance and reviewed by the authors.
Before / after: actual output comparison
CloudWatch alarm investigation
Before (3 calls, manual parameter construction):
After (1 call):
Auto-calculates the window, adjusts period for retention, reports what it did.
Logs Insights query
Before (3 calls + polling + array-of-arrays output):
After (1 call, named rows):
No polling, ISO timestamps, rows are named objects.
Athena query
Before (3 calls + polling + untyped VarCharValue format):
After (1 call, typed rows):
No polling, integers are integers, header separated from data.
ECS service diagnosis
Before (6+ calls):
After (1 call):
One structured response with blockers, warnings, and log evidence (secrets redacted).
Agent evaluation (AWS-Bench)
We ran paired A/B trials on AWS-Bench (Sonnet 5, claude-code,
diagnose-cloudwatch-alarm-firinganddiagnose-ecs-service-no-running-tasks-1tasks) to measure how these commands affect agent behavior in practice.Step reduction. Each command replaces a multi-call sequence with a single CLI invocation. When agents use these commands as a starting point and continue investigating, they reach the same conclusions faster:
alarm-metric-sweepdiagnose-servicerun-insights-queryData-fetching commands are safe.
run-insights-queryandrun-queryreturn query results (rows), not diagnostic assessments. Agents use them as tools and continue investigating normally, with no score regression and fewer steps.