[COORD-002] Build basic context monitor #155

Closed
opened 2026-01-31 21:06:30 +00:00 by jason.woltje · 0 comments
Owner

Objective

Build a context monitoring service that tracks agent token usage in real-time and identifies threshold crossings.

Implementation Details

Implement continuous monitoring from Part 1.

The ContextMonitor class should:

  • Define COMPACT_THRESHOLD at 0.80 (80% triggers compaction)
  • Define ROTATE_THRESHOLD at 0.95 (95% triggers rotation)
  • Poll Claude API for context usage
  • Return appropriate ContextAction based on thresholds
  • Log usage over time
  • Background monitoring loop (10-second polling)

Context Estimate

  • Files to modify: 2 (context_monitor.py, models.py)
  • Implementation complexity: medium (20,000 tokens)
  • Test requirements: medium (10,000 tokens)
  • Documentation: medium (3,000 tokens)
  • Total estimated: 49,400 tokens
  • Recommended agent: glm

Difficulty

medium

Acceptance Criteria

  • ContextMonitor class implemented with thresholds
  • Real-time polling of Claude API context usage
  • Accurate detection of 80% and 95% thresholds
  • Background monitoring loop functional
  • Logging of context usage over time
  • Unit tests (85% coverage minimum)

Testing Requirements

  • Mock Claude API responses for different usage levels
  • Test threshold detection accuracy (80%, 95%)
  • Test background monitoring loop
  • Test error handling when API unavailable
  • Coverage: 85% minimum
## Objective Build a context monitoring service that tracks agent token usage in real-time and identifies threshold crossings. ## Implementation Details Implement continuous monitoring from Part 1. The ContextMonitor class should: - Define COMPACT_THRESHOLD at 0.80 (80% triggers compaction) - Define ROTATE_THRESHOLD at 0.95 (95% triggers rotation) - Poll Claude API for context usage - Return appropriate ContextAction based on thresholds - Log usage over time - Background monitoring loop (10-second polling) ## Context Estimate - Files to modify: 2 (context_monitor.py, models.py) - Implementation complexity: medium (20,000 tokens) - Test requirements: medium (10,000 tokens) - Documentation: medium (3,000 tokens) - Total estimated: 49,400 tokens - Recommended agent: glm ## Difficulty medium ## Acceptance Criteria - ContextMonitor class implemented with thresholds - Real-time polling of Claude API context usage - Accurate detection of 80% and 95% thresholds - Background monitoring loop functional - Logging of context usage over time - Unit tests (85% coverage minimum) ## Testing Requirements - Mock Claude API responses for different usage levels - Test threshold detection accuracy (80%, 95%) - Test background monitoring loop - Test error handling when API unavailable - Coverage: 85% minimum
jason.woltje added the apiapip0phase-1 labels 2026-01-31 21:06:30 +00:00
jason.woltje added this to the M4.1-Coordinator (0.0.4) milestone 2026-01-31 21:10:04 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mosaic/stack#155