create_react_agent not working #5613
Unanswered
ibrahimlambdatest
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
My LangGraph create_react_prompt does not seem to find the input fields I am passing in my invoke. I am not using an AgentExecutor since I want to be able to decide the course of action after each call. Below is a simplified version of my code where the first call to the agent is not happening.
This is the error I get -
KeyError: "Input to ChatPromptTemplate is missing variables {‘input’, ‘tools’, ‘agent_scratchpad’, ‘tool_names’}. Expected: [‘agent_scratchpad’, ‘input’, ‘tool_names’, ‘tools’] Received: [‘messages’, ‘is_last_step’, ‘remaining_steps’]\nNote: if you intended {input} to be part of the string and not a variable, please escape it with double curly braces like: ‘{{input}}’.\nFor troubleshooting, visit: INVALID_PROMPT_INPUT | 🦜️🔗 LangChain "
Can someone please tell me what do i do here. Thanks.
from dotenv import load_dotenv
load_dotenv()
from langchain_openai import ChatOpenAI
from langchain.prompts import(
ChatPromptTemplate,
SystemMessagePromptTemplate
)
from tools.sql import(run_query_tool, get_element_tool)
from langgraph.prebuilt import create_react_agent
from langchain.agents.format_scratchpad.log_to_messages import format_log_to_messages
execute_tools = [run_query_tool, get_element_tool]
prompt3 = ChatPromptTemplate(
messages=[
SystemMessagePromptTemplate.from_template(“”"
Answer the following questions as best you can. You have access to the following tools:
{tools}
]
)
chat = ChatOpenAI(
model=‘gpt-4o’,
temperature=0,
top_p=1.0,
verbose=True
)
react_agent = create_react_agent(model=chat, tools=execute_tools, prompt=prompt3)
user_input = “Go to website https://www.snapdeal.com/”
agent_scratchpad = “”
inputs = {
“input”: user_input,
“agent_scratchpad”: agent_scratchpad,
“tool_names”: “, “.join([tool.name for tool in execute_tools]),
“tools”: “\n”.join([f”{tool.name}: {tool.description}” for tool in execute_tools]),
“intermediate_steps”: intermediate_steps
}
response = react_agent.invoke(inputs)
print(f"RESPONSE: {response}")
Beta Was this translation helpful? Give feedback.
All reactions