Inspiration

As developers, we often focus on making software functional, scalable, and reliable, but we don't always think about how much computing power our code consumes.

Inefficient database queries, redundant calculations, and poorly optimized loops might seem like small problems, but when applications handle thousands or millions of requests, these inefficiencies add up. They increase CPU usage, execution time, and infrastructure costs, which can also lead to higher energy consumption and carbon emissions.

This made us think: What if AI could help developers write more energy-efficient code without taking control away from them?

That question inspired us to build Green Bob, an AI-powered code optimization agent that combines software performance engineering, sustainability, and human oversight.

What it does

Green Bob is an AI-powered agent that detects inefficient code, recommends optimizations, and measures their impact, while keeping developers in control of every change.

Instead of simply flagging inefficient code, Green Bob takes the optimization process further. It analyzes the codebase for performance bottlenecks such as N+1 database queries, unnecessary computations, and inefficient loops. It then explains why the code is inefficient and generates a proposed patch.

Before modifying anything, Green Bob requires explicit approval from the developer. Once approved, the agent applies the change in an isolated Git worktree and runs safety tests to verify that the application's functionality remains intact.

Finally, Green Bob benchmarks the application before and after optimization, allowing developers to see measurable improvements in performance and estimated environmental impact.

Our goal is to make sustainable software development more practical by integrating energy awareness into the code optimization process.

How we built it

We developed Green Bob using Python, LangGraph, Flask, pytest, CodeCarbon, Git worktrees, and IBM Bob.

At the core of Green Bob is a stateful agent workflow orchestrated using LangGraph:

Detect → Protect → Propose → Human Approval → Apply → Verify → Measure → Report

Each stage handles a specific part of the optimization process.

  • Detect: Analyzes source code to identify inefficient patterns and potential performance bottlenecks.
  • Protect: Establishes safety tests to capture the application's expected behavior before any changes are made.
  • Propose: Generates an optimization patch and explains the reasoning behind the recommended changes.
  • Human Approval: Pauses execution until a developer explicitly approves or rejects the proposed fix.
  • Apply: Applies approved modifications in an isolated Git worktree to avoid affecting the original codebase.
  • Verify: Uses pytest to check that the optimized code still passes the application's safety tests.
  • Measure: Compares performance metrics before and after optimization, including database query counts and estimated energy consumption using CodeCarbon.
  • Report: Presents the results so developers can evaluate whether the optimization delivered meaningful improvements.

We used Flask to support the backend API and connect the agent's workflow to the application.

To demonstrate Green Bob, we also developed ShopLite, a sample application containing intentionally inefficient database operations and code patterns. This gave us a controlled environment to test the agent, validate proposed fixes, and measure performance improvements using repeatable workloads.

Challenges we ran into

One of our biggest challenges was figuring out how to accurately measure the environmental impact of software optimizations.

Unlike execution time or database query counts, energy consumption and CO₂ emissions are influenced by several external factors, including CPU utilization, hardware configuration, workload duration, and the energy mix powering the system.

We integrated CodeCarbon to estimate energy usage and carbon emissions, but we also recognized that these values are estimates rather than exact measurements. To make our comparisons more meaningful, we focused on repeatable workloads and measurable performance metrics before and after each optimization.

Another major challenge was ensuring that improving performance did not come at the cost of correctness.

An AI-generated patch might reduce execution time while unintentionally changing application behavior. To address this, we implemented automated safety tests, isolated Git worktrees, and a mandatory human approval step.

We also had to coordinate multiple stages of the agent's execution, including pausing for approval, applying changes, handling test results, and reporting performance metrics. LangGraph helped us structure these steps into a controlled workflow.

What we learned

Building Green Bob gave us a better understanding of how closely software efficiency, infrastructure utilization, and sustainability are connected.

One of our biggest takeaways was how quickly small inefficiencies can scale. A database query inside a loop may work perfectly fine with a few records, but under heavier workloads, that same pattern can generate thousands of unnecessary queries.

We also learned that software optimization is not just about writing faster code. It involves understanding how applications interact with databases, measuring resource consumption, maintaining consistent functionality, and validating changes through automated testing.

On the AI side, we gained hands-on experience building a stateful agent using LangGraph, coordinating tool-driven operations, and implementing human-in-the-loop approval.

Most importantly, we learned that AI-generated optimizations should be treated as engineering proposals, not automatically trusted solutions. Every proposed change still needs verification, measurable results, and developer oversight.

What's next for Green Bob

Our next goal is to turn Green Bob from a working prototype into a tool that developers can confidently integrate into their everyday development workflows.

We plan to expand its detection capabilities beyond inefficient database queries and loops to identify issues such as redundant API calls, excessive memory allocation, unnecessary polling, and other resource-intensive operations.

We also want to develop a VS Code extension that allows developers to scan their code, review optimization suggestions, and approve changes directly within their development environment. In addition, we hope to integrate Green Bob with GitHub pull requests and CI/CD pipelines to help identify performance issues before code reaches production.

Another major priority is improving security, privacy, and user trust. We understand that developers may be hesitant to give an AI agent access to their source code, especially when working with sensitive files or private repositories. To address this, we want to introduce stronger security measures, including fine-grained file permissions, explicit user consent before scanning, secure code processing, and improved isolation of AI-generated changes. We also want to explore local code analysis, so developers have greater control over how their source code is accessed and processed.

Our vision is for Green Bob to operate with the principle that developers should always know what the AI is accessing, what changes it recommends, and what actions it is allowed to perform. Green Bob should never modify files without permission, and users should be able to review, reject, or revert changes when necessary.

On the sustainability side, we want to improve energy and carbon measurements, support benchmarking across different environments, and provide more detailed performance reports.

Ultimately, we want Green Bob to become a secure, privacy-conscious, and trustworthy AI development assistant that helps teams build software that is efficient, reliable, and environmentally responsible, without compromising the security of their code or taking control away from developers.

Built With

Share this project:

Updates

Submission history