File size: 2,696 Bytes
f24b4d8
 
a61c2dd
f24b4d8
 
 
 
 
 
 
 
a61c2dd
f24b4d8
 
 
 
 
 
a61c2dd
f24b4d8
a61c2dd
 
f24b4d8
 
 
032080e
a61c2dd
 
 
 
 
 
 
f24b4d8
 
 
 
 
 
 
 
 
 
a61c2dd
5ecf9f6
f24b4d8
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from google.adk import Agent, Runner
from google.adk.sessions import InMemorySessionService
from tools import create_plant_diagnosis_tool, create_chroma_db_search_tool, create_bigquery_search_tool

def initialize_adk(vision_model, processor, retriever):
    """
    Initializes the ADK agent, tools, and runner.

    Args:
        vision_model: The loaded vision model.
        processor: The model's processor.
        retriever: The RAG retriever (no longer used but kept for compatibility).

    Returns:
        A dictionary containing the ADK components, or None on error.
    """
    print("Initializing ADK Tools and Agent...")
    try:
        if vision_model and processor:
            diagnosis_tool = create_plant_diagnosis_tool(model=vision_model, processor=processor)
            chroma_db_tool = create_chroma_db_search_tool()
            bigquery_tool = create_bigquery_search_tool()

            agent = Agent(
                name="AuraMindGlowAgent",
                model="gemini-2.0-flash",
                description="A farming assistant that can diagnose plant health and suggest remedies from local or cloud knowledge bases.",
                instruction="You are a friendly and intelligent farming assistant. Your primary goal is to help users identify plant health issues and find solutions. You have several tools at your disposal:\n" \
                            "- Use the 'diagnose_plant' tool when the user provides an image.\n" \
                            "- After diagnosing, use the 'search_chroma_db' tool to find a remedy in the local knowledge base.\n" \
                            "- If the user asks for cloud-based information or structured data, use the 'search_bigquery' tool.\n" \
                            "Always prioritize the local knowledge base (ChromaDB) for remedies unless the user specifies otherwise.",
                tools=[diagnosis_tool, chroma_db_tool, bigquery_tool]
            )

            session_service = InMemorySessionService()
            runner = Runner(agent=agent, app_name="AuraMindGlow", session_service=session_service)
            
            print("✅ ADK Agent and Runner initialized successfully!")
            return {
                "agent": agent,
                "runner": runner,
                "diagnosis_tool": diagnosis_tool,
                "remedy_tool": chroma_db_tool,  # For compatibility with app.py
                "session_service": session_service
            }
        else:
            print("❌ Skipping ADK setup due to errors in model or RAG loading.")
            return None
    except Exception as e:
        print(f"❌ CRITICAL ERROR during ADK setup: {e}")
        return None