Replies: 1 comment
-
Yes, you should use the To pass variables to the from langchain import hub
from langchain_community.llms import OpenAI
from langchain.agents import AgentExecutor, create_react_agent
from langchain_core.prompts import PromptTemplate
# Define the prompt template
template = '''Answer the following questions as best you can. You have access to the following tools:
{tools}
Use the following format:
Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [{tool_names}]
Action Input: the input to the action
Observation: the result of the action
... (this Thought/Action/Action Input/Observation can repeat N times)
Thought: I now know the final answer
Final Answer: the final answer to the original input question
Begin!
Question: {input}
Thought:{agent_scratchpad}'''
prompt = PromptTemplate.from_template(template)
model = OpenAI()
tools = [...] # Define your tools here
# Create the agent
agent = create_react_agent(model, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools)
# Invoke the agent with the required variables
result = await agent_executor.ainvoke({
"input": "hi",
"agent_scratchpad": "", # Initial empty scratchpad
"tools": "tool descriptions here",
"tool_names": "tool1, tool2"
}, config={"configurable": {"thread_id": "1"}}, debug=True)
print(result) In this example, the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Checked other resources
Commit to Help
Example Code
Description
Hello @dosu,
Should I use the {agent_scratchpad} key with create_react_agent?
If so, how?
I am not sure how to pass variables to the ainvoke method of create_react_agent:
Thank you.
System Info
langchain==0.2.6
langchain-community==0.2.6
langchain-core==0.2.10
langchain-experimental==0.0.62
langchain-openai==0.1.13
langchain-qdrant==0.1.0
langchain-text-splitters==0.2.1
Beta Was this translation helpful? Give feedback.
All reactions