Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧪 FarmAgent — Transparent Crop Advisory Agent (Built with Google ADK)

Code Hashnode Hackathon


📌 Current Status

The dashboard's Governor Log and Evidence Receipts panels are temporarily disabled while stability improvements are being rolled out.


🌱 What is FarmAgent?

FarmAgent is an LLM-driven crop advisory assistant built using the Google Agent Development Kit (ADK).

It provides a transparent workflow for:

  1. Understanding crop issues
  2. Generating a step-wise plan
  3. Executing tools (image analysis, lookup APIs, symptom matching)
  4. Synthesizing a final actionable recommendation

The system consists of:

  • Frontend → Flask reasoning dashboard
  • Backend → ADK-powered Planner → Governor → Executor → Synthesizer pipeline

🏗 Architecture

FarmAgent uses a strict separation between UI and agent logic, communicating via a safe Cloud-Run-friendly gateway.

Architecture Diagram

Key Components

  • agent_gateway.py — Secure bridge between UI and ADK backend
  • src/agent/orchestrator.py — Defines the FarmAgent_Orchestrator (SequentialAgent)
  • src/agent/advisor — Planner, Governor, Executor, Synthesizer, and prompts
  • src/agent/tools — Tools executed during plan execution
  • frontend/app.py — Flask server powering the UI & reasoning dashboard

🔄 End-to-End Workflow

Example query: "My tomato leaves are yellowing." (with image)

  1. User Input

    • Query + image uploaded via browser
    • Image saved temporarily → converted to file URI
  2. Frontend → Gateway

    • /run_plan → formats payload → sends to ADK backend
  3. Backend (ADK)

    • FarmAgent_Orchestrator executes the 4-stage pipeline
    • Planner creates JSON plan
    • Governor validates safety + sanity
    • Executor runs tools → logs receipts
    • Synthesizer generates final human-readable output
  4. Gateway → Frontend

    • Returns: final output, plan, receipts, execution metrics
  5. UI Updates

    • JS updates reasoning dashboard in real time

🎥 Demo Video

FarmAgent Video


🧰 Local Development Setup

Prerequisites

  • Python 3.10+
  • Google Cloud project with Vertex AI enabled

1. Authenticate

Recommended:

gcloud auth application-default login

Or use a service account:

GOOGLE_APPLICATION_CREDENTIALS=service-account-key.json

2. Install Dependencies

cd farmagent
python -m venv .venv

# Windows
.venv\Scripts\activate

# Mac/Linux
source .venv/bin/activate

pip install --upgrade pip
pip install -r requirements.txt

3. Configure .env

Rename .env.example.env:

ADK_SERVER_URL=http://127.0.0.1:8000
ADK_APP=src
ADK_USER_ID=user
ADK_SESSION_ID=s_local

FLASK_PORT=5000
FLASK_DEBUG=True

GOOGLE_CLOUD_PROJECT=your-gcp-project-id
GOOGLE_CLOUD_LOCATION=us-central1
GOOGLE_GENAI_USE_VERTEXAI=True

4. Run Servers

Terminal 1 — ADK Backend:

adk api_server . --port=8000

Terminal 2 — Flask UI:

python frontend/app.py

Open UI → http://127.0.0.1:5000


🚀 Deploying to Google Cloud Run

1. Deploy ADK Backend

gcloud run deploy farmagent-adk-backend \
  --source . \
  --region us-central1 \
  --allow-unauthenticated \
  --set-env-vars="GOOGLE_CLOUD_PROJECT=your-gcp-project-id,GOOGLE_CLOUD_LOCATION=us-central1,GOOGLE_GENAI_USE_VERTEXAI=True" \
  --command="adk" \
  --args="api_server,.,--port,8080"

2. Deploy Frontend

export ADK_BACKEND_URL="your-adk-backend-url"

gcloud run deploy farmagent-frontend \
  --source . \
  --region us-central1 \
  --allow-unauthenticated \
  --set-env-vars="ADK_SERVER_URL=$ADK_BACKEND_URL,ADK_APP=src,ADK_USER_ID=cloud_user,ADK_SESSION_ID=s_cloud"

Access the deployed UI using the generated Cloud Run URL.


🔗 Useful Links

Built for the #CloudRunHackathon using Google's Agent Development Kit.


🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

About

An AI-driven farm agent built on Google ADK, using adaptive decision-making to manage crops, resources, and environment interactions.

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages