import os from dotenv import load_dotenv from langchain_groq import ChatGroq # ----------------------------------- # Load environment variables # ----------------------------------- load_dotenv() GROQ_API_KEY = os.getenv("GROQ_API_KEY") if not GROQ_API_KEY: raise ValueError( "Missing GROQ_API_KEY" ) # ----------------------------------- # Shared LLM # ----------------------------------- llm = ChatGroq( groq_api_key=GROQ_API_KEY, model_name="llama-3.1-8b-instant", temperature=0.3, max_tokens=500 ) # ----------------------------------- # Research Agent # ----------------------------------- def research_agent(topic): prompt = f""" You are a Research Agent. Research the following topic deeply: Topic: {topic} Provide: - key facts - important concepts - useful insights """ response = llm.invoke(prompt) return response.content # ----------------------------------- # Planner Agent # ----------------------------------- def planner_agent(topic): prompt = f""" You are a Planner Agent. Create a step-by-step action plan for: {topic} Make the plan practical and structured. """ response = llm.invoke(prompt) return response.content # ----------------------------------- # Summary Agent # ----------------------------------- def summary_agent(research, plan): prompt = f""" You are a Summary Agent. Summarize the following research and plan. RESEARCH: {research} PLAN: {plan} Produce: - concise summary - key takeaways - final recommendations """ response = llm.invoke(prompt) return response.content # ----------------------------------- # Coordinator Agent # ----------------------------------- def run_multi_agent_system(user_query): # Step 1 research = research_agent(user_query) # Step 2 plan = planner_agent(user_query) # Step 3 summary = summary_agent( research, plan ) return { "research": research, "plan": plan, "summary": summary }