Fix langchain import by using langgraph prebuilt agent
Build Agents Runtime / build (push) Successful in 4m12s Details

This commit is contained in:
Deep Koluguri 2026-06-19 16:33:15 -04:00
parent 3982af34fd
commit 31576a1feb
1 changed files with 5 additions and 15 deletions

View File

@ -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