🌾 AgroIntelligence β€” A Multi-Agent System for Smarter Agriculture

AgroIntelligence Banner

πŸš€ Inspiration

Farmers often face difficulty accessing reliable data on weather, soil conditions, and market trends when deciding what crops to grow. Inspired by this, we built AgroIntelligence, a multi-agent AI system that simulates the decision-making of agricultural experts β€” each specializing in a particular domain β€” to recommend optimal crops in any region based on real-world data.

Our goal is to empower data-driven, sustainable agriculture.


πŸ’‘ What it does

AgroIntelligence:

  • Takes a location as input.
  • Uses five specialized agents to gather and analyze:
    • Crop suitability
    • Environmental data
    • Soil health
    • Market demand/supply
  • Synthesizes this information to recommend ~10 crops, backed by reasoning and data.
  • Displays the real-time thinking process of each agent on a React dashboard with WebSocket updates.

πŸ—οΈ How we built it

  • Built using Agno, an open-source multi-agent orchestration framework.
  • Agents communicate by passing structured responses in JSON format.
  • FastAPI serves as the backend and agent controller, handling requests and WebSocket streams.
  • The frontend, built with React, receives agent outputs in real-time and displays them in an interactive UI.

πŸ€– Agent Overview

Agent Name Description
CropRecommenderAgent Recommends crops suitable for the region using geolocation and agronomy. Starts the workflow, passing the shortlist to downstream agents
EnvironmentalInfoAgent Enriches each candidate crop with location‑specific Environment specific details.Runs in parallel with other agents; data is merged afterward.​
MarketingInfoAgent Evaluates the economic feasibility of each crops. Scrapes market data, weighs stability and demand to finalize economic viability for each crop.​
SoilHealthInfoAgent Analyzes soil quality, nutrients, and pH levels. Fetches soil surveys, compares actual values with crop‑specific requirements.
SummaryAgent Crafts a clear, farmer‑friendly report from all verified data. Combines all domain insights, ranks crops, and adds practical guidance.

🧬 Key Code Snippets

πŸ› οΈ Agent Definition

crop_recommender_agent = Agent(
    model=make_chat(1000),
    tools=[DuckDuckGoTools()],
    description="CropRecommenderAgent",
    instructions=thinking_prompt(
        """Search DuckDuckGo for agronomic guidance for the region.
        Return 5‑10 suitable crops with sources in `CropsList` format.
        """
    ),
    response_model=CropsList,
    structured_outputs=True
)

πŸ”„ Workflow Setup

def run(self) -> RunResponse:
    self.log_steps: List[Dict[str, Any]] = []
    ...
    self.status_callback(
        AgentStatusUpdate(
            agent="CropRecommenderAgent", status="Started crop recommendation"
        ).json()
    )

    crops_data: CropsList = self.safe_run(
        crop_recommender_agent, location, CropsList()
    )
    self.status_callback(
        AgentStatusUpdate(
            agent="CropRecommenderAgent",
            status="...
                ...,
            next_agent=["SoilHealthInfoAgent", ...,],
        ).json()
    )
    ...

⚑ Real-time WebSocket Handling (Frontend)

useEffect(() => {
  // Connect to FastAPI backend
  socketRef.current = new WebSocket("ws://localhost:8000/ws");

  socketRef.current.onmessage = (event) => {
    const data = JSON.parse(event.data);
    handleWebSocketMessage(data);
  };
  socketRef.current.onerror = (error) => {
      setOutput(prev => prev + "\nError connecting to server");
      setLoading(false);
    };
  socketRef.current.onclose = () => { ... };
  return () => socketRef.current?.close();
  }, []);

πŸ“‘ FastAPI WebSocket Route

@app.websocket("/ws")
async def websocket_endpoint(websocket: WebSocket):
    await websocket.accept()
    user_input = await websocket.receive_text()
    async for update in run_workflow_stream(user_input):
        await websocket.send_text(update.json())

🧠 Architecture Diagram

πŸ§— Challenges we ran into

  • Chaining Agent Responses: Passing outputs as structured JSON between agents while keeping context.

  • WebSocket Integration: Real-time updates in React from Python (FastAPI) without delays.

  • Structured Output from LLMs: LLMs often responded with unstructured text; we enforced schemas to fix this.

  • Debugging Multi-agent Flows: Identifying where breakdowns occurred in an agent chain was tricky.

πŸ… Accomplishments that we're proud of

  • Built an end-to-end agent-based AI system that mirrors human decision-making.
  • Achieved real-time data aggregation using WebSockets and LLMs.
  • Created a highly visual dashboard showing live agent states, interactions, and recommendations.
  • Modular agent system β€” easily extendable to other domains like disaster planning or smart cities.

πŸ“š What we learned

  • Deep understanding of multi-agent system design and orchestration.
  • Structuring agent communication via schemas and response models.
  • WebSocket integration between Python backend and React frontend.
  • Techniques for handling LLM unpredictability and timeouts in real-time applications.

🌱 What's next for AgroIntelligence

  • Add support for live weather APIs, soil sensors, and market APIs.
  • Expand to support personalized recommendations per farmer.
  • Translate to regional languages and add voice interface.
  • Integrate with blockchain supply chains for provenance tracking.
  • Release as a mobile app for wider reach in rural areas.

πŸ› οΈ Tech Stack

  • Backend: Python, Agno, FastAPI, WebSockets
  • Frontend: React.js, Tailwind CSS
  • Data: DuckDuckGoTools (search), Open-source LLMs (via Ollama)
  • Architecture: Multi-Agent Workflow (Agno), REST + Socket APIs

πŸ“‚ Project Structure

AgroIntelligence/
β”œβ”€β”€ backend/ # FastAPI backend + WebSocket endpoints
β”‚   β”œβ”€β”€ agent2_v1.py
β”‚   └── requirements.txt
β”œβ”€β”€ agent-dashboard/
β”‚   β”œβ”€β”€ App.jsx
β”‚   └── components/
β”‚       β”œβ”€β”€ AgentVisualization.jsx
β”‚       β”œβ”€β”€ DebugHelper.jsx
β”‚       └── SequentialTreeVisualization.jsx
β”œβ”€β”€ package.json.py
β”œβ”€β”€ index.html
β”œβ”€β”€ ...
β”œβ”€β”€ requirements.txt
└── README.md

πŸ§ͺ Run Locally

🐍 Backend

  1. Navigate to the backend directory:

    cd backend
    
  2. Install the necessary dependencies:

    pip install -r requirements.txt
    
  3. Run the FastAPI backend with Uvicorn:

    uvicorn agent2_v1:app --reload
    

βš›οΈ Frontend

  1. Navigate to the agent-dashboard directory:

    cd agent-dashboard
    
  2. Install the required frontend dependencies:

    npm install
    
  3. Run the React frontend:

    npm run dev
    
  4. Open your browser and navigate to http://localhost:3000 to view the dashboard.


Made with 🧠+🌱 by Team "Barbenheimer" for Luddy Hackathon 2025.

Built With

+ 5 more
Share this project:

Updates