0

I have a chatbot developed using langchain and streamlit. When I run it, it loads perfectly but as soon as I enter the first input it generates an error saying ** "ValueError: One input key expected got ['input', 'agent_scratchpad']" ** All I want to do is add the response into the memory. Can anyone suggest what I'm doing wrong in here.

My code looks as below. It's using langchain and steamlit

prompt = ZeroShotAgent.create_prompt(
    tools,
    prefix=template,
    suffix=suffix,
    input_variables=["input", "chat_history", "agent_scratchpad"]    
)

memory = ConversationBufferMemory(memory_key="chat_history")

llm_chain = LLMChain(llm=OpenAI(temperature=0), prompt=prompt,memory=memory)
agent = ZeroShotAgent(llm_chain=llm_chain, tools=tools, verbose=True,return_intermediate_steps=True)

with textcontainer:
    query = st.text_input("Query: ", key="input")
    if query:
        with st.spinner("typing..."):
            conversation_string = get_conversation_string()            

            agent_executor = AgentExecutor.from_agent_and_tools(agent=agent, tools=tools, memory=memory)
            response = agent_executor.run(input=query)
            agent_executor.verbose = True

        st.session_state.requests.append(query)
        st.session_state.responses.append(str(response)) 

2 Answers 2

0

Try this:

inputs={"input":query,"chat_history": []}
response = agent_executor.run(inputs)
Sign up to request clarification or add additional context in comments.

Comments

-1

To resolve this issue, you need to ensure consistency in the input keys. You can either update the input_variables parameter when creating the prompt to match the keys you are using, or you can adjust the keys you pass when calling agent_executor.run(input=query).

If you want to keep the input_variables parameter as it is, you should pass all the expected keys when calling agent_executor.run() like this:

response = agent_executor.run(input={"input": query, "chat_history": conversation_string, "agent_scratchpad": some_value})

1 Comment

Thanks for the response. I've tried your approach with response = agent_executor.run(input={"input": query, "chat_history": conversation_string, "agent_scratchpad": some_value}) but got the same error ValueError: One input key expected got ['agent_scratchpad', 'input']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.