A comprehensive AI-powered agricultural advisory system designed specifically for Indian farmers. This system uses multi-agent architecture with CrewAI, MCP (Model Context Protocol), and FastAPI to provide intelligent, contextual advice for agricultural decisions.
KrishiSetu addresses the critical challenges faced by Indian farmers by providing AI-driven solutions to answer questions like:
- "When should I irrigate?" - Weather-based irrigation recommendations
- "What seed variety suits this unpredictable weather?" - Climate-adaptive crop selection
- "Will next week's temperature drop kill my yield?" - Weather risk assessment
- "Can I afford to wait for the market to improve?" - Market trend analysis
- "Where can I get affordable credit, and will any state/central government policy help me with finances?" - Financial guidance and policy information
The system uses three specialized AI agents working together:
- 🌤️ Weather Agent - Provides weather analysis and irrigation recommendations
- 🌱 Crop Agent - Offers crop selection and management advice
- 💰 Finance Agent - Delivers financial guidance and government scheme information
- CrewAI - Multi-agent orchestration and task management
- MCP (Model Context Protocol) - External data integration
- FastAPI - High-performance web API
- LangChain - LLM integration and tool management
- SQLAlchemy - Database management
- Pydantic - Data validation and serialization
- English, Hindi, Tamil, Telugu, Bengali, Marathi, Gujarati, Kannada, Malayalam, Punjabi
- Automatic language detection
- Localized responses for Indian farmers
- Weather data from OpenWeatherMap API
- Government agricultural data
- Market price information
- Soil health data
- Natural language understanding
- Context-aware responses
- Confidence scoring
- Multi-domain synthesis
- Modular agent system
- Plugin-based data sources
- Configurable workflows
- Easy integration with external systems
- Python 3.8+
- pip package manager
-
Clone the repository
git clone <repository-url> cd KrishiSetu
-
Install dependencies
uv pip install -r requirements.txt
-
Set up environment variables
cp .env.example .env # Edit .env with your API keys
-
Initialize the database
python -c "from models.database import create_tables; create_tables()"
-
Run the application
python main.py
- OpenAI API Key - For LLM-powered agents
- Tavily API Key - For web search capabilities
- Weather API Key - For weather data (OpenWeatherMap)
OPENAI_API_KEY=your_openai_api_key_here
TAVILY_API_KEY=your_tavily_api_key_here
WEATHER_API_KEY=your_weather_api_key_here
DATABASE_URL=sqlite:///./krishisetu.db
DEBUG=True
HOST=0.0.0.0
PORT=8000
POST /query
Content-Type: application/json
{
"query": "When should I irrigate my wheat crop?",
"context": {
"location": "Mumbai",
"crop_type": "Wheat",
"farmer_type": "small"
},
"comprehensive": true,
"language": "en"
}
POST /query/weather
Content-Type: application/json
{
"query": "क्या आज बारिश होगी?",
"context": {"location": "Delhi"}
}
POST /query/crop
Content-Type: application/json
{
"query": "Which crop should I plant this season?",
"context": {
"location": "Punjab",
"soil_type": "Alluvial",
"season": "Kharif"
}
}
POST /query/finance
Content-Type: application/json
{
"query": "What loans are available for farmers?",
"context": {
"farmer_type": "small",
"land_area": 2.0,
"state": "Maharashtra"
}
}
{
"success": true,
"data": {
"current_weather": {
"temperature": 28.5,
"humidity": 65,
"description": "partly cloudy"
},
"irrigation_recommendation": {
"recommendation": "Moderate irrigation recommended",
"priority": "Medium",
"next_irrigation": "Within 48 hours"
}
},
"confidence": 0.85,
"source": "Weather Agent"
}
{
"success": true,
"data": {
"recommendations": [
{
"name": "Rice",
"varieties": ["IR64", "Swarna"],
"suitability_score": 85,
"market_price": 1800
}
],
"crop_calendar": {
"planting_start": "June",
"harvest_start": "September"
}
},
"confidence": 0.78,
"source": "Crop Agent"
}
Run the test suite to ensure all components work correctly:
python -m pytest tests/
Or run specific test categories:
# Test agents
python tests/test_agents.py
# Test language processing
python -c "from tests.test_agents import TestLanguageProcessor; unittest.main()"
KrishiSetu/
├── agents/ # AI agent implementations
│ ├── base_agent.py # Base agent class
│ ├── weather_agent.py # Weather analysis agent
│ ├── crop_agent.py # Crop management agent
│ └── finance_agent.py # Financial advisory agent
├── api/ # FastAPI application
│ └── main.py # Main API endpoints
├── crew/ # CrewAI orchestration
│ └── agricultural_crew.py
├── mcp/ # Model Context Protocol
│ └── mcp_client.py # MCP client implementation
├── models/ # Database models
│ └── database.py # SQLAlchemy models
├── utils/ # Utility functions
│ └── language_processor.py
├── tests/ # Test suite
│ └── test_agents.py
├── config.py # Configuration management
├── main.py # Application entry point
├── requirements.txt # Python dependencies
└── README.md # This file
-
Create a new agent class inheriting from
BaseAgent
-
Implement required methods:
_get_backstory()
_get_tools()
process_query()
_get_keywords()
-
Register the agent in the crew:
from crew.agricultural_crew import AgriculturalCrew
class NewAgent(BaseAgent):
def __init__(self):
super().__init__(
name="New Expert",
role="New Specialist",
goal="Provide new type of advice"
)
# Implement required methods...
- Extend the MCP client in
mcp/mcp_client.py
- Add new data retrieval methods
- Update the data provider in
crew/agricultural_crew.py
- Add new language patterns in
utils/language_processor.py
- Update the
language_patterns
dictionary - Add translation mappings
- Agents work together using CrewAI for comprehensive analysis
- Each agent specializes in specific domains
- Coordinated responses provide holistic advice
- Extracts location, crop type, and farmer context
- Provides personalized recommendations
- Considers local conditions and constraints
- Automatic language detection
- Localized agricultural terminology
- Cultural context awareness
- Weather data integration
- Market price monitoring
- Government scheme updates
- Confidence scoring for responses
- Source attribution
- Reasoning transparency
We welcome contributions! Please see our contributing guidelines:
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- CrewAI - For multi-agent orchestration
- LangChain - For LLM integration
- FastAPI - For high-performance API framework
- Indian Agricultural Research Institute - For agricultural data
- OpenWeatherMap - For weather data
- Government of India - For agricultural policies and schemes
For support and questions:
- Create an issue on GitHub
- Contact the development team
- Check the documentation
KrishiSetu - Bridging the gap between technology and agriculture for a sustainable future! 🌾🤖