Lightweight cognitive load monitoring primitive for AI agents
Project description
Cognitive Load Monitor
A lightweight, drop-in Python module for AI agents to self-report cognitive load using observable runtime metrics. Designed for operational reliability and external orchestration (throttling, cloning, load balancing).
Installation
pip install cognitive-load-monitor
Quick Start
from cognitive_load_monitor import CognitiveLoadMonitor
# Initialize monitor
monitor = CognitiveLoadMonitor()
# Record agent state and get load report
report = monitor.record(
tokens_used=1500,
tokens_budget=2000,
reasoning_steps=8,
latency_ms=450,
unresolved_assumptions=2,
total_assumptions=5,
)
# Check load status
print(f"Load Index: {report.load_index:.2f}")
print(f"Trend: {report.trend.value}")
if report.is_overloaded():
# Signal orchestrator to throttle or clone agent
emit_signal("THROTTLE", report.to_dict())
What is Cognitive Load?
In this context, cognitive load is an operational reliability metric—not a philosophical concept. It measures resource constraints and processing stress that affect agent performance, similar to:
- CPU/memory pressure in systems monitoring
- Queue depth in message brokers
- Latency percentiles in web services
Metrics
The monitor computes a normalized Cognitive Load Index (0–1) using five proxy metrics:
1. Context Pressure (0–1)
Ratio of tokens used to budget. Measures memory/context constraints.
2. Reasoning Complexity (0–1)
Normalized combination of reasoning steps and backtracking. High values indicate difficult problem-solving.
3. Temporal Stress (0–1)
Ratio of actual latency to expected latency. Measures time pressure and processing delays.
4. Uncertainty (0–1)
Ratio of unresolved to total assumptions. High values indicate ambiguity or missing information.
5. Error Recovery (0–1)
Ratio of self-corrections to total operations. Measures instability and rework overhead.
Configuration
Custom Weights
from cognitive_load_monitor import CognitiveLoadMonitor, MetricWeights
# Define custom weights (must sum to 1.0)
weights = MetricWeights(
context_pressure=0.30,
reasoning_complexity=0.30,
temporal_stress=0.20,
uncertainty=0.10,
error_recovery=0.10,
)
monitor = CognitiveLoadMonitor(weights=weights)
Trend Detection
monitor = CognitiveLoadMonitor(
history_window=15, # Track last 15 samples
trend_threshold=0.08, # Sensitivity for rising/falling detection
)
Use Cases
Multi-Agent Orchestration
# Load balancer decides which agent gets next request
agents = [agent1, agent2, agent3]
loads = [a.monitor.get_current_load() for a in agents]
selected = agents[loads.index(min(loads))]
Dynamic Model Selection
report = monitor.record(...)
if report.load_index < 0.3:
model = "gpt-4o-mini" # Use cheaper model for low-load tasks
elif report.load_index > 0.7:
model = "gpt-4o" # Use powerful model for high-load tasks
Quality Gates
if report.is_rising_fast(threshold=0.6):
# Escalate to human review
escalate_to_human(task, report)
Cost Optimization
# Track load vs output quality for capacity planning
metrics_db.log({
"load_index": report.load_index,
"output_quality": evaluate_output(result),
"cost": compute_cost(tokens_used),
})
API Reference
CognitiveLoadMonitor
__init__(weights=None, history_window=10, trend_threshold=0.05)
Initialize monitor with optional custom configuration.
record(**kwargs) -> CognitiveLoadReport
Record current agent state and compute load report.
Parameters:
tokens_used(int): Current token count consumedtokens_budget(int): Maximum tokens availablereasoning_steps(int): Number of reasoning steps takenmax_reasoning_steps(int): Expected maximum stepsbacktrack_count(int): Number of backtracks/revisionslatency_ms(float): Actual processing time in millisecondsexpected_latency_ms(float): Baseline expected latencyunresolved_assumptions(int): Count of uncertain assumptionstotal_assumptions(int): Total assumptions madeself_corrections(int): Number of self-correctionstotal_operations(int): Total operations attempted
reset_history()
Clear historical data. Useful when agent context resets.
get_current_load() -> Optional[float]
Get most recent load index, or None if no data.
CognitiveLoadReport
to_dict() -> dict
Convert report to dictionary for serialization.
is_overloaded(threshold=0.75) -> bool
Check if cognitive load exceeds threshold.
is_rising_fast(threshold=0.60) -> bool
Check if load is rising and already above threshold.
Attributes:
timestamp: Unix timestamp when report was generatedload_index: Normalized cognitive load score (0.0–1.0)trend: Direction of load change (LoadTrendenum)metrics: Raw metric values used to compute load_indexweights: Weight configuration used for this reporthistory_size: Number of historical samples
Design Philosophy
- Treat cognitive load as an operational signal, not a philosophical concept
- Use only metrics an agent can observe at runtime
- No inspection of chain-of-thought or model internals
- Simple, transparent, configurable
- Zero external dependencies
Non-Goals
This module intentionally does NOT include:
- Orchestration logic
- Networking or API calls
- Dashboards or visualization
- Logging frameworks
It's a primitive building block for you to integrate into your infrastructure.
License
All Rights Reserved
Free to use for non-commercial and free applications.
For commercial use, please contact Synapse Data.
Requirements
- Python 3.10+
- No external dependencies
Contributing
This is a commercial product by Synapse Data. For feature requests or commercial licensing inquiries, please contact us.
Support
For issues or questions:
- Open an issue on GitHub
- Contact: Synapse Data
Built by Synapse Data • Production-quality infrastructure for AI agents
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cognitive_load_monitor-0.1.0.tar.gz.
File metadata
- Download URL: cognitive_load_monitor-0.1.0.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7449e79aa438fbc2e6a0e80d3f247e44f54d443bbfb5aa0fd3b2ce393b9c69da
|
|
| MD5 |
87f2f7254d5d0df11f6f3788f8fff049
|
|
| BLAKE2b-256 |
6f5f098db7942a9516956f06322709c02208bb05ca5843d64c481d454b551b25
|
File details
Details for the file cognitive_load_monitor-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cognitive_load_monitor-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3ae8112414a71f2142bc02753ca08582fca49b43e5be5f2044aa1919b6b40d8
|
|
| MD5 |
08e4ea109c93f171bb6e3c5b18af57f0
|
|
| BLAKE2b-256 |
aa35bfee69a9d62b32b198f69ef62907662397ca7673a48ecac1d800d87c7426
|