EcoAgent / README.md
OpelSpeedster's picture
Update README.md
5da3721 verified
|
Raw
History Blame Contribute Delete
8.5 kB

A newer version of the Gradio SDK is available: 6.26.0

Upgrade
metadata
title: EcoAgent
emoji: ๐ŸŒฑ
colorFrom: green
colorTo: blue
sdk: gradio
sdk_version: 6.20.0
app_file: app.py
pinned: true

๐ŸŒฑ EcoAgent โ€” AI-Powered Eco Lifestyle Assistant

An sustainable assistant for India powered by IBM Granite via watsonx.ai. Chat about eco habits, explore a household impact dashboard, look up local recycling guides, and build a family sustainability profile.

Classification: Agentic AI Application with Prompt Engineering


Features

Tab What it does
๐Ÿ’ฌ Chat Multi-turn conversation with IBM Granite โ€” personalised eco tips, government schemes, impact estimates. Agent Mode enables multi-step reasoning with 5 tools.
๐Ÿ“Š Dashboard Session-based eco score (0โ€“100), COโ‚‚/water/waste savings tracker, household summary
โ™ป๏ธ Recycling Guide City-specific recycling instructions for 8 material categories + eco-friendly product alternatives
๐Ÿก Profile Household members, Indian city, current eco habits โ€” personalises all chat responses

Agent Mode

EcoAgent features an agentic AI loop that can use tools to provide accurate, data-driven answers:

Tool Purpose
๐Ÿงฎ Impact Calculator Get exact COโ‚‚/water/waste numbers for eco actions
โ™ป๏ธ Recycling Guide City-specific recycling instructions
๐Ÿ” Web Search Search latest news, schemes, local services
๐Ÿ›๏ธ Scheme Checker Indian government scheme details and eligibility
๐Ÿ‘ฅ Household Profiler Personalized action plan based on profile

How it works:

  1. Enable "Agent Mode" checkbox in Chat tab
  2. Ask a question
  3. Agent reasons step-by-step, calls tools as needed
  4. See which tools were used below the response

Date Accuracy Fix:

  • System prompt includes TODAY'S DATE so the LLM knows the current date
  • Web search results include Search conducted on: <date> header
  • LLM is instructed to trust search results over its training data
  • Prevents hallucinated outdated dates like "August 2025"

๐Ÿ’ช Effort Behind This Project

This project is the result of a full v2 rebuild with focused work across product design, AI integration and UX:

  • Replaced the older pipeline with a new watsonx_client.py architecture using IBM Granite + watsonx.ai SDK.
  • Designed and built a complete 4-tab Gradio application (Chat, Dashboard, Recycling Guide, Profile).
  • Created impact tracking logic (eco score + COโ‚‚/water/waste calculations) with session-aware state handling.
  • Added India-focused sustainability guidance, recycling flows, and household personalization.
  • Reworked environment setup, dependency management, and deployment readiness for Hugging Face Spaces.

In short: this is not a template drop-in โ€” it reflects significant end-to-end implementation effort from planning to delivery.


Architecture

.env  (WATSONX_API_KEY, WATSONX_PROJECT_ID, WATSONX_URL)
        โ”‚
        โ–ผ
watsonx_client.py   โ† IBM Granite ModelInference, AGENT_INSTRUCTIONS, IMPACT_TABLE
        โ”‚
        โ–ผ
tools.py            โ† 5 tool definitions, executor, scheme database
        โ”‚
        โ–ผ
agent.py            โ† Agentic loop with multi-step reasoning
        โ”‚
        โ–ผ
app.py              โ† Gradio Blocks (4 tabs, ultra-light eco green theme, session state)

Model: ibm/granite-4-h-small (eu-de region, watsonx.ai)
Auth: IBM Cloud API key โ†’ watsonx.ai SDK (no Orchestrate REST API)


How It Works

