From 31576a1feb4cedb75741836e0a75cb4f84f1eed1 Mon Sep 17 00:00:00 2001 From: Deep Koluguri Date: Fri, 19 Jun 2026 16:33:15 -0400 Subject: [PATCH] Fix langchain import by using langgraph prebuilt agent --- src/agent.py | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/agent.py b/src/agent.py index bbf0ca0..5b2e210 100644 --- a/src/agent.py +++ b/src/agent.py @@ -4,8 +4,7 @@ import threading import time from langchain_core.tools import tool from langchain_google_genai import ChatGoogleGenerativeAI -from langchain.agents import create_tool_calling_agent, AgentExecutor -from langchain_core.prompts import ChatPromptTemplate +from langgraph.prebuilt import create_react_agent from temporalio import activity os.environ["GOOGLE_API_KEY"] = "AIzaSyDKYcgVPN2oJirwzf_td3sBYMnXHWfVphU" @@ -55,23 +54,14 @@ def run_agent_activity(payload: dict) -> str: llm = ChatGoogleGenerativeAI(model="gemini-1.5-pro") - prompt_text = f"""You are a highly capable AI assistant operating in a WhatsApp group. + system_prompt = f"""You are a highly capable AI assistant operating in a WhatsApp group. 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 they ask for a reminder, use the `set_reminder` tool and pass {target_jid} as the target_jid! - -User Request: {{input}} """ - - prompt = ChatPromptTemplate.from_messages([ - ("system", prompt_text), - ("placeholder", "{agent_scratchpad}"), - ]) - agent = create_tool_calling_agent(llm, tools, prompt) - agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True) - - result = agent_executor.invoke({"input": user_request}) - return result["output"] + agent = create_react_agent(llm, tools, state_modifier=system_prompt) + result = agent.invoke({"messages": [("user", user_request)]}) + return result["messages"][-1].content