WAF-AGN-090 β Cost & Performance Monitoring
Description
Agent operations must be economic and performant. Token usage and compute costs must be monitored. Budget alerts must be configured to prevent cost overruns. Model selection must be optimized for cost-performance tradeoffs. Efficient caching and context management must be implemented.
Rationale
Agent costs can spiral quickly without proper monitoring:
Budget overruns: LLM API costs can exceed budgets quickly without caps and alerts.
Wasted resources: Inefficient prompting and context management waste tokens.
Model misselection: Using expensive models for simple tasks increases costs unnecessarily.
No visibility: Without metrics, cannot identify optimization opportunities.
Performance degradation: Latency issues may go undetected without monitoring.
Requirements
-
Token usage (input, output, total) must be tracked with daily aggregation
-
Budget alerts must be configured at 50%, 75%, 90%, and 100% of budget
-
Model selection must be optimized for cost-performance tradeoff
-
Caching must be implemented to reduce redundant API calls
-
Performance metrics (latency, error rates) must be monitored
Implementation Guidance
-
Set up cost budgets: Configure AWS Cost Explorer or similar budgeting
-
Create alerts at thresholds: Set SNS notifications at budget percentages
-
Optimize model selection: Match model capabilities to task complexity
-
Implement caching layer: Use Redis/ElastiCache or DynamoDB for responses
-
Monitor token efficiency: Track tokens per successful outcome
Maturity Levels
| Level | Name | Criteria |
|---|---|---|
1 |
No Monitoring |
No cost tracking. No budget alerts. No performance monitoring. |
2 |
Basic Logging |
Manual cost tracking. Simple alerts. |
3 |
Full Monitoring |
Automated token tracking. Budget alerts configured. Performance dashboards. |
4 |
Optimization Enabled |
Automated model selection based on task. Intelligent caching. |
5 |
Predictive Optimization |
AI predicts optimal model and caching strategies. |
Terraform Checks
waf-agn-090.tf.aws.token-monitoring-configured
Checks: Agent token usage is monitored and alerts configured.
| Compliant | Non-Compliant |
|---|---|
|
No token monitoring configured |
waf-agn-090.tf.aws.budget-alerts-configured
Checks: Budget alerts configured for agent costs.
# Compliant
resource "aws_budgets_budget" "agent_budget" {
budget_name = "agent-monthly-budget"
budget_type = "COST"
limit_amount = "500"
limit_unit = "USD"
time_unit = "MONTHLY"
notification {
notification_type = "ACTUAL"
comparison_operator = "GREATER_THAN"
threshold = 50
threshold_type = "PERCENTAGE"
subscriber_email_addresses = ["team-ops@example.com"]
}
}
Remediation: Configure token monitoring for input, output, and total tokens. Set up budget alerts at multiple thresholds. Implement model optimization and caching.
Evidence
| Type | Required | Description |
|---|---|---|
IaC |
β Required |
Budget configuration, metric alarms, dashboard definitions. |
Config |
β Required |
Budget thresholds, alert channels, cache configuration. |
Process |
β Required |
Cost analysis reports, budget review records, optimization plans. |
Governance |
β Required |
Cost management policy defining requirements and approval processes. |
Regulatory Mapping
| Framework | Controls |
|---|---|
ISO 27001:2022 |
A.8.2 β Privileged access rights; A.12.1 β Control of operational software |
NIST SP 800-53 |
SC-5 β Resource availability; SC-39 β Process isolation |
NIST CSF 2.0 |
DE.CM β Continuous monitoring; DE.AE β Anomalies and events |
GDPR |
Art. 32 β Security of processing; Art. 5(1)(f) β Integrity and confidentiality |
PCI DSS v4.0 |
Req 10 β Monitor and detect threats |
TISAX |
Information security β Monitoring and logging |
ANSSI SecNumCloud |
Domain β Logging and monitoring |
BIO |
BIO β Logboekhouding en monitoring |
ENS High |
op.exp.6 β GestiΓ³n de cambios |
UK NCSC CAF |
A4 β Policy and assurance |
FedRAMP |
SC-5, SC-39 (Moderate baseline) |
CMMC 2.0 |
SC.L2-3.8.1 β Limit information system use |
IT-Grundschutz |
ORP.1 β Informationstechnisch-related Angriffsschutz |
IRAP |
ISM β Logging and monitoring |
CCCS PBMM |
SC-5 β Resource availability |
MAS TRM |
Ch.9 β Change management |
ISMAP |
Monitoring and logging controls |
FISC |
Technical measures β Logging and monitoring |
AWS Well-Architected Framework |
Financial Accountability Pillar β Cost optimization; Reliability Pillar β Resource management |
Google Cloud Architecture Framework |
Cost Management β Budgets and alerts; Performance β Optimization |
BSI C5:2020 |
OPS-01 β Operational monitoring |
SOC 2 Type II |
CC4.1 β Monitoring activities; CC7.1 β Infrastructure and software monitoring |
CSA STAR |
CCM Logging and Monitoring |
CIS Controls v8 |
CIS 10 β Data Accuracy |