Energy and CO2 tracking middleware for LangChain LLM agents
Project description
Jamanota Energy Middleware is a lightweight Python middleware for tracking energy consumption and CO₂ emissions of LLM-based agent systems in LangChain.
It integrates with agent frameworks to record token usage, estimated energy consumption, and environmental impact for every model call.
Overview
Modern AI systems, especially multi-agent LLM workflows, can involve complex chains of model calls. Understanding their computational cost and environmental impact is increasingly important.
Jamanota provides:
Transparent tracking of token usage
Energy estimation based on model size and compute assumptions
CO₂ emissions estimation using global carbon intensity
Key Features
Plug-and-play middleware for agent systems
Tracks input/output tokens, energy (J), and CO₂ (kg)
Supports nested agent calls via prompt tracking
Works with multi-agent architectures
Thread-safe and lightweight
Provides structured outputs via jamanota.middleware.EnergyDataPoint
Installation
pip install jamanota
Quick Example
Start tracking energy usage in your agent system in just a few lines:
from langchain.agents import create_agent
from langchain_ollama import ChatOllama
from jamanota.middleware import EnergyMiddleware
tracker = EnergyMiddleware()
# Attach to your agent
agent = create_agent(
model=ChatOllama(model="qwen3.5:2b"),
middleware=[tracker],
name="MyAgent"
)
# Run your system
agent.invoke({
"messages": [
{
"role": "user",
"content": "What is the capital of Italy?"
}
]
})
The energy middleware tracker will be called after all model calls, including nested ones, and will log token usage, energy, and CO₂ for each call.
Thereafter, each model call produces a jamanota.middleware.EnergyDataPoint containing:
Token usage (input/output)
Estimated energy consumption
Estimated CO₂ emissions
Model name and timestamp
Associated prompt ID and agent
Use Cases
Jamanota may be useful for:
🔬 Research on efficient AI systems
🌱 Measuring environmental impact of LLMs
🤖 Adaptive multi-agent systems based on real-time energy usage
🧪 Profiling experimental pipelines
Documentation
Detailed documentation is available at https://jamanota.readthedocs.io/en/latest/.
Contributing
Contributions are welcome! You can help by:
Reporting bugs via GitHub Issues
Suggesting new features
Improving documentation
Development Setup:
From the root directory, install the package in editable mode:
pip install -e .
Running Tutorials:
Before running examples:
Install Ollama
Download models:
qwen3.5:2b
qwen3.5:4b
Install dependencies:
pip install -r tutorials/requirements.txt
For detailed instructions regarding the installation process, please refer to the multi-agent tutorial documentation.
Example Scripts:
Run the multi-agent example:
python tutorials/sample_queries.py
Or, launch the dashboard:
streamlit run tutorials/streamlit_visualisation.py
Building the Documentation:
First, install documentation dependencies:
pip install sphinx sphinx-rtd-theme
Then, build the docs from the root directory:
make html
The built documentation will be available in the docs/build/html directory. You can open the index.html file in your browser to view it.
License
This project uses the MIT License
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 jamanota-0.1.0.tar.gz.
File metadata
- Download URL: jamanota-0.1.0.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2099f15178a2f53664a1c3edcbb294bd2a52f2a0927f1d0358ac56d6ff9331ab
|
|
| MD5 |
121cc5bc323f4166f043838dd8d160d8
|
|
| BLAKE2b-256 |
0fb0ef27c640709418de7c4d7987b4eed94c34212d0b3ed4d9815ab30793b2a5
|
File details
Details for the file jamanota-0.1.0-py3-none-any.whl.
File metadata
- Download URL: jamanota-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e68af9248e22cd8a231de902e6805bf39cc34d8a20103e27fc7b2ce73605e47
|
|
| MD5 |
b0f33c2a5aff63006a0f89f7a7d9119a
|
|
| BLAKE2b-256 |
6c200f7af3f20efcadc7ff4d67f03732717073674ab336c82accd4a2b7436b19
|