Kisan Kavach is an intelligent farming assistant built with Google Cloud's Agent Development Kit (ADK) and Flutter. It provides farmers with AI-powered support for crop health monitoring, government scheme recommendations, market analysis, and weather information through voice and visual interactions in local languages.
- Overview
- Architecture
- Features
- Prerequisites
- Backend Setup
- Frontend Setup
- Agent System
- API Documentation
- Deployment
- Development Guide
- Troubleshooting
Kisan Kavach leverages cutting-edge AI technology to assist farmers with:
- Plant Disease Detection: Upload crop images to identify diseases and get treatment recommendations
- Government Schemes: Find relevant agricultural schemes and subsidies
- Market Analysis: Get real-time crop prices and market trends
- Weather Information: Receive weather updates and farming advice
- Multi-language Support: Available in English and Kannada with voice interaction
The backend is built using Google's Agent Development Kit (ADK) with a multi-agent system:
Root Agent (Intent Detection)
├── Government Schemes Agent
├── Market Analyzer Agent
├── Plant Health Support Agent
│ ├── Plant Disease Detection Agent
│ └── Plant Treatment Agent
└── Weather Agent
Key Components:
- FastAPI Server: RESTful API with speech and image processing
- Multi-Agent System: Specialized agents for different farming domains
- Google Cloud Integration: Vertex AI, Speech-to-Text, Text-to-Speech
- RAG System: Document retrieval for government schemes
Cross-platform Flutter application with:
- Multi-platform Support: iOS, Android, and Web
- Firebase Integration: Authentication and cloud services
- Voice Interface: Record and playback in local languages
- Camera Integration: Plant disease detection through images
- State Management: Provider pattern for app state
- Voice-based conversation in Kannada and English
- Image-based plant disease detection
- Real-time market price information
- Government scheme recommendations
- Weather forecasting and alerts
- Cross-platform mobile application
- Multi-modal input (text, voice, images)
- Offline capability for basic features
- Cloud-based AI processing
- Secure authentication
- Multi-language localization
- GCP Project with billing enabled
- Vertex AI API enabled
- Speech-to-Text API enabled
- Text-to-Speech API enabled
- Cloud Storage bucket
- Service account with appropriate permissions
- Firebase project
- Authentication enabled
- Firestore database
- Cloud Storage
- Python 3.9+
- Flutter SDK 3.16+
- Node.js (for Firebase CLI)
- Git
git clone <repository-url>
cd kisan-project/backend
# Using pip
pip install -r requirements.txt
# Or using uv (recommended)
pip install uv
uv sync
Create a .env
file in the backend directory:
# GCP Configuration
GOOGLE_CLOUD_PROJECT=your-gcp-project-id
GCP_PROJECT_NUMBER=your-project-number
GCP_REGION=asia-south1
GOOGLE_APPLICATION_CREDENTIALS=path/to/service-account.json
# Storage
UPLOAD_BUCKET=your-storage-bucket-name
# Firebase
FIREBASE_PROJECT_ID=your-firebase-project-id
# Model Configuration
GEMINI_MODEL=gemini-2.5-pro
SPEECH_LANGUAGE=kn-IN
TTS_LANGUAGE=kn-IN
TTS_VOICE=kn-IN-Standard-A
# App Configuration
DEBUG=true
HOST=0.0.0.0
PORT=8084
ENVIRONMENT=development
# Security
MAX_UPLOAD_SIZE=10485760
REQUEST_TIMEOUT=30
RATE_LIMIT_PER_MINUTE=60
- Create a service account in GCP Console
- Download the JSON key file
- Set the path in
GOOGLE_APPLICATION_CREDENTIALS
- Grant required permissions:
- Vertex AI User
- Speech Administrator
- Storage Object Admin
# Test the setup
python test_setup.py
# Start the development server
python main.py
The backend will be available at http://localhost:8084
cd frontend
flutter pub get
- Install Firebase CLI:
npm install -g firebase-tools
- Login and configure:
firebase login
firebase use your-firebase-project-id
- Generate Firebase configuration:
flutterfire configure
Edit lib/config/app_config.dart
:
class AppConfig {
static const String baseUrl = 'http://localhost:8084'; // For development
static const String apiVersion = 'v1';
static const String appName = 'Kisan Kavach';
}
📱 Click to expand Flutter SDK Setup Guide
-
Download Flutter SDK:
- Visit Flutter.dev
- Download the appropriate version for your operating system
- Extract to a permanent location (e.g.,
/Users/[username]/development/flutter
on macOS)
-
Add Flutter to PATH:
# Add to your shell profile (.bashrc, .zshrc, etc.) export PATH="$PATH:/path/to/flutter/bin" # Verify installation flutter --version
-
Run Flutter Doctor:
flutter doctor
This will show you what dependencies you need to install.
🤖 Android Studio & Emulator Setup
-
Download and Install Android Studio:
- Download from developer.android.com
- Install with default settings
- Launch Android Studio and complete the setup wizard
-
Install Required SDKs:
- Open Android Studio → SDK Manager
- Install Android SDK (API level 33 or higher recommended)
- Install Android SDK Build-Tools
- Install Android Emulator
-
Configure Environment Variables:
# Add to your shell profile export ANDROID_HOME=$HOME/Library/Android/sdk # macOS export ANDROID_HOME=$HOME/Android/Sdk # Linux export PATH=$PATH:$ANDROID_HOME/emulator export PATH=$PATH:$ANDROID_HOME/tools export PATH=$PATH:$ANDROID_HOME/tools/bin export PATH=$PATH:$ANDROID_HOME/platform-tools
📱 Android Virtual Device (AVD) Setup
-
Create AVD:
# Open AVD Manager android avd # Or from Android Studio: Tools → AVD Manager
-
Recommended AVD Configuration:
- Device: Pixel 7 or Pixel 6
- System Image: API 33 (Android 13) or higher
- RAM: 4GB or more
- Internal Storage: 6GB or more
- Enable Hardware Acceleration (Intel HAXM/AMD)
-
Start Emulator:
# List available AVDs flutter emulators # Launch specific emulator flutter emulators --launch <emulator-name> # Or start from Android Studio AVD Manager
⚙️ Android Project Configuration
-
Update Build Configuration: Edit
android/app/build.gradle
:android { compileSdkVersion 34 ndkVersion flutter.ndkVersion defaultConfig { minSdkVersion 21 # Required minimum targetSdkVersion 34 # ... other configurations } }
-
Add Required Permissions: Edit
android/app/src/main/AndroidManifest.xml
:<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
-
Test Android Setup:
# With emulator running flutter run -d android # Or specify device flutter devices flutter run -d <device-id>
🍎 Xcode Installation & Setup
-
Install Xcode:
- Download from Mac App Store (requires macOS)
- Or download from developer.apple.com
- Install Xcode Command Line Tools:
xcode-select --install
-
Accept Xcode License:
sudo xcodebuild -license accept
-
Verify Xcode Installation:
xcodebuild -version flutter doctor
📱 iOS Simulator Setup
-
Open iOS Simulator:
# Open Simulator app open -a Simulator # Or from Xcode: Xcode → Open Developer Tool → Simulator
-
Install Additional Simulators:
- Xcode → Preferences → Components
- Download required iOS versions (iOS 15.0+ recommended)
- Or use Simulator → Device → Manage Devices
-
Recommended Simulator Devices:
- iPhone 14 Pro (iOS 16.0+)
- iPhone 13 (iOS 15.0+)
- iPad Pro (12.9-inch) for tablet testing
⚙️ iOS Project Configuration
-
Install CocoaPods:
# Install CocoaPods (Ruby gem manager) sudo gem install cocoapods # Navigate to iOS directory and install pods cd ios pod install cd ..
-
Configure iOS Deployment Target:
- Open
ios/Runner.xcworkspace
in Xcode - Select Runner project → General
- Set Deployment Target to iOS 12.0 or higher
- Open
-
Apple Developer Account (for Physical Device):
- Sign up at developer.apple.com
- Add your account in Xcode → Preferences → Accounts
- Select your team in Runner → Signing & Capabilities
-
Code Signing (for Physical Device):
- In Xcode, select Runner target
- Go to Signing & Capabilities
- Select your development team
- Xcode will automatically create provisioning profiles
🚀 Running on iOS Devices
-
iOS Simulator:
# List available iOS simulators flutter emulators # Launch simulator flutter emulators --launch apple_ios_simulator # Run app on simulator flutter run -d ios
-
Physical iOS Device:
# Connect device via USB # Trust computer on device when prompted # List connected devices flutter devices # Run on specific device flutter run -d <device-id>
✅ Flutter Doctor Checklist
Run flutter doctor -v
and ensure all items show checkmarks:
- ✅ Flutter SDK (Channel stable, version 3.16.0+)
- ✅ Android toolchain - develop for Android devices
- ✅ Xcode - develop for iOS and macOS
- ✅ Chrome - develop for the web
- ✅ Android Studio
- ✅ VS Code (optional but recommended)
- ✅ Connected device
🔧 Common Setup Issues & Solutions
-
Android License Issues:
flutter doctor --android-licenses # Accept all licenses
-
iOS CocoaPods Issues:
cd ios rm Podfile.lock rm -rf Pods pod install cd ..
-
Flutter SDK Issues:
flutter clean flutter pub get flutter doctor
-
Performance Optimization:
# Enable hardware acceleration for Android emulator # In BIOS: Enable Intel VT-x or AMD-V # For iOS Simulator, ensure sufficient RAM allocation # Close unnecessary applications during development
flutter pub get
flutter run
🚀 Development Commands
# Install dependencies first
flutter pub get
# Run on available device (auto-detect)
flutter run
# Run with hot reload enabled (default in debug mode)
flutter run --hot
# Run in release mode (optimized performance)
flutter run --release
# Web Development
flutter run -d chrome
flutter run -d web-server --web-port 8080
# Android Development
flutter run -d android
flutter run -d <android-device-id>
# iOS Development
flutter run -d ios
flutter run -d <ios-device-id>
flutter run -d "iPhone 14 Pro Simulator"
🛠️ Development Tools & Commands
# List all available devices/emulators
flutter devices
# List available emulators
flutter emulators
# Launch specific emulator
flutter emulators --launch <emulator-name>
# Enable debugging
flutter run --debug
flutter attach # Attach to running app
# Build without running
flutter build apk # Android APK
flutter build ios # iOS build
flutter build web # Web build
🔧 Troubleshooting Development Setup
-
Clean and Rebuild:
flutter clean flutter pub get flutter run
-
Reset Flutter Configuration:
flutter config --clear-features flutter doctor
-
Update Flutter and Dependencies:
flutter upgrade flutter pub upgrade
-
Platform-Specific Issues:
# Android: Clear Gradle cache cd android && ./gradlew clean && cd .. # iOS: Clean Xcode build cd ios && xcodebuild clean && cd ..
The main orchestrator that analyzes user queries and routes them to appropriate sub-agents:
root_agent = Agent(
model="gemini-2.5-flash",
name="root_agent",
instruction="Intent detection for agricultural queries",
sub_agents=[scheme_agent, market_agent, weather_agent, disease_agent]
)
- Government Schemes Agent: RAG-based system for finding relevant schemes
- Market Analyzer Agent: Real-time market data and price analysis
- Plant Health Support Agent: Disease detection and treatment recommendations
- Weather Agent: Weather information and agricultural advice
- Create agent directory:
backend/agents/kisan_agent/sub_agents/new_agent/
- Implement agent logic in
agent.py
- Define prompts in
prompt.py
- Add tools if needed in
tools.py
- Register in root agent
POST /api/chat_endpoint
Request Body:
{
"text": "What's the weather today?",
"audio_file": "base64_encoded_audio",
"image": "base64_encoded_image",
"city": "Bangalore",
"name": "John Farmer",
"state": "Karnataka",
"country": "India",
"preferred_language": "kn"
}
Response:
{
"text_response": "Weather information...",
"audio_response_base64": "base64_encoded_audio"
}
GET /
Returns API status and documentation link.
- Build Docker image:
docker build -t kisan-backend .
- Push to Container Registry:
docker tag kisan-backend gcr.io/PROJECT_ID/kisan-backend
docker push gcr.io/PROJECT_ID/kisan-backend
- Deploy to Cloud Run:
gcloud run deploy kisan-backend \
--image gcr.io/PROJECT_ID/kisan-backend \
--platform managed \
--region asia-south1 \
--allow-unauthenticated
flutter build web
firebase deploy --only hosting
Android (Google Play Store):
flutter build appbundle
iOS (App Store):
flutter build ios
- Backend: Create new agents or extend existing ones
- Frontend: Add new screens and services
- Testing: Use the provided test files
Backend:
agents/
: Agent implementationsservices/
: External service integrationsmodels/
: Data modelsconfig/
: Configuration management
Frontend:
lib/screens/
: UI screenslib/services/
: Business logiclib/models/
: Data modelslib/widgets/
: Reusable UI components
Backend:
python -m pytest
Frontend:
flutter test
-
GCP Authentication Error
- Verify service account permissions
- Check
GOOGLE_APPLICATION_CREDENTIALS
path
-
Flutter Build Issues
- Run
flutter clean && flutter pub get
- Check platform-specific requirements
- Run
-
API Connection Issues
- Verify backend is running
- Check network connectivity
- Validate API endpoints
- Check the logs in
backend/logs/
- Enable debug mode in
.env
- Use Flutter DevTools for frontend debugging
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Google Cloud Platform for AI services
- Firebase for backend services
- Flutter team for the cross-platform framework
- Open source community for various libraries used
Built with ❤️ for Indian farmers by The Agentic Troop using Google Agent Development Kit