diff --git a/src/agent.py b/src/agent.py index 636d3dd..47aca58 100644 --- a/src/agent.py +++ b/src/agent.py @@ -82,7 +82,20 @@ def delete_k8s_pod(pod_name: str, namespace: str) -> str: except Exception as e: return f"K8s Error: {str(e)}" -tools = [send_whatsapp, set_reminder, schedule_calendar, trigger_utility_scraper, get_k8s_pods, delete_k8s_pod] +GMAIL_AGENT_URL = "http://gmail-agent.ai-agents.svc.cluster.local:5002/api/send-email" + +@tool +def send_email(to_email: str, subject: str, body: str) -> str: + """Send an email response back to the user.""" + try: + resp = requests.post(GMAIL_AGENT_URL, json={"to": to_email, "subject": subject, "body": body}) + print(f"Sent Email: {resp.json()}") + return f"Email sent successfully to {to_email}" + except Exception as e: + print(f"Failed to send Email: {e}") + return f"Failed to send email: {str(e)}" + +tools = [send_whatsapp, set_reminder, schedule_calendar, trigger_utility_scraper, get_k8s_pods, delete_k8s_pod, send_email] @activity.defn def run_agent_activity(payload: dict) -> str: @@ -92,15 +105,20 @@ def run_agent_activity(payload: dict) -> str: llm = ChatGoogleGenerativeAI(model="gemini-1.5-pro") - system_prompt = f"""You are a highly capable AI assistant operating in a WhatsApp group. + system_prompt = f"""You are a highly capable AI assistant operating as an orchestrator. The user ({sender}) has sent a message. -Their WhatsApp Group/Chat ID (target_jid) is: {target_jid}. -Whenever you need to send a message back, use the `send_whatsapp` tool and pass {target_jid} as the target_jid! -If the user asks to scrape utility data, run the utility scraper, or fetch utility bills/data, call the `trigger_utility_scraper` tool. -If they ask for a reminder, use the `set_reminder` tool and pass {target_jid} as the target_jid! -If they ask to check Kubernetes pods, use the `get_k8s_pods` tool. -If they ask to restart a pod or deployment, use the `delete_k8s_pod` tool. +Their routing ID (target_jid) is: {target_jid}. + +ROUTING INSTRUCTIONS: +- If target_jid is 'EMAIL', it means the user sent this request via Email. You MUST use the `send_email` tool to reply to them (set `to_email` to {sender}, and choose a relevant `subject`). +- Otherwise, the user sent this request via WhatsApp. You MUST use the `send_whatsapp` tool to reply and pass {target_jid} as the target_jid! + +TOOLS AVAILABLE: +- Scrape utility data: call the `trigger_utility_scraper` tool. +- Reminders: use the `set_reminder` tool (pass {target_jid} as target_jid unless it's EMAIL, then fallback to WhatsApp or don't set reminders for email). +- Check Kubernetes pods: use the `get_k8s_pods` tool. +- Restart a pod or deployment: use the `delete_k8s_pod` tool. """ # Use state_modifier or prompt depending on langgraph version, falling back to older syntax if needed.