Skip to main content

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

Release files for jamanota 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jamanota 0.1.0
File Size Uploaded
jamanota-0.1.0.tar.gz 9.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jamanota 0.1.0
File Interpreter ABI Platform
jamanota-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.4 kB

Release files / jamanota-0.1.0.tar.gz

Download URL jamanota-0.1.0.tar.gz
Size 9.0 kB
Tags Source
SHA-256 checksum
How to use checksums
2099f15178a2f53664a1c3edcbb294bd2a52f2a0927f1d0358ac56d6ff9331ab
BLAKE2b-256 checksum
How to use checksums
0fb0ef27c640709418de7c4d7987b4eed94c34212d0b3ed4d9815ab30793b2a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Release files / jamanota-0.1.0-py3-none-any.whl

Download URL jamanota-0.1.0-py3-none-any.whl
Size 8.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6e68af9248e22cd8a231de902e6805bf39cc34d8a20103e27fc7b2ce73605e47
BLAKE2b-256 checksum
How to use checksums
6c200f7af3f20efcadc7ff4d67f03732717073674ab336c82accd4a2b7436b19
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page