feat: OTel budget circuit-breaker for AWS AgentCore integration#2
feat: OTel budget circuit-breaker for AWS AgentCore integration#2up2itnow0822 wants to merge 2 commits intomainfrom
Conversation
Adds three new MCP tools for budget enforcement above AgentCore's observability layer: - otel_register_budget_policy: Set per-agent/per-task spend limits with configurable breach actions (warn/block/kill) - otel_evaluate_spend: Evaluate OTel span cost data against policies, returns enforcement decisions as OTel-compatible events - otel_budget_status: Query accumulated spend and policy utilization Why: AWS AgentCore Policy Controls (GA March 2026) provide observability but no native per-agent spend cap APIs. This module fills that gap by reading OTel span data and applying budget policies with circuit-breaker patterns. Includes comprehensive test suite covering: - Policy registration (agent-level and task-level) - Budget evaluation (allow/warn/block/kill decisions) - 90% utilization warning threshold - Task-level policy precedence over agent-level - OTel event attribute generation - Decision history and audit trail Refs: INTEL-CYCLE-196, INTEL-CYCLE-198
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 696a4aa897
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0e66c3c964
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return _spendLedger | ||
| .filter( | ||
| (r) => | ||
| r.agentId === agentId && | ||
| (taskId === undefined || r.taskId === taskId) && | ||
| r.timestamp >= cutoff | ||
| ) |
There was a problem hiding this comment.
Bound spend ledger growth to active policy windows
Each call to evaluateSpan appends to _spendLedger, and getAccumulatedSpend then scans the full array for every evaluation. Because old records are never pruned, long-running/high-throughput agents will see steadily increasing latency and memory usage, and can eventually OOM even when most entries are already outside every policy window and no longer relevant.
Useful? React with 👍 / 👎.
| budgetLimitUsd: Infinity, | ||
| remainingUsd: Infinity, |
There was a problem hiding this comment.
Avoid non-JSON numeric sentinels in allow decisions
The no-policy branch sets budgetLimitUsd and remainingUsd to Infinity, but handleOTelEvaluateSpend serializes decisions with JSON.stringify, which converts Infinity to null. Clients expecting numeric budget fields will receive null and can mis-handle arithmetic or schema validation in the common case where no policy is registered.
Useful? React with 👍 / 👎.
Summary
Adds an OpenTelemetry Budget Circuit-Breaker module that fills the gap left by AWS AgentCore Policy Controls (GA March 2026): observability without spend enforcement.
New MCP Tools
otel_register_budget_policyotel_evaluate_spendotel_budget_statusHow It Works
agentcore.cost.usd,gen_ai.usage.cost)killaction supports webhook callbacks to terminate runaway agent runsArchitecture
Test Coverage
Comprehensive test suite covering:
Context