EcoAgent uses prompt engineering + agentic AI to transform IBM Granite into a domain-specific eco advisor:

  1. System Prompt: 86-line AGENT_INSTRUCTIONS defining persona, output format, focus areas, and guardrails
  2. Static Knowledge: IMPACT_TABLE (20 eco actions) and PRODUCT_RECS (8 material categories) injected via prompt
  3. Dynamic Context: Household profile (members, location, habits) injected per session
  4. Agent Loop: Multi-step reasoning with tool calls (max 5 iterations)
  5. Tool Execution: Real-time tool calls with result feedback
  6. Date Injection: Current date injected into system prompt and search results for accuracy
  7. Output Format: Fixed 4-part structure (Quick Tip โ†’ Why it Matters โ†’ Impact โ†’ Optional Resource)
  8. Guardrails: Never invent stats, label [Lookup] vs [Estimate], no medical/financial advice

UI Theme

Ultra-light eco green theme with near-white background and green accents:

  • Background: #fcfcfd (near white)
  • Primary accent: #2e7d50 (green)
  • Cards: #ffffff with subtle shadows
  • Text: #1c1c1e (near black), muted: #4a4a4e
  • Borders: #e4e4e7 (light gray)
  • CheckboxGroup styled as selectable pills/chips

Environment Variables

Set these as Secrets in your Hugging Face Space (Settings โ†’ Variables and Secrets)
or in a local .env file (never commit with real values).

Variable Required Description
WATSONX_API_KEY โœ… IBM Cloud API key โ€” get one here
WATSONX_PROJECT_ID โœ… watsonx.ai Studio Project ID (UUID) โ€” see below
WATSONX_URL โœ… watsonx.ai endpoint for your region โ€” default https://eu-de.ml.cloud.ibm.com

How to get WATSONX_PROJECT_ID

  1. Go to https://eu-de.dataplatform.cloud.ibm.com
  2. Create or open a project
  3. Click the Manage tab โ†’ General section
  4. Copy the Project ID (a UUID like xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
  5. Add it to .env as WATSONX_PROJECT_ID=<your-uuid>

Regional watsonx.ai URLs

Region URL
EU Frankfurt (default) https://eu-de.ml.cloud.ibm.com
US Dallas https://us-south.ml.cloud.ibm.com
UK London https://eu-gb.ml.cloud.ibm.com
Japan Tokyo https://jp-tok.ml.cloud.ibm.com
Australia Sydney https://au-syd.ml.cloud.ibm.com

Local Development

Prerequisites

  • Python 3.10+ (Python 3.14 via uv is configured in .venv)
  • uv (recommended) or pip

Steps

# 1. Clone the repo
git clone https://huggingface.co/spaces/<your-username>/ecoagent
cd ecoagent

# 2. Install dependencies
uv pip install -r requirements.txt
# or: pip install -r requirements.txt

# 3. Configure credentials
# Copy .env.example to .env and fill in your values:
cp .env.example .env
# Edit .env โ€” set WATSONX_API_KEY, WATSONX_PROJECT_ID, WATSONX_URL

# 4. Run
uv run python app.py
# โ†’ Open http://localhost:7860

Customising the Agent

Open watsonx_client.py and edit the AGENT_INSTRUCTIONS constant at the top of the file. You can change:

  • Persona & tone โ€” make it more formal, more playful, multilingual, etc.
  • Focus areas โ€” add specific sustainability topics (e.g. marine conservation)
  • India-specific context โ€” add regional schemes, local brands, city-specific advice
  • Safety rules โ€” tighten or relax what the agent will/won't say
  • Answer structure โ€” change the tip โ†’ why โ†’ impact โ†’ resource format

The IMPACT_TABLE dict below it controls the carbon/water/waste numbers shown in the Dashboard tab โ€” add new actions or update existing values there.


Project Files

File Purpose
app.py Gradio Blocks UI โ€” 4 tabs, callbacks, CSS theme
watsonx_client.py IBM watsonx.ai SDK wrapper, agent config, impact data
tools.py Agent tool definitions, executor, scheme database
agent.py Agentic loop with multi-step reasoning
requirements.txt Pinned Python dependencies (5 packages)
.env Local credentials (gitignored)
.env.example Template โ€” safe to commit
ecoagent-plan.md Implementation plan and architecture decisions
architecture.png Architecture blueprint diagram
fill.txt PPT content fill for presentation

Disclaimer

Answers are AI-generated by IBM Granite. Impact figures labelled [Lookup] are sourced from IPCC AR6, BEE India, and CPCB data. Figures labelled [Estimate] are model-generated approximations. Always verify government schemes and legal/financial details with official sources.