Fix langchain import by using langgraph prebuilt agent
Build Agents Runtime / build (push) Successful in 4m12s
Details
Build Agents Runtime / build (push) Successful in 4m12s
Details
This commit is contained in:
parent
3982af34fd
commit
31576a1feb
20
src/agent.py
20
src/agent.py
|
|
@ -4,8 +4,7 @@ import threading
|
||||||
import time
|
import time
|
||||||
from langchain_core.tools import tool
|
from langchain_core.tools import tool
|
||||||
from langchain_google_genai import ChatGoogleGenerativeAI
|
from langchain_google_genai import ChatGoogleGenerativeAI
|
||||||
from langchain.agents import create_tool_calling_agent, AgentExecutor
|
from langgraph.prebuilt import create_react_agent
|
||||||
from langchain_core.prompts import ChatPromptTemplate
|
|
||||||
from temporalio import activity
|
from temporalio import activity
|
||||||
|
|
||||||
os.environ["GOOGLE_API_KEY"] = "AIzaSyDKYcgVPN2oJirwzf_td3sBYMnXHWfVphU"
|
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")
|
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.
|
The user ({sender}) has sent a message.
|
||||||
Their WhatsApp Group/Chat ID (target_jid) is: {target_jid}.
|
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!
|
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!
|
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 = create_react_agent(llm, tools, state_modifier=system_prompt)
|
||||||
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
|
result = agent.invoke({"messages": [("user", user_request)]})
|
||||||
|
return result["messages"][-1].content
|
||||||
result = agent_executor.invoke({"input": user_request})
|
|
||||||
return result["output"]
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue