Agents Optimize
AWSOfficialCreated by aws-agentcore
- Skill
- Tool integration
- Cloud and DevOps
- Apache-2.0
- No issues found
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
The agents-optimize skill provides a structured approach to monitoring and refining AgentCore agents. It guides developers through setting up evaluators, configuring continuous monitoring, implementing CI/CD quality gates, and analyzing agent costs. The skill leverages project context to determine whether to focus on evaluation workflows, observability setups like CloudWatch and X-Ray, or cost optimization strategies.
What it does
- Configures evaluators for assessing agent responses
- Sets up continuous online monitoring for live traffic
- Generates CI/CD quality gate scripts to validate agent performance
- Provides guidance on setting up CloudWatch dashboards and X-Ray tracing
- Analyzes cost drivers for AgentCore runtimes and memory usage
- Facilitates local evaluation loops using dev traces
When to use it
- When you need to verify if your agent is providing accurate responses
- When you want to implement automated quality checks in your deployment pipeline
- When you need to gain visibility into agent behavior via logs and metrics
- When you need to understand and control the costs associated with your agent
Advantages
- Supports local iteration on evaluators without requiring full deployments
- Integrates with standard AWS observability tools like CloudWatch
- Provides clear paths for both development-time and production-time monitoring
- Helps identify specific cost drivers within the AgentCore architecture
Usage examples
- “evaluate my agent”
- The skill initiates an interactive session to determine if you want to run a one-time evaluation, set up monitoring, or add a CI/CD quality gate.
- “set up observability”
- The skill loads the observability reference and guides you through configuring CloudWatch dashboards and X-Ray tracing for your agent.
- “how much does my agent cost”
- The skill provides a breakdown of cost components such as runtime compute, memory events, and model usage to help you optimize your spending.
- “quality gate”
- The skill generates a script to integrate a quality gate into your CI/CD pipeline, ensuring builds fail if performance thresholds are not met.
Install
Download the skill as a ZIP:
https://mp-staging.autogineer.com/agent-skills/aws/agents-optimize/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip agents-optimize.zip -d .agents/skills
Documentation by aws-agentcore
optimize
Measure and improve your AgentCore agent's quality through evaluation, monitoring, and observability.
When to use
You want to know if your agent is giving good answers
You want to set up continuous quality monitoring in production
You want to add a quality gate to your CI/CD pipeline
You want to understand agent behavior through logs, metrics, and traces
You want to set up CloudWatch dashboards or X-Ray tracing
Do NOT use for:
Debugging a specific broken agent (wrong answers, errors) → use
agents-debugProduction security hardening (IAM, auth) → use
agents-harden
Input
$ARGUMENTS can be:
An eval goal: "add a quality gate", "set up monitoring"
An observability goal: "set up CloudWatch dashboard", "understand my traces"
A specific evaluator: "llm-as-a-judge", "code-based"
Empty — the skill will guide based on project context
Process
Step 0: Verify CLI version
Run agentcore --version. This skill requires v0.9.0 or later.
Step 1: Read project context
Read agentcore/agentcore.json to understand existing evaluators, online eval configs, and agent setup.
If agentcore/agentcore.json is not found:
"This skill requires an AgentCore project. Use
agents-get-startedto create one."
Step 2: Determine the workflow
| Developer intent | Action |
|---|---|
| Measure quality, add evaluator, run eval, CI/CD gate, online monitoring | Load references/evals.md and follow its workflow |
| Set up observability, CloudWatch, X-Ray, logs, metrics, dashboards | Load references/observability.md and follow its workflow |
| Understand or reduce AgentCore costs | Load references/cost.md |
| Both — "I want to understand and improve my agent" | Start with observability setup, then add evals |
Step 3: Follow the loaded reference
The reference file contains the full procedure. Follow it step by step.
Cross-references
After setting up evals, suggest
agents-hardenfor production readinessIf eval results reveal agent issues, suggest
agents-debugfor root cause analysisIf the developer needs to add capabilities first, suggest
agents-build
Output
Depends on the workflow — see the loaded reference for specific outputs.
Quality criteria
Evaluator configuration uses only valid CLI flags
Online eval sampling rate is appropriate (not 100% in production without discussion)
CI/CD quality gate has a clear pass/fail threshold
Observability setup includes both tracing and logging
The developer understands the eval data delay: ~10 seconds put-to-get, end-to-end — one ingestion step covers both trace reads and eval queries; there is no separate indexing wait
Files
- ATTRIBUTION.mdAdded by AutoGineer1020 B
- LICENSELicence file added by AutoGineer9.9 KiB
- NOTICELicence file added by AutoGineer67 B
- SKILL.md3.6 KiB
- references/cost.md7.0 KiB
- references/evals.md20.6 KiB
- references/observability.md5.8 KiB
references/observability.md
Observability Setup
Set up logging, tracing, and monitoring for your AgentCore agent.
What's auto-enabled
AgentCore automatically enables:
X-Ray tracing — every invocation generates a trace
CloudWatch logging — agent logs ship to CloudWatch
These are on by default whether you're running deployed (agentcore deploy + invoke) or locally (agentcore dev). The dev server auto-instruments your agent with the AWS OpenTelemetry distro the same way the deployed runtime does; opt out with agentcore dev --no-traces.
Two prerequisites for the local path to work end-to-end:
AWS credentials available locally — the OTEL exporter needs them to ship spans.
CloudWatch Transaction Search is enabled on the account (one-time setup per account) — see "Viewing traces" below. Without it, spans are ingested but not searchable, so
agentcore traces listandagentcore run eval --session-idreturn empty.
After deploy, AgentCore Runtime also auto-instruments the container (the default CMD wraps the app with opentelemetry-instrument). You don't need to configure OTEL in your code for either path — but you do need your agent code to be instrumented correctly.
Ensuring logs appear in CloudWatch
Three things must be true for logs to appear:
1. OTEL entrypoint wrapper in Dockerfile
Your Dockerfile CMD must use the OpenTelemetry wrapper:
CMD ["opentelemetry-instrument", "python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]For CodeZip builds, this is handled automatically. For Container builds, you must add it.
2. IAM permissions for CloudWatch and X-Ray
Your runtime execution role needs:
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"xray:PutTraceSegments",
"xray:PutTelemetryRecords"
],
"Resource": "*"
}3. Use the logging module, not print()
AgentCore captures structured logs via the Python logging module. print() statements go to stdout but are not captured by the OTEL pipeline.
import logging
logger = logging.getLogger(__name__)
# Good — captured by CloudWatch
logger.info("Processing request", extra={"session_id": session_id})
# Bad — not captured
print(f"Processing request {session_id}")Viewing traces
Traces show the full execution path of one agent invocation — model calls, tool calls, and timing.
# List recent traces
agentcore traces list --runtime <AgentName> --since 1h --limit 10
# Get a specific trace
agentcore traces get <traceId> --runtime <AgentName>Trace delay: Traces appear ~10 seconds after invocation (previously 30–60s). Don't panic if they're not immediate, and don't bake longer waits into scripts — older skills and docs that say "30–60 seconds" or "2–5 minutes" are stale.
Also verify Transaction Search is enabled in CloudWatch — this is a prerequisite for trace visibility in the console.
Viewing logs
# Stream recent logs
agentcore logs --runtime <AgentName> --since 30m
# Filter by level
agentcore logs --runtime <AgentName> --level error --since 1h
# Search for specific text
agentcore logs --runtime <AgentName> --query "timeout" --since 2hCloudWatch dashboard
For production agents, set up a CloudWatch dashboard with:
Invocation count and error rate
P50/P90/P99 latency
Memory and CPU utilization
Error log count by type
These metrics are available in the AWS/BedrockAgentCore namespace after deploy.
Multi-account observability
If your agents are spread across accounts (typical setup: separate prod / staging / dev accounts), use CloudWatch cross-account observability to view metrics, traces, and logs from one central monitoring account.
The setup order matters — do it in this sequence or the console won't show source-account data:
Pick a monitoring account. This is where you'll view everything. Often a central observability account, not a workload account.
Configure the monitoring account first. CloudWatch console → Settings → Monitoring account configuration → Configure. Choose which telemetry types to share (enable Metrics and Logs — traces go through X-Ray's own cross-account mechanism).
Link each source account. Either via AWS Organizations (if your accounts are in one) or via individual linking. Source accounts must accept the link.
Deploy AgentCore agents in the source accounts with observability enabled — same default OTEL wrap-up as single-account. No code changes needed.
View from the monitoring account. AgentCore Observability in the CloudWatch console now shows data from all linked accounts side-by-side, identified by source account ID.
Order-of-operations trap: if you deploy agents in source accounts before linking, the telemetry still flows correctly — it just won't be visible from the monitoring account until the link is active. You don't need to redeploy, just wait a few minutes after linking.
Traces: cross-account trace viewing uses X-Ray's existing cross-account sharing model. If the CloudWatch cross-account link is set up correctly for Logs and Metrics but traces don't show, check X-Ray's cross-account config separately.
IAM: no extra IAM on the agent execution roles for cross-account observability. The cross-account feature operates at the CloudWatch/X-Ray layer, not at the source of the telemetry.
See cross-account observability for the current console flow and edge cases.
Cross-references
If logs aren't appearing at all, check the three requirements above or use
agents-debugFor production observability setup, see
agents-hardenFor measuring agent quality (not just operational health), load
references/evals.md
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Declares allowed tools
Security
No issues found by our static scan· No issues found
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- aws-agentcore
- Publisher
- AWS (Official)
- Source
- aws/agent-toolkit-for-aws · plugins/aws-agents/skills/agents-optimize · commit 0a218f8
- Licence
- Apache License 2.0 (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- NOTICE (added by AutoGineer from NOTICE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by aws-agentcore or AWS.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download agents-optimize.zip