Skip to content

charithmadhuranga/AI-Agriculture-Advisor

Repository files navigation

AI Agriculture Advisor

An intelligent agriculture advisory system powered by AI agents that provides personalized farming advice based on soil conditions, climate, and crop requirements.

🌟 Features

  • Multi-Agent AI System: Utilizes three specialized AI agents:

    • 🌱 Soil Expert: Analyzes soil composition and health
    • 🌾 Crop Advisor: Recommends suitable crops based on conditions
    • 📊 Agricultural Analyst: Provides comprehensive farming strategies
  • Modern Web Interface: Beautiful, responsive chat interface with:

    • Dark theme with glassmorphism effects
    • Real-time loading indicators
    • Example queries for quick start
    • Smooth animations and transitions
  • RESTful API: FastAPI backend with:

    • CORS support for cross-origin requests
    • Error handling and logging
    • Health check endpoints

🏗️ Architecture

latest_ai_development/
├── src/latest_ai_development/     # CrewAI implementation
│   ├── config/
│   │   ├── agents.yaml            # Agent configurations
│   │   └── tasks.yaml             # Task definitions
│   ├── crew.py                    # Crew orchestration
│   └── main.py                    # CLI entry point
├── api/                           # FastAPI backend
│   ├── main.py                    # API server
│   └── requirements.txt           # API dependencies
└── frontend/                      # Web interface
    ├── index.html                 # Main HTML
    ├── styles.css                 # Styling
    └── app.js                     # Frontend logic

🚀 Getting Started

Prerequisites

  • Python >= 3.10, < 3.14
  • Node.js (for serving the frontend)
  • Google Gemini API key (get it from Google AI Studio)

Installation

  1. Clone and navigate to the project:

    cd latest_ai_development
  2. Set up environment variables: Create a .env file in the root directory:

    GEMINI_API_KEY=your_gemini_api_key_here

    📝 See GEMINI_SETUP.md for detailed instructions on getting your API key.

  3. Install CrewAI dependencies:

    pip install uv
    crewai install
  4. Install API dependencies:

    cd api
    pip3 install -r requirements.txt
    cd ..

Running the Application

1. Start the FastAPI Backend

cd api
python main.py

The API will be available at http://localhost:8000

You can test the API:

  • Health check: http://localhost:8000/health
  • API docs: http://localhost:8000/docs

2. Start the Frontend

In a new terminal, serve the frontend:

cd frontend
python -m http.server 3000

The frontend will be available at http://localhost:3000

3. Use the Application

  1. Open your browser and navigate to http://localhost:3000
  2. Type your farming question or click on an example query
  3. Wait for the AI agents to analyze and provide advice
  4. View the comprehensive farming strategy

💡 Example Queries

  • "I have a 2-acre farm in a tropical region with clay-loam soil. What crops should I plant this season?"
  • "My soil is sandy and I'm in a dry climate. What vegetables can I grow?"
  • "I want to start organic farming. What are the best practices for soil preparation?"
  • "What crops are best for monsoon season in South Asia?"
  • "How can I improve soil fertility naturally?"

🧪 Testing the CrewAI System

You can test the CrewAI agents directly without the API:

crewai run

This will run the crew with the default query defined in src/latest_ai_development/main.py.

📝 Customization

Modifying Agents

Edit src/latest_ai_development/config/agents.yaml to customize agent roles, goals, and backstories.

Modifying Tasks

Edit src/latest_ai_development/config/tasks.yaml to customize task descriptions and expected outputs.

Changing the LLM

By default, the system uses the LLM configured in your environment. You can modify the LLM settings in the .env file or in the agent configurations.

🛠️ Development

Project Structure

  • CrewAI Layer: Handles the multi-agent AI system
  • API Layer: Provides RESTful endpoints for the frontend
  • Frontend Layer: User interface for interacting with the system

Adding New Features

  1. New Agent: Add configuration to agents.yaml and create agent method in crew.py
  2. New Task: Add configuration to tasks.yaml and create task method in crew.py
  3. New API Endpoint: Add route in api/main.py
  4. Frontend Updates: Modify frontend/ files as needed

🐛 Troubleshooting

API Connection Error

  • Ensure the FastAPI backend is running on port 8000
  • Check CORS settings if accessing from a different origin

Model Overload Error

  • This is a temporary API issue from the LLM provider
  • Wait a few moments and try again
  • Consider using a different model or API key

No Response from Agents

  • Verify your API key is correctly set in .env
  • Check the API logs for error messages
  • Ensure all dependencies are installed

📚 Resources

📄 License

This project is built using CrewAI framework and follows its licensing terms.

🤝 Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.


Built with ❤️ using CrewAI, FastAPI, and modern web technologies

About

This Python-based application uses specialized AI agents to provide expert farming advice, aiming to help farmers make data-driven decisions.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors